项目作者: StuartApp

项目描述 :
Stuart Java client
高级语言: Java
项目地址: git://github.com/StuartApp/stuart-client-java.git
创建时间: 2018-03-19T17:10:03Z
项目社区:https://github.com/StuartApp/stuart-client-java

开源协议:MIT License

下载


Codeship Status for StuartApp/stuart-client-java

Nexus

Stuart Java Client

For a complete documentation of all endpoints offered by the Stuart API, you can visit Stuart API documentation.

Install

If you’re using Maven, add the following dependency to your pom.xml file:

  1. <dependency>
  2. <groupId>com.github.stuartapp</groupId>
  3. <artifactId>stuart-client-java</artifactId>
  4. <version>1.0.0</version>
  5. </dependency>

Usage

Initialize HTTP client

  1. Environment environment = Environment.SANDBOX;
  2. String apiClientId = "c6058849d0a056fc743203acb8e6a850dad103485c3edc51b16a9260cc7a7689"; // can be found here: https://dashboard.sandbox.stuart.com/settings/api
  3. String apiClientSecret = "aa6a415fce31967501662c1960fcbfbf4745acff99acb19dbc1aae6f76c9c618"; // can be found here: https://dashboard.sandbox.stuart.com/settings/api
  4. Authenticator authenticator = new Authenticator(environment, apiClientId, apiClientSecret);
  5. HttpClient httpClient = new HttpClient(authenticator);

Custom request

  1. public void createAJobExample() {
  2. JsonObject job = new JsonObject();
  3. job.addProperty("transport_type", "bike");
  4. JsonArray pickups = new JsonArray();
  5. JsonObject pickup = buildLocation(
  6. "46 Boulevard Barbès, 75018 Paris",
  7. "Wait outside for an employee to come.",
  8. "Martin",
  9. "Pont",
  10. "+33698348756",
  11. "KFC Paris Barbès"
  12. );
  13. pickups.add(pickup);
  14. JsonArray dropoffs = new JsonArray();
  15. JsonObject dropoff = buildLocation(
  16. "156 rue de Charonne, 75011 Paris",
  17. "code: 3492B. 3e étage droite. Sonner à Durand.",
  18. "Alex",
  19. "Durand",
  20. "+33634981209",
  21. "Durand associates."
  22. );
  23. dropoff.addProperty("client_reference", "reference-id-01");
  24. dropoffs.add(dropoff);
  25. JsonObject root = new JsonObject();
  26. job.add("pickups", pickups);
  27. job.add("dropoffs", dropoffs);
  28. root.add("job", job);
  29. ApiResponse apiResponse = httpClient.performPost("/v2/jobs", root.toString());
  30. }
  31. public JsonObject buildLocation(String address, String comment, String firstname, String lastname, String phone, String company) {
  32. JsonObject location = new JsonObject();
  33. location.addProperty("address", address);
  34. location.addProperty("comment", comment);
  35. JsonObject contact = new JsonObject();
  36. location.add("contact", contact);
  37. contact.addProperty("firstname", firstname);
  38. contact.addProperty("lastname", lastname);
  39. contact.addProperty("phone", phone);
  40. contact.addProperty("company", company);
  41. return location;
  42. }