Skip to content

Commit 7be9d47

Browse files
author
stephen powis
committed
implement assign, unassign. also fix some parsing bugs
1 parent 115d686 commit 7be9d47

File tree

13 files changed

+564
-43
lines changed

13 files changed

+564
-43
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,35 +96,37 @@ Official Documentation: [Accounts](http://developer.pardot.com/kb/api-version-3/
9696
### Campaigns
9797
Official Documentation: [Campaigns](http://developer.pardot.com/kb/api-version-3/campaigns/)
9898

99+
- Create
99100
- Query
100101
- Read
101-
- Create
102102
- Update
103103

104104
### Emails
105105
Official Documentation: [Emails](http://developer.pardot.com/kb/api-version-3/emails/)
106106

107107
- Read
108-
- Stats
109-
- Sending One to One Emails
110108
- Sending List Emails
109+
- Sending One to One Emails
110+
- Stats
111111

112112
### Prospects
113113
Official Documentation: [Prospects](http://developer.pardot.com/kb/api-version-3/prospects/)
114114

115-
- Read
116-
- Create - Partial implementation, can only set default fields.
117-
- Update - Partial implementation, can only set default fields.
118-
- Upsert - Partial implementation, can only set default fields.
115+
- Assign
116+
- Create - Does not support multiple values for record-multiple fields.
119117
- Delete
120118
- Query
119+
- Read
120+
- Unassign
121+
- Update - Does not support multiple values for record-multiple fields.
122+
- Upsert - Does not support multiple values for record-multiple fields.
121123

122124
### Users
123125
Official Documentation: [Users](http://developer.pardot.com/kb/api-version-3/users/)
124126

127+
- Abilities of current API User
125128
- Query
126129
- Read
127-
- Abilities of API User
128130

129131
## How to Contribute
130132

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
import com.darksci.pardot.api.request.email.EmailSendOneToOneRequest;
2626
import com.darksci.pardot.api.request.email.EmailStatsRequest;
2727
import com.darksci.pardot.api.request.login.LoginRequest;
28+
import com.darksci.pardot.api.request.prospect.ProspectAssignRequest;
2829
import com.darksci.pardot.api.request.prospect.ProspectCreateRequest;
2930
import com.darksci.pardot.api.request.prospect.ProspectDeleteRequest;
3031
import com.darksci.pardot.api.request.prospect.ProspectQueryRequest;
3132
import com.darksci.pardot.api.request.prospect.ProspectReadRequest;
33+
import com.darksci.pardot.api.request.prospect.ProspectUnassignRequest;
3234
import com.darksci.pardot.api.request.prospect.ProspectUpdateRequest;
3335
import com.darksci.pardot.api.request.prospect.ProspectUpsertRequest;
3436
import com.darksci.pardot.api.request.user.UserAbilitiesRequest;
@@ -360,6 +362,24 @@ public boolean prospectDelete(final ProspectDeleteRequest request) {
360362
return true;
361363
}
362364

365+
/**
366+
* Make API request to assign a prospect.
367+
* @param request Request definition.
368+
* @return Parsed api response.
369+
*/
370+
public Prospect prospectAssign(final ProspectAssignRequest request) {
371+
return submitRequest(request, new ProspectReadResponseParser());
372+
}
373+
374+
/**
375+
* Make API request to unassign a prospect.
376+
* @param request Request definition.
377+
* @return Parsed api response.
378+
*/
379+
public Prospect prospectUnassign(final ProspectUnassignRequest request) {
380+
return submitRequest(request, new ProspectReadResponseParser());
381+
}
382+
363383
/**
364384
* Clean up instance, releasing any resources held internally.
365385
*/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.darksci.pardot.api.parser;
2+
3+
import com.fasterxml.jackson.core.JsonParser;
4+
import com.fasterxml.jackson.databind.DeserializationContext;
5+
import com.fasterxml.jackson.databind.JsonDeserializer;
6+
7+
import java.io.IOException;
8+
9+
/**
10+
* Converts values to boolean.
11+
*
12+
* False values: NULL, emptyString, NO, FALSE, 0
13+
* True values: all others.
14+
*/
15+
public class PardotBooleanSerializer extends JsonDeserializer<Boolean> {
16+
@Override
17+
public Boolean deserialize(final JsonParser jsonParser, final DeserializationContext ctxt) throws IOException {
18+
final String value = jsonParser.getText();
19+
20+
// Null => false
21+
// Empty string => false
22+
if (value == null || value.isEmpty()) {
23+
return false;
24+
}
25+
26+
// Make all lower case
27+
final String normalizedValue = value.toLowerCase();
28+
29+
// No, false, and 0 => false
30+
if (normalizedValue.equals("no") || normalizedValue.equals("false") || normalizedValue.equals("0")) {
31+
return false;
32+
}
33+
34+
// All others defaulted to true
35+
return true;
36+
}
37+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.darksci.pardot.api.request.prospect;
2+
3+
import com.darksci.pardot.api.request.BaseRequest;
4+
5+
/**
6+
* Represents a request to perform an action against a specific prospect, either by
7+
* Id or Email address.
8+
*/
9+
abstract class ProspectActionRequest<T> extends BaseRequest<T> {
10+
11+
/**
12+
* Define which prospect to perform action on by Id.
13+
* @param prospectId Id of prospect to delete.
14+
* @return RequestBuilder
15+
*/
16+
public T withProspectId(final Long prospectId) {
17+
setParam("email", null);
18+
return setParam("id", prospectId);
19+
}
20+
21+
/**
22+
* Define which prospect to perform action on by email.
23+
* @param email Email of prospect to delete.
24+
* @return RequestBuilder
25+
*/
26+
public T withProspectEmail(final String email) {
27+
setParam("id", null);
28+
return setParam("email", email);
29+
}
30+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.darksci.pardot.api.request.prospect;
2+
3+
/**
4+
* Request for assigning a Prospect to a user.
5+
*/
6+
public class ProspectAssignRequest extends ProspectActionRequest<ProspectAssignRequest> {
7+
@Override
8+
public String getApiEndpoint() {
9+
return "prospect/do/assign";
10+
}
11+
12+
/**
13+
* Assign prospect to the specified User's email address.
14+
* @param email Email address of user.
15+
* @return RequestBuilder
16+
*/
17+
public ProspectAssignRequest withUserEmail(final String email) {
18+
setParam("user_id", null);
19+
setParam("group_id", null);
20+
return setParam("user_email", email);
21+
}
22+
23+
/**
24+
* Assign prospect to the specified User by userId.
25+
* @param userId Id of user.
26+
* @return RequestBuilder
27+
*/
28+
public ProspectAssignRequest withUserId(final Long userId) {
29+
setParam("user_id", userId);
30+
setParam("group_id", null);
31+
return setParam("user_email", null);
32+
}
33+
34+
/**
35+
* Assign prospect to the specified Group by the group's Id.
36+
* @param groupId Id of the Group.
37+
* @return RequestBuilder
38+
*/
39+
public ProspectAssignRequest withGroupId(final Long groupId) {
40+
setParam("user_id", null);
41+
setParam("group_id", groupId);
42+
return setParam("user_email", null);
43+
}
44+
}
Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,11 @@
11
package com.darksci.pardot.api.request.prospect;
22

3-
import com.darksci.pardot.api.request.BaseRequest;
4-
53
/**
64
* For deleting Prospects using Pardot's API.
75
*/
8-
public class ProspectDeleteRequest extends BaseRequest<ProspectDeleteRequest> {
6+
public class ProspectDeleteRequest extends ProspectActionRequest<ProspectDeleteRequest> {
97
@Override
108
public String getApiEndpoint() {
119
return "prospect/do/delete";
1210
}
13-
14-
/**
15-
* Define which prospect to delete by Id.
16-
* @param prospectId Id of prospect to delete.
17-
* @return RequestBuilder
18-
*/
19-
public ProspectDeleteRequest withProspectId(final Long prospectId) {
20-
setParam("email", null);
21-
return setParam("id", prospectId);
22-
}
23-
24-
/**
25-
* Define which prospect to delete by email.
26-
* @param email Email of prospect to delete.
27-
* @return RequestBuilder
28-
*/
29-
public ProspectDeleteRequest withProspectEmail(final String email) {
30-
setParam("id", null);
31-
return setParam("email", email);
32-
}
3311
}

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

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.darksci.pardot.api.request.BaseRequest;
44
import com.darksci.pardot.api.response.prospect.Prospect;
55

6+
import java.util.Map;
7+
68
/**
79
* Abstract shared code between Create, Update, and Upsert Prospect operations.
810
*/
@@ -14,16 +16,17 @@ abstract class ProspectModifyRequest<T> extends BaseRequest<T> {
1416
* @return CampaignCreateRequest builder.
1517
*/
1618
public T withProspect(final Prospect prospect) {
19+
// Identifying fields
20+
setParam("id", prospect.getId());
1721
setParam("email", prospect.getEmail());
22+
23+
// Default fields
1824
setParam("first_name", prospect.getFirstName());
1925
setParam("last_name", prospect.getLastName());
20-
21-
setParam("id", prospect.getId());
2226
setParam("campaign_id", prospect.getCampaignId());
2327
setParam("salutation", prospect.getSalutation());
2428
setParam("company", prospect.getCompany());
2529
setParam("prospect_account_d", prospect.getProspectAccountId());
26-
2730
setParam("website", prospect.getWebsite());
2831
setParam("job_title", prospect.getJobTitle());
2932
setParam("department", prospect.getDepartment());
@@ -34,18 +37,91 @@ public T withProspect(final Prospect prospect) {
3437
setParam("state", prospect.getState());
3538
setParam("territory", prospect.getTerritory());
3639
setParam("zip", prospect.getZip());
37-
3840
setParam("phone", prospect.getPhone());
3941
setParam("fax", prospect.getFax());
40-
4142
setParam("source", prospect.getSource());
4243
setParam("annual_revenue", prospect.getAnnualRevenue());
4344
setParam("employees", prospect.getEmployees());
4445
setParam("industry", prospect.getIndustry());
4546
setParam("years_in_business", prospect.getYearsInBusiness());
4647

48+
// Loop through and set custom fields
49+
if (prospect.getCustomFields() != null) {
50+
for (Map.Entry<String, String> entry: prospect.getCustomFields().entrySet()) {
51+
setParam(entry.getKey(), entry.getValue());
52+
}
53+
}
54+
4755
// TODO add other fields? How to handle custom fields?
4856

4957
return (T) this;
5058
}
59+
60+
/**
61+
* Explicitly clear the value of a field.
62+
*
63+
* You can get the same behavior by setting the field on a Prospect to empty string ""
64+
* or by calling setFieldValue(fieldName, "")
65+
*
66+
* @param fieldName The field to clear.
67+
* @return RequestBuilder
68+
*/
69+
public T withFieldValueCleared(final String fieldName) {
70+
return setParam(fieldName, "");
71+
}
72+
73+
/**
74+
* Explicity set the value of a field.
75+
* @param fieldName The field to set
76+
* @param value The value to set.
77+
* @return RequestBuilder
78+
*/
79+
public T withFieldValue(final String fieldName, final Object value) {
80+
return setParam(fieldName, value);
81+
}
82+
83+
/**
84+
* Subscribe prospect to specified list.
85+
* @param listId List to subscribe prospect to.
86+
* @return RequestBuilder
87+
*/
88+
public T withSubscribeToList(final Long listId) {
89+
return setParam("list_" + String.valueOf(listId), "1");
90+
}
91+
92+
/**
93+
* Subscribe prospect to specified list.
94+
* @param listId List to subscribe prospect to.
95+
* @return RequestBuilder
96+
*/
97+
public T withUnsubscribeFromList(final Long listId) {
98+
return setParam("list_" + String.valueOf(listId), "0");
99+
}
100+
101+
/**
102+
* Set a prospect's profile criteria as matching.
103+
* @param profileCriteriaId Id of the profile criteria to mark as matching.
104+
* @return RequestBuilder
105+
*/
106+
public T withProfileCriteriaMatching(final Long profileCriteriaId) {
107+
return setParam("profile_criteria_" + String.valueOf(profileCriteriaId), "match");
108+
}
109+
110+
/**
111+
* Set a prospect's profile criteria as not matching.
112+
* @param profileCriteriaId Id of the profile criteria to mark as not matching.
113+
* @return RequestBuilder
114+
*/
115+
public T withProfileCriteriaNotMatching(final Long profileCriteriaId) {
116+
return setParam("profile_criteria_" + String.valueOf(profileCriteriaId), "nomatch");
117+
}
118+
119+
/**
120+
* Set a prospect's profile criteria as unknown.
121+
* @param profileCriteriaId Id of the profile criteria to mark as unknown.
122+
* @return RequestBuilder
123+
*/
124+
public T withProfileCriteriaUnknown(final Long profileCriteriaId) {
125+
return setParam("profile_criteria_" + String.valueOf(profileCriteriaId), "unknown");
126+
}
51127
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.darksci.pardot.api.request.prospect;
2+
3+
/**
4+
* Request for unassigning a Prospect to a user.
5+
*/
6+
public class ProspectUnassignRequest extends ProspectActionRequest<ProspectUnassignRequest> {
7+
8+
@Override
9+
public String getApiEndpoint() {
10+
return "prospect/do/unassign";
11+
}
12+
}

0 commit comments

Comments
 (0)