Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stuartapp/stuart-client-java

Stuart Java client
https://github.com/stuartapp/stuart-client-java

delivery java maven stuart

Last synced: 3 months ago
JSON representation

Stuart Java client

Awesome Lists containing this project

README

        

[![Codeship Status for StuartApp/stuart-client-java](https://app.codeship.com/projects/2464dd40-b15b-0137-b854-3e6824a8821c/status?branch=master)](https://app.codeship.com/projects/363060)

![Nexus](https://img.shields.io/nexus/r/https/oss.sonatype.org/com.github.stuartapp/stuart-client-java.svg)

# Stuart Java Client
For a complete documentation of all endpoints offered by the Stuart API, you can visit [Stuart API documentation](https://api-docs.stuart.com).

## Install
If you're using **Maven**, add the following dependency to your `pom.xml` file:

``` xml

com.github.stuartapp
stuart-client-java
1.0.0

```

## Usage

### Initialize HTTP client

```java
Environment environment = Environment.SANDBOX;
String apiClientId = "c6058849d0a056fc743203acb8e6a850dad103485c3edc51b16a9260cc7a7689"; // can be found here: https://dashboard.sandbox.stuart.com/settings/api
String apiClientSecret = "aa6a415fce31967501662c1960fcbfbf4745acff99acb19dbc1aae6f76c9c618"; // can be found here: https://dashboard.sandbox.stuart.com/settings/api
Authenticator authenticator = new Authenticator(environment, apiClientId, apiClientSecret);

HttpClient httpClient = new HttpClient(authenticator);
```

### Custom request

```java
public void createAJobExample() {

JsonObject job = new JsonObject();
job.addProperty("transport_type", "bike");

JsonArray pickups = new JsonArray();
JsonObject pickup = buildLocation(
"46 Boulevard Barbès, 75018 Paris",
"Wait outside for an employee to come.",
"Martin",
"Pont",
"+33698348756",
"KFC Paris Barbès"
);
pickups.add(pickup);

JsonArray dropoffs = new JsonArray();
JsonObject dropoff = buildLocation(
"156 rue de Charonne, 75011 Paris",
"code: 3492B. 3e étage droite. Sonner à Durand.",
"Alex",
"Durand",
"+33634981209",
"Durand associates."
);
dropoff.addProperty("client_reference", "reference-id-01");
dropoffs.add(dropoff);

JsonObject root = new JsonObject();
job.add("pickups", pickups);
job.add("dropoffs", dropoffs);
root.add("job", job);

ApiResponse apiResponse = httpClient.performPost("/v2/jobs", root.toString());
}

public JsonObject buildLocation(String address, String comment, String firstname, String lastname, String phone, String company) {
JsonObject location = new JsonObject();

location.addProperty("address", address);
location.addProperty("comment", comment);

JsonObject contact = new JsonObject();
location.add("contact", contact);

contact.addProperty("firstname", firstname);
contact.addProperty("lastname", lastname);
contact.addProperty("phone", phone);
contact.addProperty("company", company);

return location;
}

```