GithubHelp home page GithubHelp logo

infogram-java's Introduction

#Infogram-Java

A library to view, create and update infographics on Infogr.am. For details on the different calls see https://developers.infogr.am/rest/

##Usage

To make the API calls, use the net.infogram.api.InfogramAPI class. The response is wrapped in an appropriate Response object, containing the metadata and the body of the response. The response body can be accessed via a java.io.InputStream.

import net.infogram.api.InfogramAPI;
import net.infogram.api.response.Response;
// ...

InfogramAPI infogram = new InfogramAPI(YOUR_API_KEY, YOUR_API_SECRET);

try {
    Response response = infogram.sendRequest("GET", "infographics", null);

    if (response.isSuccessful()) {
        InputStream is = response.getResponseBody();

        // ...
    } else {
        String errmsg = String.format("The server returned %d %s", response.getHttpStatusCode(), response.getHttpStatusMessage());
        System.err.println(errmsg);
    }
} catch (IOException e) {
    System.err.println("There was a problem connecting to the server");
    e.printStackTrace();
}

To make the calls asynchronously, use the you can wrap a Future around the sendRequest() method. An example is given below.

import net.infogram.api.InfogramAPI;
import net.infogram.api.response.Response;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

// ...

InfogramAPI infogram = new InfogramAPI(YOUR_API_KEY, YOUR_API_SECRET);

FutureTask responseFuture = new FutureTask<Response>(new Callable<Response>() {
@Override
    public Response call() throws Exception {
        return sendRequest("GET", "infographics", null);
    }
});

ExecutorService executor = Executors.newCachedThreadPool();
executor.execute(responseFuture);

// ...

Response response = responseFuture.get();

// ...

executor.shutdown();

More samples can be found in infogram-java-samples project

infogram-java's People

Contributors

ansiss avatar kaspars avatar labsansis avatar

Watchers

James Cloos avatar  avatar

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.