Skip to content

Commit

Permalink
SmartcarVehicleRequest improvements (#136)
Browse files Browse the repository at this point in the history
* feat(SmartcarVehicleRequest): add support for double body params

* feat(SmartcarVehicleRequest): add support for query params

* feat(SmartcarVehicleRequest): add support for object body params

* fix: comment out connections tests for now

The connections endpoints were updated to only work for live mode
vehicles. This will change in the coming weeks, but want to unblock
fixes for now.

* feat(SmartcarVehicleRequest): add all primitive number types
  • Loading branch information
gurpreetatwal authored Sep 27, 2023
1 parent 142ae88 commit ca190bc
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 30 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ The recommended method for obtaining the SDK is via Gradle or Maven through the

### Gradle
```groovy
compile "com.smartcar.sdk:java-sdk:3.9.0"
compile "com.smartcar.sdk:java-sdk:3.10.0"
```

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

### Jar Direct Download
* [java-sdk-3.9.0.jar](https://repo1.maven.org/maven2/com/smartcar/sdk/java-sdk/3.9.0/java-sdk-3.9.0.jar)
* [java-sdk-3.9.0-sources.jar](https://repo1.maven.org/maven2/com/smartcar/sdk/java-sdk/3.9.0/java-sdk-3.9.0-sources.jar)
* [java-sdk-3.9.0-javadoc.jar](https://repo1.maven.org/maven2/com/smartcar/sdk/java-sdk/3.9.0/java-sdk-3.9.0-javadoc.jar)
* [java-sdk-3.10.0.jar](https://repo1.maven.org/maven2/com/smartcar/sdk/java-sdk/3.10.0/java-sdk-3.10.0.jar)
* [java-sdk-3.10.0-sources.jar](https://repo1.maven.org/maven2/com/smartcar/sdk/java-sdk/3.10.0/java-sdk-3.10.0-sources.jar)
* [java-sdk-3.10.0-javadoc.jar](https://repo1.maven.org/maven2/com/smartcar/sdk/java-sdk/3.10.0/java-sdk-3.10.0-javadoc.jar)

Signatures and other downloads available at [Maven Central](https://central.sonatype.com/artifact/com.smartcar.sdk/java-sdk/3.9.0).
Signatures and other downloads available at [Maven Central](https://central.sonatype.com/artifact/com.smartcar.sdk/java-sdk/3.10.0).

## Usage

Expand Down Expand Up @@ -136,7 +136,7 @@ In accordance with the Semantic Versioning specification, the addition of suppor
[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-3.9.0-brightgreen.svg
[javadoc-image]: https://img.shields.io/badge/javadoc-3.10.0-brightgreen.svg
[javadoc-url]: https://smartcar.github.io/java-sdk
[maven-image]: https://img.shields.io/maven-central/v/com.smartcar.sdk/java-sdk.svg?label=Maven%20Central
[maven-url]: https://central.sonatype.com/artifact/com.smartcar.sdk/java-sdk
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
libGroup=com.smartcar.sdk
libName=java-sdk
libVersion=3.9.0
libVersion=3.10.0
libDescription=Smartcar Java SDK
42 changes: 22 additions & 20 deletions src/integration/java/com/smartcar/sdk/SmartcarTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,27 @@ public void testGetCompatibility() throws Exception {
Assert.assertFalse((capable));
}

@Test
public void testGetConnections() throws SmartcarException {
String testVehicleId = this.vehicleIds.getVehicleIds()[0];
ConnectionsFilter filter = new ConnectionsFilter
.Builder()
.vehicleId(testVehicleId)
.build();
GetConnections connections = Smartcar.getConnections(this.amt, filter);
Assert.assertEquals(connections.getConnections().length, 1);
}
// TODO uncomment when test mode connections are returned
// @Test
// public void testGetConnections() throws SmartcarException {
// String testVehicleId = this.vehicleIds.getVehicleIds()[0];
// ConnectionsFilter filter = new ConnectionsFilter
// .Builder()
// .vehicleId(testVehicleId)
// .build();
// GetConnections connections = Smartcar.getConnections(this.amt, filter);
// Assert.assertEquals(connections.getConnections().length, 1);
// }

@Test
public void testDeleteConnections() throws SmartcarException {
String testVehicleId = this.vehicleIds.getVehicleIds()[0];
ConnectionsFilter filter = new ConnectionsFilter
.Builder()
.vehicleId(testVehicleId)
.build();
DeleteConnections connections = Smartcar.deleteConnections(this.amt, filter);
Assert.assertEquals(connections.getConnections().length, 1);
}
// TODO uncomment when test mode connections are returned
// @Test
// public void testDeleteConnections() throws SmartcarException {
// String testVehicleId = this.vehicleIds.getVehicleIds()[0];
// ConnectionsFilter filter = new ConnectionsFilter
// .Builder()
// .vehicleId(testVehicleId)
// .build();
// DeleteConnections connections = Smartcar.deleteConnections(this.amt, filter);
// Assert.assertEquals(connections.getConnections().length, 1);
// }
}
45 changes: 43 additions & 2 deletions src/main/java/com/smartcar/sdk/SmartcarVehicleRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@
public final class SmartcarVehicleRequest {
private final String method;
private final String path;
private final Map<String, String> queryParams;
private final RequestBody body;
private final Map<String, String> headers;
private final String flags;

public static class Builder {
private String method;
private String path;
private final Map<String, String> queryParams;
private final JsonObjectBuilder body;
private final Map<String, String> headers;
private final List<String> flags;

public Builder() {
this.method = "";
this.path = "";
this.queryParams = new HashMap<>();
this.body = Json.createObjectBuilder();
this.headers = new HashMap<>();
this.flags = new ArrayList<>();
Expand All @@ -48,12 +51,37 @@ public Builder addHeader(String key, String value) {
return this;
}

public Builder addBodyParameter(String key, String value) {
public Builder addBodyParameter(String key, short value) {
this.body.add(key, value);
return this;
}

public Builder addBodyParameter(String key, int value) {
this.body.add(key, value);
return this;
}

public Builder addBodyParameter(String key, long value) {
this.body.add(key, value);
return this;
}

public Builder addBodyParameter(String key, float value) {
this.body.add(key, value);
return this;
}

public Builder addBodyParameter(String key, double value) {
this.body.add(key, value);
return this;
}

public Builder addBodyParameter(String key, boolean value) {
this.body.add(key, value);
return this;
}

public Builder addBodyParameter(String key, Boolean value) {
public Builder addBodyParameter(String key, String value) {
this.body.add(key, value);
return this;
}
Expand All @@ -63,6 +91,16 @@ public Builder addBodyParameter(String key, JsonArray values) {
return this;
}

public Builder addBodyParameter(String key, JsonObject values) {
this.body.add(key, values);
return this;
}

public Builder addQueryParameter(String key, String value) {
this.queryParams.put(key, value);
return this;
}

public Builder addFlag(String key, String value) {
this.flags.add(key + ":" + value);
return this;
Expand All @@ -87,6 +125,7 @@ public SmartcarVehicleRequest build() throws Exception {
private SmartcarVehicleRequest(Builder builder) {
this.method = builder.method;
this.path = builder.path;
this.queryParams = builder.queryParams;

JsonObject jsonBody = builder.body.build();

Expand All @@ -107,6 +146,8 @@ private SmartcarVehicleRequest(Builder builder) {

public String getPath() { return this.path; }

public Map<String, String> getQueryParams() { return this.queryParams;}

public RequestBody getBody() { return this.body; }

public Map<String, String> getHeaders() { return this.headers; }
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/smartcar/sdk/Vehicle.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ public VehicleResponse request(SmartcarVehicleRequest vehicleRequest) throws Sma
urlBuilder.addQueryParameter("flags", vehicleRequest.getFlags());
}

vehicleRequest.getQueryParams().forEach(urlBuilder::addQueryParameter);

HttpUrl url = urlBuilder.build();

Map<String, String> headers = new HashMap<>();
Expand Down

0 comments on commit ca190bc

Please sign in to comment.