Giter Club home page Giter Club logo

sparkjava's Introduction

SparkJava API

The SparkAPI object is designed as a standalone Java interface for use with the Spark API. It implements Spark authentication via the Hybrid or OpenID methods. API calls per HTTP method provide a high-level Spark API interface and return a JSON results array on success while handling errors like session expiration for the client.

Requirements

Configuration

Once you register as a Spark developer and receive your Spark Client Id and Client Secret, open the sparkapi.properties file and set the API_KEY and API_SECRET properties. You must also set the USER_AGENT with the name of your app or your API requests will not be accepted.

Command Line Interface

The pom.xml file contains the maven configuration. To compile, run the tests, and generate the jar, execute mvn install. A SparkJava-1.0.jar file will be generated in the target/ folder for use in your project.

API Examples

Authentication

Processing Authentication:

SparkAPI provides methods for processing authentication and setting a SparkSession object upon success:

public static String isHybridAuthorized(String url);

public SparkSession hybridAuthenticate(String openIdSparkCode) throws SparkAPIClientException;

public SparkSession openIdAuthenticate(String url) throws SparkAPIClientException;

Making API calls

Once an authenticated SparkSession is set, SparkAPI methods corresponding to the four HTTP methods can be called.

On success, a Spark Response object is returned with convenience methods to access the JSON, return code, and results array.

On failure, a SparkAPIClientException is thrown.

Session renewal is handled automatically by the SparkAPI object when a session token expire error code is returned by the API.

public Response get(String path, Map<ApiParameter, String> options) throws SparkAPIClientException;

public Response post(String path, String body, Map<ApiParameter, String> options) throws SparkAPIClientException;

public Response put(String path, String body, Map<ApiParameter, String> options) throws SparkAPIClientException;

public Response delete(String path, Map<ApiParameter, String> options) throws SparkAPIClientException;

Dependencies

sparkjava's People

Contributors

dragones avatar wlmcewen avatar

Watchers

 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.