smartcar / java-sdk

Java client SDK for the Smartcar API.
https://smartcar.github.io/java-sdk
MIT License
20 stars 20 forks source link

SmartcarVehicleRequest improvements for Ford Charge Schedule #136

Closed gurpreetatwal closed 1 year ago

gurpreetatwal commented 1 year ago

import com.google.gson.Gson;
import com.smartcar.sdk.*;
import com.smartcar.sdk.data.*;
import javax.json.*;

public class Main {
  private static Gson gson = new Gson();

  public static void main(String[] args) throws Exception {
    String accessToken = "redacted";

    VehicleIds vehiclesResponse = Smartcar.getVehicles(accessToken);
    String[] vehicleIds = vehiclesResponse.getVehicleIds();

    Vehicle vehicle = new Vehicle(vehicleIds[0], accessToken);

    VehicleAttributes attributes = vehicle.attributes();
    System.out.println(gson.toJson(attributes));

    JsonArrayBuilder weekday = Json.createArrayBuilder().add(
        Json.createObjectBuilder().add("start", "05:00").add("end", "07:00"));

    JsonArrayBuilder weekend = Json.createArrayBuilder().add(
        Json.createObjectBuilder().add("start", "06:00").add("end", "07:00"));

    JsonObject chargingWindows = Json.createObjectBuilder()
                                       .add("weekday", weekday)
                                       .add("weekend", weekend)
                                       .build();

    JsonObject chargingLocation = Json.createObjectBuilder()
                                      .add("chargeLimit", 1.0)
                                      .add("chargeOnPlugin", false)
                                      .add("chargingWindows", chargingWindows)
                                      .build();

    SmartcarVehicleRequest request =
        new SmartcarVehicleRequest.Builder()
            .method("PUT")
            .path("ford/charge/schedule_by_location")
            .addQueryParameter("latitude", "40.000000")
            .addQueryParameter("longitude", "-120.00000")
            .addBodyParameter("chargingLocation", chargingLocation)
            .build();

    VehicleResponse chargeSched = vehicle.request(request);

    System.out.println(gson.toJson(chargeSched));
  }
}

Asana: https://app.asana.com/0/1205492687081021/1205552473166823/f

codecov[bot] commented 1 year ago

Codecov Report

Merging #136 (ac123a3) into master (4111656) will decrease coverage by 4.85%. Report is 1 commits behind head on master. The diff coverage is 22.22%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #136      +/-   ##
============================================
- Coverage     73.59%   68.74%   -4.85%     
+ Complexity      245      235      -10     
============================================
  Files            50       50              
  Lines           977      995      +18     
  Branches         69       69              
============================================
- Hits            719      684      -35     
- Misses          217      279      +62     
+ Partials         41       32       -9     
Flag Coverage Δ
integration 55.47% <22.22%> (-4.61%) :arrow_down:
test 46.13% <22.22%> (-0.45%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/main/java/com/smartcar/sdk/Vehicle.java 96.06% <100.00%> (+0.03%) :arrow_up:
.../java/com/smartcar/sdk/SmartcarVehicleRequest.java 61.29% <17.64%> (-16.49%) :arrow_down:

... and 6 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 142ae88...ac123a3. Read the comment docs.