Skip to content

Commit f83f3e1

Browse files
author
stephen powis
committed
add account end point
1 parent 251b034 commit f83f3e1

File tree

10 files changed

+281
-4
lines changed

10 files changed

+281
-4
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.darksci.pardot.api.request.account;
2+
3+
4+
import com.darksci.pardot.api.request.BaseRequest;
5+
6+
/**
7+
* Used to generate an Account read request.
8+
*/
9+
public class AccountReadRequest extends BaseRequest<AccountReadRequest> {
10+
11+
@Override
12+
public String getApiEndpoint() {
13+
return "account/do/read";
14+
}
15+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package com.darksci.pardot.api.response.account;
2+
3+
import com.fasterxml.jackson.annotation.JsonFormat;
4+
import org.joda.time.DateTime;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
/**
9+
* Represents a Pardot Account.
10+
*/
11+
public class Account {
12+
private Long id;
13+
private String company;
14+
private String level;
15+
private String website;
16+
private String vanityDomain;
17+
private Long pluginCampaignId;
18+
private String trackingCodeTemplate;
19+
private String address1;
20+
private String address2;
21+
private String city;
22+
private String state;
23+
private String territory;
24+
private Integer zip;
25+
private String country;
26+
private String phone;
27+
private String fax;
28+
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
29+
private DateTime createdAt;
30+
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
31+
private DateTime updatedAt;
32+
33+
public Long getId() {
34+
return id;
35+
}
36+
37+
public String getCompany() {
38+
return company;
39+
}
40+
41+
public String getLevel() {
42+
return level;
43+
}
44+
45+
public String getWebsite() {
46+
return website;
47+
}
48+
49+
public String getVanityDomain() {
50+
return vanityDomain;
51+
}
52+
53+
public Long getPluginCampaignId() {
54+
return pluginCampaignId;
55+
}
56+
57+
public String getTrackingCodeTemplate() {
58+
return trackingCodeTemplate;
59+
}
60+
61+
public String getAddress1() {
62+
return address1;
63+
}
64+
65+
public String getAddress2() {
66+
return address2;
67+
}
68+
69+
public String getCity() {
70+
return city;
71+
}
72+
73+
public String getState() {
74+
return state;
75+
}
76+
77+
public String getTerritory() {
78+
return territory;
79+
}
80+
81+
public Integer getZip() {
82+
return zip;
83+
}
84+
85+
public String getCountry() {
86+
return country;
87+
}
88+
89+
public String getPhone() {
90+
return phone;
91+
}
92+
93+
public String getFax() {
94+
return fax;
95+
}
96+
97+
public DateTime getCreatedAt() {
98+
return createdAt;
99+
}
100+
101+
public DateTime getUpdatedAt() {
102+
return updatedAt;
103+
}
104+
105+
@Override
106+
public String toString() {
107+
return "Account{"
108+
+ "id=" + id
109+
+ ", company='" + company + '\''
110+
+ ", level='" + level + '\''
111+
+ ", website='" + website + '\''
112+
+ ", vanityDomain='" + vanityDomain + '\''
113+
+ ", pluginCampaignId=" + pluginCampaignId
114+
+ ", trackingCodeTemplate='" + trackingCodeTemplate + '\''
115+
+ ", address1='" + address1 + '\''
116+
+ ", address2='" + address2 + '\''
117+
+ ", city='" + city + '\''
118+
+ ", state='" + state + '\''
119+
+ ", territory='" + territory + '\''
120+
+ ", zip=" + zip
121+
+ ", country='" + country + '\''
122+
+ ", phone='" + phone + '\''
123+
+ ", fax='" + fax + '\''
124+
+ ", createdAt=" + createdAt
125+
+ ", updatedAt=" + updatedAt
126+
+ '}';
127+
}
128+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.darksci.pardot.api.response.account;
2+
3+
/**
4+
* Represents API response for an account read request.
5+
*/
6+
public class AccountReadResponse {
7+
private Account account;
8+
9+
public Account getAccount() {
10+
return account;
11+
}
12+
}

src/main/java/com/darksci/pardot/api/rest/HttpClientRestClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.darksci.pardot.api.rest;
22

3+
import com.darksci.pardot.api.request.account.AccountReadRequest;
4+
import com.darksci.pardot.api.response.account.Account;
5+
import com.darksci.pardot.api.rest.handlers.account.AccountReadResponseHandler;
36
import com.darksci.pardot.api.rest.handlers.campaign.CampaignQueryResponseHandler;
47
import com.darksci.pardot.api.Configuration;
58
import com.darksci.pardot.api.request.Request;
@@ -298,6 +301,16 @@ public LoginResponse authenticate() {
298301
return null;
299302
}
300303

304+
/**
305+
* Make API request to read the account of the currently authenticated user.
306+
* @param request Request definition.
307+
* @return Parsed api response.
308+
* @throws IOException on parse errors.
309+
*/
310+
public Account accountRead(final AccountReadRequest request) throws IOException {
311+
return post(request, new AccountReadResponseHandler());
312+
}
313+
301314
/**
302315
* Make API request to query one or more users.
303316
* @param request Request definition.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.darksci.pardot.api.rest.handlers.account;
2+
3+
import com.darksci.pardot.api.response.account.Account;
4+
import com.darksci.pardot.api.response.account.AccountReadResponse;
5+
import com.darksci.pardot.api.response.campaign.Campaign;
6+
import com.darksci.pardot.api.response.campaign.CampaignReadResponse;
7+
import com.darksci.pardot.api.rest.handlers.BaseResponseHandler;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
10+
11+
import java.io.IOException;
12+
13+
/**
14+
* Handles parsing AccountRead API responses into POJOs.
15+
*/
16+
public class AccountReadResponseHandler extends BaseResponseHandler<Account> {
17+
@Override
18+
public Account parseResponse(final String responseStr) throws IOException {
19+
return getMapper().readValue(responseStr, AccountReadResponse.class).getAccount();
20+
}
21+
}

src/main/java/com/darksci/pardot/api/rest/handlers/campaign/CampaignReadResponseHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* Handles parsing CampaignRead API responses into POJOs.
1313
*/
1414
public class CampaignReadResponseHandler extends BaseResponseHandler<Campaign> {
15-
private static final Logger logger = LoggerFactory.getLogger(CampaignReadResponseHandler.class);
1615

1716
@Override
1817
public Campaign parseResponse(final String responseStr) throws IOException {

src/test/java/com/darksci/pardot/api/rest/HttpClientRestClientTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.darksci.pardot.api.rest;
22

33
import categories.IntegrationTest;
4+
import com.darksci.pardot.api.request.account.AccountReadRequest;
45
import com.darksci.pardot.api.request.email.EmailSendListRequest;
6+
import com.darksci.pardot.api.response.account.Account;
57
import com.darksci.pardot.api.response.email.Email;
68
import com.darksci.pardot.api.response.user.UserQueryResponse;
79
import com.darksci.pardot.api.Configuration;
@@ -94,6 +96,18 @@ public void loginTest() throws IOException {
9496
assertNotNull("Should have non-null property", response.getApiKey());
9597
}
9698

99+
/**
100+
* Attempt to retrieve account.
101+
*/
102+
@Test
103+
public void accountReadTest() throws IOException {
104+
AccountReadRequest readRequest = new AccountReadRequest();
105+
106+
final Account response = restClient.accountRead(readRequest);
107+
assertNotNull("Should not be null", response);
108+
logger.info("Response: {}", response);
109+
}
110+
97111
/**
98112
* Attempt to retrieve users.
99113
*/
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.darksci.pardot.api.rest.handlers.account;
2+
3+
import com.darksci.pardot.api.response.account.Account;
4+
import com.darksci.pardot.api.rest.handlers.BaseResponseHandlerTest;
5+
import org.junit.Test;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import java.io.IOException;
10+
11+
import static org.junit.Assert.*;
12+
13+
public class AccountReadResponseHandlerTest extends BaseResponseHandlerTest {
14+
private static final Logger logger = LoggerFactory.getLogger(AccountReadResponseHandlerTest.class);
15+
16+
/**
17+
* Validates we can parse an Account Read
18+
*/
19+
@Test
20+
public void testRead() throws IOException {
21+
final String input = readFile("accountRead.xml");
22+
final Account account = new AccountReadResponseHandler().parseResponse(input);
23+
logger.info("Result: {}", account);
24+
25+
assertNotNull("Should not be null", account);
26+
assertEquals("Has correct id", 1L, (long) account.getId());
27+
assertEquals("Has correct company", "Test Account", account.getCompany());
28+
assertEquals("Has correct level", "SFDC Ultimate Edition", account.getLevel());
29+
assertEquals("Has correct website", "http://www.example.com", account.getWebsite());
30+
assertEquals("Has correct vanity domain", "http://go.example.com", account.getVanityDomain());
31+
assertEquals("Has correct plugin campaign id", 2, (long) account.getPluginCampaignId());
32+
assertNotNull("Has non-null tracking code template", account.getTrackingCodeTemplate());
33+
assertEquals("Has correct address1", "123 Main Street", account.getAddress1());
34+
assertEquals("Has correct address2", "addr2", account.getAddress2());
35+
assertEquals("Has correct city", "Atlanta", account.getCity());
36+
assertEquals("Has correct state", "GA", account.getState());
37+
assertEquals("Has correct territory", "Test Territory", account.getTerritory());
38+
assertEquals("Has correct zipcode", 30064, (int) account.getZip());
39+
assertEquals("Has correct country", "United States", account.getCountry());
40+
assertEquals("Has correct phone", "123-456-4789", account.getPhone());
41+
assertEquals("Has correct createdAt", "2016-01-04T10:39:26.000Z", account.getCreatedAt().toString());
42+
assertEquals("Has correct updatedAt", "2017-08-10T05:32:19.000Z", account.getUpdatedAt().toString());
43+
}
44+
}

src/test/java/com/darksci/pardot/api/rest/handlers/campaign/CampaignReadResponseHandlerTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
import static org.junit.Assert.assertEquals;
1212
import static org.junit.Assert.assertNotNull;
1313

14-
/**
15-
*
16-
*/
1714
public class CampaignReadResponseHandlerTest extends BaseResponseHandlerTest {
1815
private static final Logger logger = LoggerFactory.getLogger(CampaignReadResponseHandlerTest.class);
1916

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<rsp stat="ok" version="1.0">
3+
<account>
4+
<id>1</id>
5+
<company>Test Account</company>
6+
<level>SFDC Ultimate Edition</level>
7+
<website>http://www.example.com</website>
8+
<vanity_domain>http://go.example.com</vanity_domain>
9+
<plugin_campaign_id>2</plugin_campaign_id>
10+
<tracking_code_template>piAId = '10001';&#13;
11+
&#13;
12+
&#13;
13+
(function() {&#13;
14+
function async_load(){&#13;
15+
var s = document.createElement('script'); s.type = 'text/javascript';&#13;
16+
s.src = ('https:' == document.location.protocol ? 'https://pi' : 'http://cdn') + '.pardot.com/pd.js';&#13;
17+
var c = document.getElementsByTagName('script')[0]; c.parentNode.insertBefore(s, c);&#13;
18+
}&#13;
19+
if(window.attachEvent) { window.attachEvent('onload', async_load); }&#13;
20+
else { window.addEventListener('load', async_load, false); }&#13;
21+
})();</tracking_code_template>
22+
<address1>123 Main Street</address1>
23+
<address2>addr2</address2>
24+
<city>Atlanta</city>
25+
<state>GA</state>
26+
<territory>Test Territory</territory>
27+
<zip>30064</zip>
28+
<country>United States</country>
29+
<phone>123-456-4789</phone>
30+
<fax></fax>
31+
<created_at>2016-01-04 10:39:26</created_at>
32+
<updated_at>2017-08-10 05:32:19</updated_at>
33+
</account>
34+
</rsp>

0 commit comments

Comments
 (0)