/content-api-the-guardian

A java client for the guardian api: http://open-platform.theguardian.com/explore/

Primary LanguageJavaApache License 2.0Apache-2.0

content-api-the-guardian

A java client for the guardian api: http://open-platform.theguardian.com/explore/

Creating Request

Here is a basic GET request that will show how easy is to use the client, you just nedd a valid api-key:

    com.apitheguardian.GuardianContentApi api = new com.apitheguardian.GuardianContentApi("<api-key>");
    Response response = api.getContent();
    Arrays.stream(response.getResults()).forEach(System.out::println);

If you need to specify a query:

    com.apitheguardian.GuardianContentApi api = new com.apitheguardian.GuardianContentApi("<api-key>");
    Response response = api.getContent("bitcoin");
    Arrays.stream(response.getResults()).forEach(System.out::println);

If you need to specify as well a section:

    com.apitheguardian.GuardianContentApi api = new com.apitheguardian.GuardianContentApi("<api-key>");
    api.setSection("business");
    Response response = api.getContent("bitcoin");
    Arrays.stream(response.getResults()).forEach(System.out::println);

If you need to specify as well a interval of time:

    final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    com.apitheguardian.GuardianContentApi api = new com.apitheguardian.GuardianContentApi("<api-key>");
    api.setSection("business");
    api.setFromDate(dateFormat.parse("22/07/2016"));
    api.setToDate(dateFormat.parse("22/07/2017"));
    Response response = api.getContent("bitcoin");
    Arrays.stream(response.getResults()).forEach(System.out::println);

In order to build the project, open the test java file GuardianContentApiTest set the apiKey, and run from the command line:

mvn install