Giter Club home page Giter Club logo

xively4j's Introduction

Xively Java library (BETA)

Please note that this library is still in beta.

Build Status

Overview

This is a RESTful Java client for accessing Xively API. It uses Apache HttpComponent for handling HTTP requests while remaining decoupled. This fully featured Java library parses domain objects to and from Xively JSON data format.

Quickstart

To get started:

  • Update api.key in src/main/res/config.properties with your Xively API key
  • Call XivelyService.instance() and you will get access to all operations

All configuration for the library is contained within AppConfig class. These settings are loaded from config.properties, which override the defaults defined in AppConfig.

Simple timeouts and retries can be configured via config.properties, for example:

http.connectionTimeout=5000

The connection timeout can also be set dynamically by calling:

HttpClientBuilder.getInstance().setConnectionTimeout(5000);

Main Class Summary

The DomainObject is the model interface for all objects that can be directly accessed/modified via Xively RESTful API. Each model has a equals, hashcode and deepEquals defined to streamline downstream processing.

All CRUD operations on DomaimObject(s) are provided by XivelyService.

It is designed to be fluent, here are some examples:

XivelyService.instance().feed().create(<Feed object>);
XivelyService.instance().datastream(feedId).create(<Datastream object>);
XivelyService.instance().datastream(feedId).delete(datastreamId);

Each DomainObject has a corresponding requester interface for accessing the API in com.xively.client.http.api package for all CRUD operations, and the access to these is made fluent via the user of the XivelyService. Each of the requester will provide access to all available API endpoints for the corresponding resource.

Method calls take DomainObject(s) as parameters and return DomainObject, therefore downstream application does not need to be concerned about parsing or the underlying HTTP request/response details.

On success, the requester implementation will return the object post CRUD operation:

  • create - returns the DomainObject created, fully populated with fields generated post API call
  • get (read) - returns the DomainObject retrieved
  • update - returns the updated DomainObject
  • delete - returns an empty DomainObject with the ID only

On failure, the requester implementation will throw:

  • InvalidRequestException, if the request is invalid
  • HttpException, if the response status is not 2xx

RESTful requests to Xively API are managed by DefaultRequestHandler and DefaultResponseHandler handles the responses. Therefore, this client is fully decoupled from the HTTP client implementation. Parsing to and from DomainObjects to HTTP request/response body are encapsulated in com.xively.client.http.util.ParseUtil. It may throw:

  • ParseToObjectException, if the returned response cannot be parse into DomainObject implementations
  • ParseFromObjectException, if the DomainObject implementation cannot be parse into specified data format (e.g. JSON)

Any exception thrown out of the library is a subclass of XivelyClientException.

More Example

Retrieve a feed:

Feed feed = XivelyService.instance().feed().get(123);
// the returned object will be populate with fields generated by the API

Create several datapoints and then put them into the same datastream:

Datapoint dp1 = new Datapoint();
dp1.setAt("2013-01-01T00:00:00.000000Z");
dp1.setValue("123");

Datapoint dp2 = new Datapoint();
dp2.setAt("2013-01-02T00:00:00.000000Z");
dp2.setValue("456");

// assuming your API key has permission to write
// to the feed:123 and datastream:"test_stream0"
DatastreamRequester requester = XivelyService.instance().datapoint(123, "test_stream-0");
requester.create(dp1, dp2);

dp1.setValue("234");
requester.update(dp1);

Generating Documentation

Run this to regenerate docs:

javadoc -d doc/ \
	-sourcepath src/main/java/ \
	-subpackages com.xively.client \
	-stylesheetfile src/main/res/doc_stylesheet.css

githalytics.com alpha

xively4j's People

Contributors

errordeveloper avatar baz44 avatar s0pau avatar

Watchers

James Cloos avatar gerald krug 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.