Skip to content

Commit

Permalink
Surface SC-Request-Id header in the SmartcarResponse class. (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
sankethkatta authored Mar 10, 2020
1 parent a45203c commit 7f51579
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 20 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Smartcar, Inc. <[email protected]>
Copyright (c) 2020 Smartcar, Inc. <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ download links are also provided below.

### Gradle
```groovy
compile "com.smartcar.sdk:java-sdk:2.3.0"
compile "com.smartcar.sdk:java-sdk:2.4.0"
```

### Maven
```xml
<dependency>
<groupId>com.smartcar.sdk</groupId>
<artifactId>java-sdk</artifactId>
<version>2.3.0</version>
<version>2.4.0</version>
</dependency>
```

### Jar Direct Download
* [java-sdk-2.3.0.jar](https://bintray.com/smartcar/library/download_file?file_path=com%2Fsmartcar%2Fsdk%2Fjava-sdk%2F2.3.0%2Fjava-sdk-2.3.0.jar)
* [java-sdk-2.3.0-sources.jar](https://bintray.com/smartcar/library/download_file?file_path=com%2Fsmartcar%2Fsdk%2Fjava-sdk%2F2.3.0%2Fjava-sdk-2.3.0-sources.jar)
* [java-sdk-2.3.0-docs.jar](https://bintray.com/smartcar/library/download_file?file_path=com%2Fsmartcar%2Fsdk%2Fjava-sdk%2F2.3.0%2Fjava-sdk-2.3.0-docs.jar)
* [java-sdk-2.4.0.jar](https://bintray.com/smartcar/library/download_file?file_path=com%2Fsmartcar%2Fsdk%2Fjava-sdk%2F2.4.0%2Fjava-sdk-2.4.0.jar)
* [java-sdk-2.4.0-sources.jar](https://bintray.com/smartcar/library/download_file?file_path=com%2Fsmartcar%2Fsdk%2Fjava-sdk%2F2.4.0%2Fjava-sdk-2.4.0-sources.jar)
* [java-sdk-2.4.0-docs.jar](https://bintray.com/smartcar/library/download_file?file_path=com%2Fsmartcar%2Fsdk%2Fjava-sdk%2F2.4.0%2Fjava-sdk-2.4.0-docs.jar)


## Usage
Expand Down Expand Up @@ -129,5 +129,5 @@ start making requests to vehicles.
[ci-url]: https://travis-ci.com/smartcar/java-sdk
[coverage-image]: https://codecov.io/gh/smartcar/java-sdk/branch/master/graph/badge.svg?token=nZAITx7w3X
[coverage-url]: https://codecov.io/gh/smartcar/java-sdk
[javadoc-image]: https://img.shields.io/badge/javadoc-2.3.0-brightgreen.svg
[javadoc-image]: https://img.shields.io/badge/javadoc-2.4.0-brightgreen.svg
[javadoc-url]: https://smartcar.github.io/java-sdk
52 changes: 46 additions & 6 deletions docs/com/smartcar/sdk/data/SmartcarResponse.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
catch(err) {
}
//-->
var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10};
var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10};
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
Expand Down Expand Up @@ -202,35 +202,47 @@ <h3>Method Summary</h3>
</tr>
<tr id="i3" class="rowColor">
<td class="colFirst"><code>java.lang.String</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../com/smartcar/sdk/data/SmartcarResponse.html#getRequestId--">getRequestId</a></span>()</code>
<div class="block">Return the Smartcar request id from the response headers</div>
</td>
</tr>
<tr id="i4" class="altColor">
<td class="colFirst"><code>java.lang.String</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../com/smartcar/sdk/data/SmartcarResponse.html#getUnitSystem--">getUnitSystem</a></span>()</code>
<div class="block">Return the unit system of the response</div>
</td>
</tr>
<tr id="i4" class="altColor">
<tr id="i5" class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../com/smartcar/sdk/data/SmartcarResponse.html#setAge-java.util.Date-">setAge</a></span>(java.util.Date&nbsp;age)</code>
<div class="block">Stores the age of the response</div>
</td>
</tr>
<tr id="i5" class="rowColor">
<tr id="i6" class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../com/smartcar/sdk/data/SmartcarResponse.html#setData-T-">setData</a></span>(<a href="../../../../com/smartcar/sdk/data/SmartcarResponse.html" title="type parameter in SmartcarResponse">T</a>&nbsp;data)</code>
<div class="block">Stores the response data</div>
</td>
</tr>
<tr id="i6" class="altColor">
<tr id="i7" class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../com/smartcar/sdk/data/SmartcarResponse.html#setPaging-com.smartcar.sdk.data.ResponsePaging-">setPaging</a></span>(<a href="../../../../com/smartcar/sdk/data/ResponsePaging.html" title="class in com.smartcar.sdk.data">ResponsePaging</a>&nbsp;paging)</code>
<div class="block">Stores the paging information</div>
</td>
</tr>
<tr id="i7" class="rowColor">
<tr id="i8" class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../com/smartcar/sdk/data/SmartcarResponse.html#setRequestId-java.lang.String-">setRequestId</a></span>(java.lang.String&nbsp;requestId)</code>
<div class="block">Stores the age of the response</div>
</td>
</tr>
<tr id="i9" class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../com/smartcar/sdk/data/SmartcarResponse.html#setUnitSystem-java.lang.String-">setUnitSystem</a></span>(java.lang.String&nbsp;unitSystem)</code>
<div class="block">Stores the unit system of the response</div>
</td>
</tr>
<tr id="i8" class="altColor">
<tr id="i10" class="altColor">
<td class="colFirst"><code>java.lang.String</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../com/smartcar/sdk/data/SmartcarResponse.html#toString--">toString</a></span>()</code>
<div class="block">Returns the stored data string.</div>
Expand Down Expand Up @@ -428,6 +440,34 @@ <h4>setAge</h4>
</dl>
</li>
</ul>
<a name="getRequestId--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getRequestId</h4>
<pre>public&nbsp;java.lang.String&nbsp;getRequestId()</pre>
<div class="block">Return the Smartcar request id from the response headers</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the request id</dd>
</dl>
</li>
</ul>
<a name="setRequestId-java.lang.String-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>setRequestId</h4>
<pre>public&nbsp;void&nbsp;setRequestId(java.lang.String&nbsp;requestId)</pre>
<div class="block">Stores the age of the response</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>requestId</code> - the request id</dd>
</dl>
</li>
</ul>
<a name="getPaging--">
<!-- -->
</a>
Expand Down
8 changes: 8 additions & 0 deletions docs/index-all.html
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ <h2 class="title">G</h2>
<dd>
<div class="block">Returns the currently stored refresh token.</div>
</dd>
<dt><span class="memberNameLink"><a href="com/smartcar/sdk/data/SmartcarResponse.html#getRequestId--">getRequestId()</a></span> - Method in class com.smartcar.sdk.data.<a href="com/smartcar/sdk/data/SmartcarResponse.html" title="class in com.smartcar.sdk.data">SmartcarResponse</a></dt>
<dd>
<div class="block">Return the Smartcar request id from the response headers</div>
</dd>
<dt><span class="memberNameLink"><a href="com/smartcar/sdk/data/VehicleCharge.html#getState--">getState()</a></span> - Method in class com.smartcar.sdk.data.<a href="com/smartcar/sdk/data/VehicleCharge.html" title="class in com.smartcar.sdk.data">VehicleCharge</a></dt>
<dd>
<div class="block">Returns the charge state</div>
Expand Down Expand Up @@ -795,6 +799,10 @@ <h2 class="title">S</h2>
<dd>
<div class="block">Stores a new refresh token.</div>
</dd>
<dt><span class="memberNameLink"><a href="com/smartcar/sdk/data/SmartcarResponse.html#setRequestId-java.lang.String-">setRequestId(String)</a></span> - Method in class com.smartcar.sdk.data.<a href="com/smartcar/sdk/data/SmartcarResponse.html" title="class in com.smartcar.sdk.data">SmartcarResponse</a></dt>
<dd>
<div class="block">Stores the age of the response</div>
</dd>
<dt><span class="memberNameLink"><a href="com/smartcar/sdk/AuthClient.AuthUrlBuilder.html#setSingleSelect-boolean-">setSingleSelect(boolean)</a></span> - Method in class com.smartcar.sdk.<a href="com/smartcar/sdk/AuthClient.AuthUrlBuilder.html" title="class in com.smartcar.sdk">AuthClient.AuthUrlBuilder</a></dt>
<dd>&nbsp;</dd>
<dt><span class="memberNameLink"><a href="com/smartcar/sdk/AuthClient.AuthUrlBuilder.html#setSingleSelectVin-java.lang.String-">setSingleSelectVin(String)</a></span> - Method in class com.smartcar.sdk.<a href="com/smartcar/sdk/AuthClient.AuthUrlBuilder.html" title="class in com.smartcar.sdk">AuthClient.AuthUrlBuilder</a></dt>
Expand Down
4 changes: 4 additions & 0 deletions docs/serialized-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ <h4>unitSystem</h4>
<h4>age</h4>
<pre>java.util.Date age</pre>
</li>
<li class="blockList">
<h4>requestId</h4>
<pre>java.lang.String requestId</pre>
</li>
<li class="blockListLast">
<h4>paging</h4>
<pre><a href="com/smartcar/sdk/data/ResponsePaging.html" title="class in com.smartcar.sdk.data">ResponsePaging</a> paging</pre>
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
libGroup=com.smartcar.sdk
libName=java-sdk
libVersion=2.3.0
libVersion=2.4.0
libDescription=The Smartcar Java SDK
libUrl=https://github.com/smartcar/java-sdk

Expand Down
10 changes: 10 additions & 0 deletions src/integration/java/com/smartcar/sdk/VehicleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public void testImperialHeaders() throws SmartcarException {
Assert.assertEquals(response.getUnitSystem(), "imperial");
}

/**
* Tests that the vehicle correctly handles imperial headers.
*/
@Test(groups = "vehicle")
public void testRequestIdHeader() throws SmartcarException {
SmartcarResponse response = this.vehicle.odometer();
// Request ID is a UUID (36 characters)
Assert.assertEquals(response.getRequestId().length(), 36);
}

/**
* Tests that the vehicle has certain permissions.
*/
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/smartcar/sdk/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,19 @@ protected static <T extends ApiData> SmartcarResponse<T> execute(Request request

T data = ApiClient.gson.create().fromJson(body, dataType);

String unitHeader = response.header("sc-unit-system");

String unitSystem = response.header("sc-unit-system");
String ageHeader = response.header("sc-data-age");
String requestId = response.header("sc-request-id");

SmartcarResponse<T> smartcarResponse = new SmartcarResponse<T>(data);
smartcarResponse.setUnitSystem(unitSystem);
smartcarResponse.setRequestId(requestId);

if(ageHeader != null) {
DateTime date = DateTime.parse(ageHeader);

return new SmartcarResponse<T>(data, unitHeader, date.toDate());
} else {
return new SmartcarResponse<T>(data, unitHeader, null);
smartcarResponse.setAge(date.toDate());
}

return smartcarResponse;
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/smartcar/sdk/data/SmartcarResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class SmartcarResponse<T extends ApiData> extends ApiData {
private T data;
private String unitSystem;
private Date age;
private String requestId;
private ResponsePaging paging;

/**
Expand Down Expand Up @@ -110,6 +111,24 @@ public void setAge(Date age) {
this.age = age;
}

/**
* Return the Smartcar request id from the response headers
*
* @return the request id
*/
public String getRequestId() {
return this.requestId;
}

/**
* Stores the age of the response
*
* @param requestId the request id
*/
public void setRequestId(String requestId) {
this.requestId = requestId;
}

/**
* Return paging information
*
Expand Down Expand Up @@ -137,6 +156,7 @@ public String toString() {
"data=" + data +
", unitSystem='" + unitSystem + '\'' +
", age=" + age +
", requestId=" + requestId +
", paging=" + paging +
'}';
}
Expand Down

0 comments on commit 7f51579

Please sign in to comment.