Skip to content

Commit

Permalink
feat: adds sendDestination (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
sektek authored Dec 13, 2023
1 parent fcdea09 commit fb482a2
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 13 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.10.1"
compile "com.smartcar.sdk:java-sdk:3.11.0"
```

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

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

Signatures and other downloads available at [Maven Central](https://central.sonatype.com/artifact/com.smartcar.sdk/java-sdk/3.10.1).
Signatures and other downloads available at [Maven Central](https://central.sonatype.com/artifact/com.smartcar.sdk/java-sdk/3.11.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.10.1-brightgreen.svg
[javadoc-image]: https://img.shields.io/badge/javadoc-3.11.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.10.1
libVersion=3.11.0
libDescription=Smartcar Java SDK
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public void beforeSuite() throws Exception {
this.getVehicle(
"FORD",
new String[]{
"required:control_charge", "required:control_security", "read_battery", "read_charge"
"required:control_charge",
"required:control_security",
"required:control_navigation",
"read_battery",
"read_charge"
});
}

Expand Down Expand Up @@ -223,6 +227,14 @@ public void testActionStopCharge() throws SmartcarException {
this.eVehicle.stopCharge();
}

/**
* Test that the vehicle sendDestination action works.
*/
@Test(groups = "vehicle")
public void testActionSendDestination() throws SmartcarException {
this.eVehicle.sendDestination(47.6205063, -122.3518523);
}

/**
* Tests that the batch request method works.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
/** Provides all shared functionality among integration tests. */
public class AuthHelpers {
public static final String[] DEFAULT_SCOPE = {
"required:control_navigation",
"required:control_security",
"required:read_vehicle_info",
"required:read_location",
"required:read_odometer",
"required:control_security",
"required:read_vin",
"required:read_fuel",
"required:read_battery",
Expand Down
41 changes: 38 additions & 3 deletions src/main/java/com/smartcar/sdk/Vehicle.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import okhttp3.HttpUrl;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import javax.json.Json;
import javax.json.JsonArray;
Expand All @@ -13,7 +12,6 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;


/** Smartcar Vehicle API Object */
Expand All @@ -23,6 +21,11 @@ public enum UnitSystem {
METRIC,
}

private static final double LATITUDE_MIN = -90.0;
private static final double LATITUDE_MAX = 90.0;
private static final double LONGITUDE_MIN = -180.0;
private static final double LONGITUDE_MAX = 180.0;

private final String vehicleId;
private final String accessToken;
private Vehicle.UnitSystem unitSystem;
Expand Down Expand Up @@ -58,7 +61,7 @@ public Vehicle(String vehicleId, String accessToken, SmartcarVehicleOptions opti

/**
* Gets the version of Smartcar API that this vehicle is using
* @return
* @return String representing version
*/
public String getVersion() {
return this.version;
Expand Down Expand Up @@ -369,6 +372,38 @@ public VehicleLockStatus lockStatus() throws SmartcarException {
return this.call("security", "GET", null, VehicleLockStatus.class);
}

/**
* Send request to the /navigation/destination endpoint to set the navigation destination
*
* @param latitude A double representing the destination's latitude
* @param longitude A double representing the destination's longitude
* @return a response indicating success
* @throws SmartcarException if the request is unsuccessful
* @throws IllegalArgumentException if the latitude is not between -90.0 and 90.0 or
* if the longitude is not between -180.0 and 180.0
*/
public ActionResponse sendDestination(double latitude, double longitude) throws SmartcarException {
if (latitude < LATITUDE_MIN || latitude > LATITUDE_MAX) {
throw new IllegalArgumentException(
String.format("Latitude must be between %f and %f", LATITUDE_MIN, LATITUDE_MAX));
}
if (longitude < LONGITUDE_MIN || longitude > LONGITUDE_MAX) {
throw new IllegalArgumentException(
String.format("Longitude must be between %f and %f", LONGITUDE_MIN, LONGITUDE_MAX));
}

JsonObject json = Json.createObjectBuilder()
.add("latitude", latitude)
.add("longitude", longitude)
.build();

RequestBody requestBody = RequestBody.create(ApiClient.JSON, json.toString());

return this.call("navigation/destination", "POST", requestBody, ActionResponse.class);
}



/**
* Subscribe vehicle to a webhook
*
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/smartcar/sdk/VehicleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,28 @@ public void testVehicleLockStatus() throws Exception {
Assert.assertEquals(chargingPort.getStatus(), "CLOSED");
}

@Test
public void testSendDestination() throws Exception {
loadAndEnqueueResponse("SendDestination");

ActionResponse res = this.subject.sendDestination(47.6205063, -122.3518523);

Assert.assertEquals(res.getStatus(), "success");
Assert.assertEquals(res.getMessage(), "Message sent successfully to vehicle");
}

@Test
public void testSendDestinationIllegalArgumentLatitude() {
Assert.assertThrows(IllegalArgumentException.class,
() -> this.subject.sendDestination(147.6205063, -122.3518523));
}

@Test
public void testSendDestinationIllegalArgumentLongitude() {
Assert.assertThrows(IllegalArgumentException.class,
() -> this.subject.sendDestination(47.6205063, -192.3518523));
}

@Test
public void testSubscribe() throws Exception {
loadAndEnqueueResponse("SubscribeVehicle");
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/SendDestination.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"status": "success",
"message": "Message sent successfully to vehicle"
}

0 comments on commit fb482a2

Please sign in to comment.