Skip to content

Commit 1c72bb2

Browse files
authored
Update API client (#31)
* Update API client with User end points * code cleanup * use openjdk9 * Add RequestInterceptor interface * Add ability to accept "User Defined Requests" * Can set role by id or name * Add UserDelete endpoint support * Add support for user Update endpoint * Resolve checkstyle violations * Update changelog * Abstract RequestInterceptor interface to not leak the underlying http client library * Update changelog * Add setters * add ability to set role by name * revert ability to set role by name * cleanup * cleanup * resolve merge conflict errors * remove explicit dependency on org.apache.logging.log4j * Refactor RequestInterceptor, add Chained implementation * cleanup * cleanup
1 parent 5e7e10d commit 1c72bb2

35 files changed

+1585
-59
lines changed

CHANGELOG.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,97 @@
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+
## 1.1.0 (12/17/2019)
6+
7+
- Removed `org.apache.logging.log4j` dependency, instead relying on the org.slf4j logging interface/facade dependency explicitly.
8+
- If your project was depending on this transitive dependency you may need to add it to your own project:
9+
10+
```
11+
<dependency>
12+
<groupId>org.apache.logging.log4j</groupId>
13+
<artifactId>log4j-api</artifactId>
14+
<version>2.12.1</version>
15+
</dependency>
16+
<dependency>
17+
<groupId>org.apache.logging.log4j</groupId>
18+
<artifactId>log4j-core</artifactId>
19+
<version>2.12.1</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.apache.logging.log4j</groupId>
23+
<artifactId>log4j-slf4j-impl</artifactId>
24+
<version>2.12.1</version>
25+
</dependency>
26+
```
27+
28+
- Adds support for additional user end points.
29+
- Adds [RequestInterceptor](src/main/java/com/darksci/pardot/api/rest/interceptor/RequestInterceptor.java) interface to allow for end-user manipulation of requests prior to being sent over the wire.
30+
- Adds [UserDefinedRequest](src/main/java/com/darksci/pardot/api/request/UserDefinedRequest.java) interface to allow for customizing/defining your own API requests.
31+
32+
```java
33+
/**
34+
* Example of defining a Custom API endpoint request. The methods required to be implemented are
35+
* defined below with examples.
36+
*
37+
* You can make use of the methods defined on the parent 'BaseRequest' class to set request parameter
38+
* as needed.
39+
*/
40+
public class MyTestRequest extends UserDefinedRequest<MyTestRequest, MyCustomReturnObject> {
41+
/**
42+
* Given the API's response String, this method should parse it into a more easily consumed object.
43+
* Alternatively, it could just return the API's response string.
44+
*
45+
* @return An object that represents the parsed API response.
46+
*/
47+
@Override
48+
public ResponseParser<MyCustomReturnObject> getResponseParser() {
49+
return (apiResponseStringapiResponseString) -> {
50+
// Your own custom parsing Logic.
51+
return new MyCustomReturnObject(apiResponseString);
52+
};
53+
}
54+
55+
/**
56+
* The API endpoint URL string.
57+
*
58+
* @return The API endpoint URL string.
59+
*/
60+
@Override
61+
public String getApiEndpoint() {
62+
return "/prospect/query";
63+
}
64+
65+
/**
66+
* Set the Id property.
67+
*/
68+
public MyTestRequest withId(final long id) {
69+
return setParam("id", id);
70+
}
71+
72+
/**
73+
* Set other property.
74+
*/
75+
public MyTestRequest withOtherProperty(final String value) {
76+
return setParam("other", value);
77+
}
78+
}
79+
```
80+
81+
```java
82+
/**
83+
* Example usage of the above class:
84+
*/
85+
PardotClient apiClient = new PardotClient(new Configuration("username", "password", "api-key"));
86+
87+
// Construct custom request class instance
88+
MyTestRequest myCustomRequest = new MyTestRequest()
89+
.withId(123L)
90+
.withOtherProperty("SomeValue");
91+
92+
// Execute the request and get the parsed response returned
93+
MyCustomReturnObject parsedApiResponse = apiClient.userDefinedRequest(myCustomRequest);
94+
```
95+
596
## 1.0.1 (12/12/2019)
697

798
#### Bugfixes

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This client library is released on Maven Central. Add a new dependency to your
2121
<dependency>
2222
<groupId>com.darksci</groupId>
2323
<artifactId>pardot-api-client</artifactId>
24-
<version>1.0.1</version>
24+
<version>1.1.0</version>
2525
</dependency>
2626
```
2727

pom.xml

Lines changed: 26 additions & 15 deletions
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>1.0.1</version>
9+
<version>1.1.0</version>
1010
<packaging>jar</packaging>
1111

1212
<!-- Require Maven 3.5.0 -->
@@ -59,6 +59,7 @@
5959

6060
<!-- Log4J Version -->
6161
<log4j2.version>2.12.1</log4j2.version>
62+
<slf4j.version>1.7.29</slf4j.version>
6263

6364
<!-- test toggling -->
6465
<skipTests>false</skipTests>
@@ -100,21 +101,11 @@
100101
<version>${jackson.version}</version>
101102
</dependency>
102103

103-
<!-- Logging -->
104+
<!-- Logging Interface -->
104105
<dependency>
105-
<groupId>org.apache.logging.log4j</groupId>
106-
<artifactId>log4j-api</artifactId>
107-
<version>${log4j2.version}</version>
108-
</dependency>
109-
<dependency>
110-
<groupId>org.apache.logging.log4j</groupId>
111-
<artifactId>log4j-core</artifactId>
112-
<version>${log4j2.version}</version>
113-
</dependency>
114-
<dependency>
115-
<groupId>org.apache.logging.log4j</groupId>
116-
<artifactId>log4j-slf4j-impl</artifactId>
117-
<version>${log4j2.version}</version>
106+
<groupId>org.slf4j</groupId>
107+
<artifactId>slf4j-api</artifactId>
108+
<version>${slf4j.version}</version>
118109
</dependency>
119110

120111
<!-- Testing Tools -->
@@ -149,6 +140,26 @@
149140
<version>2.6</version>
150141
<scope>test</scope>
151142
</dependency>
143+
144+
<!-- Logging implementation for tests -->
145+
<dependency>
146+
<groupId>org.apache.logging.log4j</groupId>
147+
<artifactId>log4j-api</artifactId>
148+
<version>${log4j2.version}</version>
149+
<scope>test</scope>
150+
</dependency>
151+
<dependency>
152+
<groupId>org.apache.logging.log4j</groupId>
153+
<artifactId>log4j-core</artifactId>
154+
<version>${log4j2.version}</version>
155+
<scope>test</scope>
156+
</dependency>
157+
<dependency>
158+
<groupId>org.apache.logging.log4j</groupId>
159+
<artifactId>log4j-slf4j-impl</artifactId>
160+
<version>${log4j2.version}</version>
161+
<scope>test</scope>
162+
</dependency>
152163
</dependencies>
153164

154165
<build>

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

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
package com.darksci.pardot.api;
1919

20+
import com.darksci.pardot.api.rest.interceptor.NoopRequestInterceptor;
21+
import com.darksci.pardot.api.rest.interceptor.RequestInterceptor;
22+
23+
import java.util.Objects;
24+
2025
/**
2126
* Configure your Pardot API credentials.
2227
*
@@ -52,6 +57,11 @@ public class Configuration {
5257
*/
5358
private boolean ignoreInvalidSslCertificates = false;
5459

60+
/**
61+
* Optional interface to allow for modifying the outbound Http Post request prior to sending it.
62+
*/
63+
private RequestInterceptor requestInterceptor = new NoopRequestInterceptor();
64+
5565
/**
5666
* Constructor.
5767
* @param email Pardot user's email address.
@@ -122,6 +132,28 @@ public Configuration withApiVersion3() {
122132
return this;
123133
}
124134

135+
/**
136+
* Allows for injecting a Http Request Interceptor instance.
137+
*
138+
* @param requestInterceptor Implementation to use.
139+
* @return Configuration instance.
140+
*/
141+
public Configuration withRequestInterceptor(final RequestInterceptor requestInterceptor) {
142+
Objects.requireNonNull(requestInterceptor);
143+
this.requestInterceptor = requestInterceptor;
144+
return this;
145+
}
146+
147+
/**
148+
* Skip all validation of SSL Certificates. This is insecure and highly discouraged!
149+
*
150+
* @return Configuration instance.
151+
*/
152+
public Configuration useInsecureSslCertificates() {
153+
this.ignoreInvalidSslCertificates = true;
154+
return this;
155+
}
156+
125157
public String getProxyHost() {
126158
return proxyHost;
127159
}
@@ -146,35 +178,47 @@ public String getPardotApiHost() {
146178
return pardotApiHost;
147179
}
148180

181+
/**
182+
* Allows for overriding the Pardot Api hostname.
183+
*
184+
* @param pardotApiHost the Pardot API hostname to use.
185+
* @return Configuration instance.
186+
*/
149187
public Configuration setPardotApiHost(final String pardotApiHost) {
150188
this.pardotApiHost = pardotApiHost;
151189
return this;
152190
}
153191

192+
/**
193+
* Allows for overriding the Pardot Api hostname.
194+
*
195+
* @param pardotApiHost the Pardot API hostname to use.
196+
* @return Configuration instance.
197+
*/
198+
public Configuration withPardotApiHost(final String pardotApiHost) {
199+
return setPardotApiHost(pardotApiHost);
200+
}
201+
154202
public String getPardotApiVersion() {
155203
return pardotApiVersion;
156204
}
157205

158-
public void setPardotApiVersion(final String pardotApiVersion) {
206+
public Configuration setPardotApiVersion(final String pardotApiVersion) {
159207
this.pardotApiVersion = pardotApiVersion;
208+
return this;
160209
}
161210

162211
public String getApiKey() {
163212
return apiKey;
164213
}
165214

166-
public void setApiKey(final String apiKey) {
215+
public Configuration setApiKey(final String apiKey) {
167216
this.apiKey = apiKey;
217+
return this;
168218
}
169219

170-
/**
171-
* Skip all validation of SSL Certificates. This is insecure and highly discouraged!
172-
*
173-
* @return Configuration instance.
174-
*/
175-
public Configuration useInsecureSslCertificates() {
176-
this.ignoreInvalidSslCertificates = true;
177-
return this;
220+
public RequestInterceptor getRequestInterceptor() {
221+
return requestInterceptor;
178222
}
179223

180224
public boolean getIgnoreInvalidSslCertificates() {

0 commit comments

Comments
 (0)