Skip to content

Commit 1a56a59

Browse files
authored
feat: add the visit endpoint (#75)
1 parent 0dbf134 commit 1a56a59

18 files changed

+768
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ Official Documentation: [VisitorActivities](http://developer.pardot.com/kb/api-v
259259
- Query
260260
- Read
261261

262+
### Visits
263+
Official Documentation: [Visits](https://developer.pardot.com/kb/api-version-3/visits/)
264+
265+
- Query
266+
- Read
267+
262268
## How to Contribute
263269

264270
Want to help implement the missing API end points? Fork the repository, write some code, and

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
import com.darksci.pardot.api.parser.user.UserCreateResponseParser;
5959
import com.darksci.pardot.api.parser.user.UserQueryResponseParser;
6060
import com.darksci.pardot.api.parser.user.UserReadResponseParser;
61+
import com.darksci.pardot.api.parser.visit.VisitQueryResponseParser;
62+
import com.darksci.pardot.api.parser.visit.VisitReadResponseParser;
6163
import com.darksci.pardot.api.parser.visitor.VisitorQueryResponseParser;
6264
import com.darksci.pardot.api.parser.visitor.VisitorReadResponseParser;
6365
import com.darksci.pardot.api.parser.visitoractivity.VisitorActivityQueryResponseParser;
@@ -127,6 +129,8 @@
127129
import com.darksci.pardot.api.request.user.UserQueryRequest;
128130
import com.darksci.pardot.api.request.user.UserReadRequest;
129131
import com.darksci.pardot.api.request.user.UserUpdateRoleRequest;
132+
import com.darksci.pardot.api.request.visit.VisitQueryRequest;
133+
import com.darksci.pardot.api.request.visit.VisitReadRequest;
130134
import com.darksci.pardot.api.request.visitor.VisitorAssignRequest;
131135
import com.darksci.pardot.api.request.visitor.VisitorQueryRequest;
132136
import com.darksci.pardot.api.request.visitor.VisitorReadRequest;
@@ -170,6 +174,8 @@
170174
import com.darksci.pardot.api.response.user.User;
171175
import com.darksci.pardot.api.response.user.UserAbilitiesResponse;
172176
import com.darksci.pardot.api.response.user.UserQueryResponse;
177+
import com.darksci.pardot.api.response.visit.Visit;
178+
import com.darksci.pardot.api.response.visit.VisitQueryResponse;
173179
import com.darksci.pardot.api.response.visitor.Visitor;
174180
import com.darksci.pardot.api.response.visitor.VisitorQueryResponse;
175181
import com.darksci.pardot.api.response.visitoractivity.VisitorActivity;
@@ -1127,6 +1133,28 @@ public Optional<VisitorActivity> visitorActivityRead(final VisitorActivityReadRe
11271133
);
11281134
}
11291135

1136+
/**
1137+
* Make API request to query visits.
1138+
* @param request Request definition.
1139+
* @return Parsed api response.
1140+
*/
1141+
public VisitQueryResponse.Result visitQuery(final VisitQueryRequest request) {
1142+
return submitRequest(request, new VisitQueryResponseParser())
1143+
.orElseThrowInvalidRequestException();
1144+
}
1145+
1146+
/**
1147+
* Make API request to read a visit.
1148+
* @param request Request definition.
1149+
* @return Parsed api response
1150+
*/
1151+
public Optional<Visit> visitRead(final VisitReadRequest request) {
1152+
return optionalUnlessErrorCode(
1153+
submitRequest(request, new VisitReadResponseParser()),
1154+
ErrorCode.INVALID_ID, ErrorCode.INVALID_VISIT_ID
1155+
);
1156+
}
1157+
11301158
/**
11311159
* Entry point for adhoc user defined requests.
11321160
*
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2017, 2018, 2019, 2020 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.visit;
19+
20+
import com.darksci.pardot.api.parser.JacksonFactory;
21+
import com.darksci.pardot.api.parser.ResponseParser;
22+
import com.darksci.pardot.api.response.visit.VisitQueryResponse;
23+
24+
import java.io.IOException;
25+
26+
/**
27+
* Handles parsing Visit Query API responses into POJOs.
28+
*/
29+
public class VisitQueryResponseParser implements ResponseParser<VisitQueryResponse.Result> {
30+
31+
@Override
32+
public VisitQueryResponse.Result parseResponse(final String responseStr) throws IOException {
33+
return JacksonFactory.newInstance().readValue(responseStr, VisitQueryResponse.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, 2018, 2019, 2020 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.visit;
19+
20+
import com.darksci.pardot.api.parser.JacksonFactory;
21+
import com.darksci.pardot.api.parser.ResponseParser;
22+
import com.darksci.pardot.api.response.visit.Visit;
23+
import com.darksci.pardot.api.response.visit.VisitReadResponse;
24+
25+
import java.io.IOException;
26+
27+
/**
28+
* Handles parsing Visit Read API responses into POJOs.
29+
*/
30+
public class VisitReadResponseParser implements ResponseParser<Visit> {
31+
32+
@Override
33+
public Visit parseResponse(final String responseStr) throws IOException {
34+
return JacksonFactory.newInstance().readValue(responseStr, VisitReadResponse.class).getVisit();
35+
}
36+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* Copyright 2017, 2018, 2019, 2020 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.visit;
19+
20+
import com.darksci.pardot.api.request.BaseQueryRequest;
21+
22+
import java.util.Collection;
23+
24+
/**
25+
* Defines a Visit Query Request.
26+
*/
27+
public class VisitQueryRequest extends BaseQueryRequest<VisitQueryRequest> {
28+
29+
@Override
30+
public String getApiEndpoint() {
31+
return "visit/do/query";
32+
}
33+
34+
// Filter Options
35+
36+
/**
37+
* Only select visits who are associated with the specified visit id.
38+
* @param id The visit id to filter by.
39+
* @return RequestBuilder
40+
*/
41+
public VisitQueryRequest withId(final Long id) {
42+
return withCollectionParam("ids", id);
43+
}
44+
45+
/**
46+
* Only select visits who are associated with the specified visit ids.
47+
* @param ids The visit ids to filter by.
48+
* @return RequestBuilder
49+
*/
50+
public VisitQueryRequest withIds(final Collection<Long> ids) {
51+
return withCollectionParams("ids", ids);
52+
}
53+
54+
/**
55+
* Only select visits who are associated with the specified visitor id.
56+
* @param visitorId The visitor id to filter by.
57+
* @return RequestBuilder
58+
*/
59+
public VisitQueryRequest withVisitorId(final Long visitorId) {
60+
return withCollectionParam("visitor_ids", visitorId);
61+
}
62+
63+
/**
64+
* Only select visits who are associated with the specified visitor ids.
65+
* @param visitorIds The visitor ids to filter by.
66+
* @return RequestBuilder
67+
*/
68+
public VisitQueryRequest withVisitorIds(final Collection<Long> visitorIds) {
69+
return withCollectionParams("visitor_ids", visitorIds);
70+
}
71+
72+
/**
73+
* Only select visits who are associated with the specified prospect id.
74+
* @param prospectId The prospect id to filter by.
75+
* @return RequestBuilder
76+
*/
77+
public VisitQueryRequest withProspectId(final Long prospectId) {
78+
return withCollectionParam("prospect_ids", prospectId);
79+
}
80+
81+
/**
82+
* Only select visits who are associated with the specified prospect ids.
83+
* @param prospectIds The prospect ids to filter by.
84+
* @return RequestBuilder
85+
*/
86+
public VisitQueryRequest withProspectIds(final Collection<Long> prospectIds) {
87+
return withCollectionParams("prospect_ids", prospectIds);
88+
}
89+
90+
91+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright 2017, 2018, 2019, 2020 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.visit;
19+
20+
import com.darksci.pardot.api.request.BaseRequest;
21+
22+
/**
23+
* Used to generate a Visit read request.
24+
*/
25+
public class VisitReadRequest extends BaseRequest<VisitReadRequest> {
26+
27+
@Override
28+
public String getApiEndpoint() {
29+
return "visit/do/read";
30+
}
31+
32+
/**
33+
* Returns the data for the visit specified by id.
34+
* @param id The Id of the target visit.
35+
* @return VisitReadRequest builder.
36+
*/
37+
public VisitReadRequest selectById(final Long id) {
38+
return setParam("id", id);
39+
}
40+
}

src/main/java/com/darksci/pardot/api/response/ErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public enum ErrorCode {
3737
INVALID_VISITOR_ID(24),
3838
INVALID_OPPORTUNITY_ID(35),
3939
INVALID_CAMPAIGN_ID(38),
40+
INVALID_VISIT_ID(48),
4041
EMAIL_ADDRESS_IS_ALREADY_IN_USE(54),
4142
INVALID_LIST_ID(55),
4243
INVALID_EMAIL_FORMAT(65),
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* Copyright 2017, 2018, 2019, 2020 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.response.visit;
19+
20+
import com.fasterxml.jackson.annotation.JsonFormat;
21+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
22+
import org.joda.time.LocalDateTime;
23+
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
27+
/**
28+
* Represents a Pardot visit.
29+
*/
30+
public class Visit {
31+
private Long id;
32+
private Long visitorId;
33+
private Long prospectId;
34+
private Integer visitorPageViewCount;
35+
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
36+
private LocalDateTime firstVisitorPageViewAt;
37+
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
38+
private LocalDateTime lastVisitorPageViewAt;
39+
private Integer durationInSeconds;
40+
private String campaignParameter;
41+
private String mediumParameter;
42+
private String sourceParameter;
43+
private String contentParameter;
44+
private String termParameter;
45+
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
46+
private LocalDateTime createdAt;
47+
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
48+
private LocalDateTime updatedAt;
49+
50+
@JacksonXmlElementWrapper(localName = "visitor_page_views")
51+
private List<VisitorPageView> visitorPageViews;
52+
53+
public Long getId() { return id; }
54+
55+
public Long getVisitorId() { return visitorId; }
56+
57+
public Long getProspectId() { return prospectId; }
58+
59+
public Integer getVisitorPageViewCount() { return visitorPageViewCount; }
60+
61+
public LocalDateTime getFirstVisitorPageViewAt() { return firstVisitorPageViewAt; }
62+
63+
public LocalDateTime getLastVisitorPageViewAt() { return lastVisitorPageViewAt; }
64+
65+
public Integer getDurationInSeconds() { return durationInSeconds; }
66+
67+
public String getCampaignParameter() { return campaignParameter; }
68+
69+
public String getMediumParameter() { return mediumParameter; }
70+
71+
public String getSourceParameter() { return sourceParameter; }
72+
73+
public String getContentParameter() { return contentParameter; }
74+
75+
public String getTermParameter() { return termParameter; }
76+
77+
public LocalDateTime getCreatedAt() { return createdAt; }
78+
79+
public LocalDateTime getUpdatedAt() { return updatedAt; }
80+
81+
/**
82+
* Visitor Page Views associated to the visit, or empty list if none.
83+
*
84+
* @return Associated Visitor Page Views, or empty list if none.
85+
*/
86+
public List<VisitorPageView> getVisitorPageViews() {
87+
if (visitorPageViews == null) {
88+
return new ArrayList<>();
89+
}
90+
return visitorPageViews;
91+
}
92+
93+
@Override
94+
public String toString() {
95+
return "Visitor{"
96+
+ "id=" + id
97+
+ ", visitorId=" + visitorId
98+
+ ", prospectId=" + prospectId
99+
+ ", visitorPageViewCount=" + visitorPageViewCount
100+
+ ", firstVisitorPageViewAt=" + firstVisitorPageViewAt
101+
+ ", lastVisitorPageViewAt=" + lastVisitorPageViewAt
102+
+ ", durationInSeconds=" + durationInSeconds
103+
+ ", campaignParameter='" + campaignParameter + '\''
104+
+ ", mediumParameter='" + mediumParameter + '\''
105+
+ ", sourceParameter='" + sourceParameter + '\''
106+
+ ", contentParameter='" + contentParameter + '\''
107+
+ ", termParameter='" + termParameter + '\''
108+
+ ", createdAt=" + createdAt
109+
+ ", updatedAt=" + updatedAt
110+
+ '}';
111+
}
112+
}

0 commit comments

Comments
 (0)