Name: wordpress-rest-api-java-client
Owner: The Washington Post
Description: Java Client for connecting to and parsing JSON coming our of a WordPress REST API plugin
Created: 2015-08-19 14:23:11.0
Updated: 2018-01-07 07:32:19.0
Pushed: 2015-08-26 15:51:12.0
Homepage: null
Size: 260
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Java Client for connecting to and parsing JSON coming our of a WordPress REST API plugin
This Client uses JAX-RS to connect to a remote WordPress REST API and retrieve the lists of Posts from the /posts endpoint. The client passes through whatever query parameters sent to the getPosts( )
method directly to the WordPress REST API. This client comes with a default implementation of a Transformer class that knows how to transform WordPress JSON into a “WordPressPost.java” POJO.
If your WordPress JSON feed is customized to include fields not contained in the off-the-shelf WordPress JSON API installation, you can construct an instance of a WordPressClient with your own Transformer/POJO pair that's suitable for your organization.
Add this dependency to your Maven POM:
endency>
<groupId>com.washingtonpost.wordpress</groupId>
<artifactId>wordpress-rest-api-client</artifactId>
<version>x.y.z</version> // Check RELEASE_NOTES.md for the best version for your needs
pendency>
rt com.washingtonpost.wordpress.rest.api.JAXRSWordPressClient;
rt com.washingtonpost.wordpress.rest.api.JAXRSWordPressFactory;
ic class FooClazz {
public void myMethod() {
JAXRSWordPressClient myClient = (new JAXRSWordPressFactory())
.withBaseUrl("http://wordpress.foo.com/wp-json")
.withCredentials("joe", "secret")
.build();
...
}
This client ships with a MockWordPressClient that loads a classpath resource and returns the JSON contents of that resource as fixture data, like so:
rt com.washingtonpost.wordpress.rest.api.model.WordPressPost;
ic class TestJAXRSWordPressClient {
@Test
public void testHappyPath() throws IOException {
WordPressClient client = new WordPressClientFactory()
.withMockResource("off-the-shelf-response.json")
.build();
...
}
To use this client to parse a different batch of JSON than comes with the standard WordPress REST API, implement 2 classes:
Register your transformer with the Client when you use the ClientFactory to create your Client instance, like:
SWordPressClient myClient = (new JAXRSWordPressFactory())
.withTransformer(new MySpecialTransformer())
.withBaseUrl("http://wordpress.foo.com/wp-json")
.build();