Skip to content

sparkapi/SparkJava

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Java interface for use with the Spark API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages