Skip to content

Commit c9f746d

Browse files
authored
Visitor + Visitor Activity API requests (#3)
1 parent 324e442 commit c9f746d

35 files changed

+2038
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
The format is based on [Keep a Changelog](http://keepachangelog.com/)
33
and this project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## 0.3.0 (12/15/17)
6+
- Add support for Visitor and VisitorActivity API endpoints.
7+
- Bugfix to Prospect parser.
8+
9+
510
## 0.2.0 (11/11/17)
611
- Support Api version 4 via configuration method .withApiVersion4()
712
- Add support for List and ListMembership API endpoints.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.darksci</groupId>
88
<artifactId>pardot-api-client</artifactId>
9-
<version>0.2.0</version>
9+
<version>0.3.0</version>
1010
<packaging>jar</packaging>
1111

1212
<!-- Require Maven 3.3.9 -->

src/main/java/com/darksci/pardot/api/PardotClient.java

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
import com.darksci.pardot.api.parser.user.UserAbilitiesParser;
3636
import com.darksci.pardot.api.parser.user.UserQueryResponseParser;
3737
import com.darksci.pardot.api.parser.user.UserReadResponseParser;
38+
import com.darksci.pardot.api.parser.visitor.VisitorQueryResponseParser;
39+
import com.darksci.pardot.api.parser.visitor.VisitorReadResponseParser;
40+
import com.darksci.pardot.api.parser.visitoractivity.VisitorActivityQueryResponseParser;
41+
import com.darksci.pardot.api.parser.visitoractivity.VisitorActivityReadResponseParser;
3842
import com.darksci.pardot.api.request.Request;
3943
import com.darksci.pardot.api.request.account.AccountReadRequest;
4044
import com.darksci.pardot.api.request.campaign.CampaignCreateRequest;
@@ -65,6 +69,11 @@
6569
import com.darksci.pardot.api.request.user.UserAbilitiesRequest;
6670
import com.darksci.pardot.api.request.user.UserQueryRequest;
6771
import com.darksci.pardot.api.request.user.UserReadRequest;
72+
import com.darksci.pardot.api.request.visitor.VisitorAssignRequest;
73+
import com.darksci.pardot.api.request.visitor.VisitorQueryRequest;
74+
import com.darksci.pardot.api.request.visitor.VisitorReadRequest;
75+
import com.darksci.pardot.api.request.visitoractivity.VisitorActivityQueryRequest;
76+
import com.darksci.pardot.api.request.visitoractivity.VisitorActivityReadRequest;
6877
import com.darksci.pardot.api.response.ErrorResponse;
6978
import com.darksci.pardot.api.response.account.Account;
7079
import com.darksci.pardot.api.response.campaign.Campaign;
@@ -81,6 +90,10 @@
8190
import com.darksci.pardot.api.response.user.User;
8291
import com.darksci.pardot.api.response.user.UserAbilitiesResponse;
8392
import com.darksci.pardot.api.response.user.UserQueryResponse;
93+
import com.darksci.pardot.api.response.visitor.Visitor;
94+
import com.darksci.pardot.api.response.visitor.VisitorQueryResponse;
95+
import com.darksci.pardot.api.response.visitoractivity.VisitorActivity;
96+
import com.darksci.pardot.api.response.visitoractivity.VisitorActivityQueryResponse;
8497
import com.darksci.pardot.api.rest.HttpClientRestClient;
8598
import com.darksci.pardot.api.rest.RestClient;
8699
import com.darksci.pardot.api.rest.RestResponse;
@@ -155,7 +168,7 @@ private <T> T submitRequest(final Request request, ResponseParser<T> responsePar
155168
}
156169

157170
// High level check for error response
158-
if (restResponse.getResponseStr().contains("<rsp stat=\"fail\"")) {
171+
if (responseStr.contains("<rsp stat=\"fail\"")) {
159172
try {
160173
// Parse error response
161174
final ErrorResponse error = new ErrorResponseParser().parseResponse(restResponse.getResponseStr());
@@ -184,9 +197,7 @@ public Configuration getConfiguration() {
184197
}
185198

186199
/**
187-
*
188-
189-
package protected for access in tests.
200+
* package protected for access in tests.
190201
* @return Rest Client.
191202
*/
192203
RestClient getRestClient() {
@@ -487,6 +498,51 @@ public Prospect prospectUnassign(final ProspectUnassignRequest request) {
487498
return submitRequest(request, new ProspectReadResponseParser());
488499
}
489500

501+
/**
502+
* Make API request to assign a visitor.
503+
* @param request Request definition.
504+
* @return Parsed api response.
505+
*/
506+
public Visitor visitorAssign(final VisitorAssignRequest request) {
507+
return submitRequest(request, new VisitorReadResponseParser());
508+
}
509+
510+
/**
511+
* Make API request to query visitors.
512+
* @param request Request definition.
513+
* @return Parsed api response.
514+
*/
515+
public VisitorQueryResponse.Result visitorQuery(final VisitorQueryRequest request) {
516+
return submitRequest(request, new VisitorQueryResponseParser());
517+
}
518+
519+
/**
520+
* Make API request to read a visitor activity.
521+
* @param request Request definition.
522+
* @return Parsed api response
523+
*/
524+
public Visitor visitorRead(final VisitorReadRequest request) {
525+
return submitRequest(request, new VisitorReadResponseParser());
526+
}
527+
528+
/**
529+
* Make API request to query visitorActivities.
530+
* @param request Request definition.
531+
* @return Parsed api response.
532+
*/
533+
public VisitorActivityQueryResponse.Result visitorActivityQuery(final VisitorActivityQueryRequest request) {
534+
return submitRequest(request, new VisitorActivityQueryResponseParser());
535+
}
536+
537+
/**
538+
* Make API request to read a visitor activity.
539+
* @param request Request definition.
540+
* @return Parsed api response
541+
*/
542+
public VisitorActivity visitorActivityRead(final VisitorActivityReadRequest request) {
543+
return submitRequest(request, new VisitorActivityReadResponseParser());
544+
}
545+
490546
/**
491547
* Clean up instance, releasing any resources held internally.
492548
*/
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2017 Stephen Powis https://github.com/Crim/pardot-java-client
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7+
* persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package com.darksci.pardot.api.parser.visitor;
19+
20+
import com.darksci.pardot.api.parser.JacksonFactory;
21+
import com.darksci.pardot.api.parser.ResponseParser;
22+
import com.darksci.pardot.api.response.visitor.VisitorQueryResponse;
23+
24+
import java.io.IOException;
25+
26+
/**
27+
* Handles parsing Visitor Query API responses into POJOs.
28+
*/
29+
public class VisitorQueryResponseParser implements ResponseParser<VisitorQueryResponse.Result> {
30+
31+
@Override
32+
public VisitorQueryResponse.Result parseResponse(final String responseStr) throws IOException {
33+
return JacksonFactory.newInstance().readValue(responseStr, VisitorQueryResponse.class).getResult();
34+
}
35+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2017 Stephen Powis https://github.com/Crim/pardot-java-client
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7+
* persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package com.darksci.pardot.api.parser.visitor;
19+
20+
import com.darksci.pardot.api.parser.JacksonFactory;
21+
import com.darksci.pardot.api.parser.ResponseParser;
22+
import com.darksci.pardot.api.response.visitor.Visitor;
23+
import com.darksci.pardot.api.response.visitor.VisitorReadResponse;
24+
25+
import java.io.IOException;
26+
27+
/**
28+
* Handles parsing Visitor Read API responses into POJOs.
29+
*/
30+
public class VisitorReadResponseParser implements ResponseParser<Visitor> {
31+
32+
@Override
33+
public Visitor parseResponse(final String responseStr) throws IOException {
34+
return JacksonFactory.newInstance().readValue(responseStr, VisitorReadResponse.class).getVisitor();
35+
}
36+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2017 Stephen Powis https://github.com/Crim/pardot-java-client
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7+
* persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package com.darksci.pardot.api.parser.visitoractivity;
19+
20+
import com.darksci.pardot.api.parser.JacksonFactory;
21+
import com.darksci.pardot.api.parser.ResponseParser;
22+
import com.darksci.pardot.api.response.visitoractivity.VisitorActivityQueryResponse;
23+
24+
import java.io.IOException;
25+
26+
/**
27+
* Handles parsing VisitorActivity Query API responses into POJOs.
28+
*/
29+
public class VisitorActivityQueryResponseParser implements ResponseParser<VisitorActivityQueryResponse.Result> {
30+
31+
@Override
32+
public VisitorActivityQueryResponse.Result parseResponse(final String responseStr) throws IOException {
33+
return JacksonFactory.newInstance().readValue(responseStr, VisitorActivityQueryResponse.class).getResult();
34+
}
35+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2017 Stephen Powis https://github.com/Crim/pardot-java-client
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7+
* persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package com.darksci.pardot.api.parser.visitoractivity;
19+
20+
import com.darksci.pardot.api.parser.JacksonFactory;
21+
import com.darksci.pardot.api.parser.ResponseParser;
22+
import com.darksci.pardot.api.response.visitoractivity.VisitorActivity;
23+
import com.darksci.pardot.api.response.visitoractivity.VisitorActivityReadResponse;
24+
25+
import java.io.IOException;
26+
27+
/**
28+
* Handles parsing VisitorActivity Read API responses into POJOs.
29+
*/
30+
public class VisitorActivityReadResponseParser implements ResponseParser<VisitorActivity> {
31+
32+
@Override
33+
public VisitorActivity parseResponse(final String responseStr) throws IOException {
34+
return JacksonFactory.newInstance().readValue(responseStr, VisitorActivityReadResponse.class).getVisitorActivity();
35+
}
36+
}

src/main/java/com/darksci/pardot/api/request/BaseRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ public abstract class BaseRequest<T> implements Request {
3030
// Param holder
3131
private Map<String, Object> params = new HashMap<>();
3232

33+
@SuppressWarnings("unchecked")
3334
protected <T> T getParam(final String name) {
3435
return (T) params.getOrDefault(name, null);
3536
}
3637

38+
@SuppressWarnings("unchecked")
3739
protected T setParam(final String name, Object value) {
3840
if (value == null) {
3941
params.remove(name);
@@ -50,6 +52,7 @@ protected T setParam(final String name, Object value) {
5052
* @return BaseRequest
5153
*/
5254
protected T setBooleanParam(final String parameterName, final boolean booleanValue) {
55+
// TODO i think this is a bug? Or needs to be removed.
5356
String value = "true";
5457
if (!booleanValue) {
5558
value = "false";
@@ -67,6 +70,7 @@ protected T withCollectionParam(final String name, final Object value) {
6770
return setParam(name, values);
6871
}
6972

73+
@SuppressWarnings("unchecked")
7074
protected T withCollectionParams(final String name, Collection<?> values) {
7175
for (final Object value: values) {
7276
withCollectionParam(name, value);

src/main/java/com/darksci/pardot/api/request/prospect/ProspectModifyRequest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ abstract class ProspectModifyRequest<T> extends BaseRequest<T> {
3232
* @param prospect The prospect you want to create in pardot.
3333
* @return CampaignCreateRequest builder.
3434
*/
35+
@SuppressWarnings("unchecked")
3536
public T withProspect(final Prospect prospect) {
3637
// Identifying fields
3738
setParam("id", prospect.getId());
@@ -69,8 +70,6 @@ public T withProspect(final Prospect prospect) {
6970
}
7071
}
7172

72-
// TODO add other fields? How to handle custom fields?
73-
7473
return (T) this;
7574
}
7675

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright 2017 Stephen Powis https://github.com/Crim/pardot-java-client
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7+
* persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package com.darksci.pardot.api.request.visitor;
19+
20+
21+
import com.darksci.pardot.api.request.BaseQueryRequest;
22+
23+
/**
24+
* Request for assigning a visitor to a prospect.
25+
*/
26+
public class VisitorAssignRequest extends BaseQueryRequest<VisitorAssignRequest> {
27+
@Override
28+
public String getApiEndpoint() {
29+
return "visitor/do/assign";
30+
}
31+
32+
/**
33+
* Assign visitor to the specified Prospect's email address.
34+
* @param email Email address of prospect.
35+
* @return RequestBuilder
36+
*/
37+
public VisitorAssignRequest withProspectEmail(final String email) {
38+
setParam("prospect_id", null);
39+
return setParam("prospect_email", email);
40+
}
41+
42+
/**
43+
* Assign visitor to the specified prospect by prospectId.
44+
* @param prospectId Id of prospect.
45+
* @return RequestBuilder
46+
*/
47+
public VisitorAssignRequest withProspectId(final Long prospectId) {
48+
setParam("prospect_email", null);
49+
return setParam("prospect_id", prospectId);
50+
}
51+
52+
/**
53+
* Select which visitor to assign.
54+
* @param visitorId The id of the visitor to assign.
55+
* @return RequestBuilder
56+
*/
57+
public VisitorAssignRequest withVisitorId(final Long visitorId) {
58+
return setParam("id", visitorId);
59+
}
60+
}

0 commit comments

Comments
 (0)