GithubHelp home page GithubHelp logo

washingtonpost / wordpress-rest-api-java-client Goto Github PK

View Code? Open in Web Editor NEW
10.0 9.0 10.0 260 KB

Java Client for connecting to and parsing JSON coming our of a WordPress REST API plugin

License: MIT License

Java 100.00%

wordpress-rest-api-java-client's Introduction

wordpress-rest-api-java-client

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.

Including this JAR

Add this dependency to your Maven POM:

<dependency>
    <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
</dependency>

Constructing a default client with BasicAuth autentication:

import com.washingtonpost.wordpress.rest.api.JAXRSWordPressClient;
import com.washingtonpost.wordpress.rest.api.JAXRSWordPressFactory;

public class FooClazz {

    public void myMethod() {
        JAXRSWordPressClient myClient = (new JAXRSWordPressFactory())
                                               .withBaseUrl("http://wordpress.foo.com/wp-json")
                                               .withCredentials("joe", "secret")
                                               .build();
        ...
    }

Testing with this client

This client ships with a MockWordPressClient that loads a classpath resource and returns the JSON contents of that resource as fixture data, like so:

import com.washingtonpost.wordpress.rest.api.model.WordPressPost;

public class TestJAXRSWordPressClient {

    @Test
    public void testHappyPath() throws IOException {
        WordPressClient client = new WordPressClientFactory()
                                        .withMockResource("off-the-shelf-response.json")
                                        .build();
        ...
    }

Extending Functionality

To use this client to parse a different batch of JSON than comes with the standard WordPress REST API, implement 2 classes:

  • implement com.washingtonpost.wordpress.rest.api.model.Post // just a marker interface
  • extend the com.washingtonpost.wordpress.rest.api.transformers.AbstractTransformer (or just implement your own Transformer)

Register your transformer with the Client when you use the ClientFactory to create your Client instance, like:

JAXRSWordPressClient myClient = (new JAXRSWordPressFactory())
                                               .withTransformer(new MySpecialTransformer())
                                               .withBaseUrl("http://wordpress.foo.com/wp-json")
                                               .build();

What this Client doesn't (yet) support

  • OAuth authentication
  • Any REST method other than a GET to the WordPress API's /posts endpoint

wordpress-rest-api-java-client's People

Contributors

tvaughan77 avatar gengel avatar

Stargazers

 avatar Jamith Nimantha avatar Lei Chen avatar Arne Zelasko avatar Tiago Oliveira avatar Łukasz Rżanek avatar Kemal Dogan avatar  avatar Misael avatar Jeremy O'Day avatar

Watchers

Timothy Kim avatar Chad Moone avatar Seth Blanchard avatar James Cloos avatar Greg Franczyk avatar Rupesh Shah avatar  avatar  avatar  avatar

wordpress-rest-api-java-client's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.