Class Vehicle


  • public class Vehicle
    extends java.lang.Object
    Smartcar Vehicle API Object
    • Constructor Detail

      • Vehicle

        public Vehicle​(java.lang.String vehicleId,
                       java.lang.String accessToken)
        Initializes a new Vehicle.
        Parameters:
        vehicleId - the vehicle ID
        accessToken - the OAuth 2.0 access token
      • Vehicle

        public Vehicle​(java.lang.String vehicleId,
                       java.lang.String accessToken,
                       SmartcarVehicleOptions options)
        Initializes a new Vehicle with provided options
        Parameters:
        vehicleId - vehicleId the vehicle ID
        accessToken - accessToken the OAuth 2.0 access token
        options - optional arguments provided with a SmartcarVehicleOptions instance
    • Method Detail

      • getVersion

        public java.lang.String getVersion()
        Gets the version of Smartcar API that this vehicle is using
        Returns:
        String representing version
      • getFlags

        public java.lang.String getFlags()
        Gets the flags that are passed to the vehicle object as a serialized string
        Returns:
        serialized string of the flags
      • call

        protected <T extends ApiData> T call​(java.lang.String path,
                                             java.lang.String method,
                                             okhttp3.RequestBody body,
                                             java.lang.String accessToken,
                                             java.lang.Class<T> type)
                                      throws SmartcarException
        Executes an API request under the VehicleIds endpoint.
        Parameters:
        path - the path to the sub-endpoint
        method - the method of the request
        body - the body of the request
        type - the type into which the response will be parsed
        Returns:
        the parsed response
        Throws:
        SmartcarException - if the request is unsuccessful
      • call

        protected <T extends ApiData> T call​(java.lang.String path,
                                             java.lang.String method,
                                             okhttp3.RequestBody body,
                                             java.util.Map<java.lang.String,​java.lang.String> query,
                                             java.lang.Class<T> type)
                                      throws SmartcarException
        Throws:
        SmartcarException
      • setChargeLimit

        public ActionResponse setChargeLimit​(double limit)
                                      throws SmartcarException
        Set a vehicle's charge limit
        Parameters:
        limit - the new charge limit to set.
        Returns:
        a response indicating success
        Throws:
        SmartcarException - if the request is unsuccessful
      • sendDestination

        public ActionResponse sendDestination​(double latitude,
                                              double longitude)
                                       throws SmartcarException
        Send request to the /navigation/destination endpoint to set the navigation destination
        Parameters:
        latitude - A double representing the destination's latitude
        longitude - A double representing the destination's longitude
        Returns:
        a response indicating success
        Throws:
        SmartcarException - if the request is unsuccessful
        java.lang.IllegalArgumentException - if the latitude is not between -90.0 and 90.0 or if the longitude is not between -180.0 and 180.0
      • unsubscribe

        public UnsubscribeResponse unsubscribe​(java.lang.String applicationManagementToken,
                                               java.lang.String webhookId)
                                        throws SmartcarException
        Unsubscribe vehicle from a webhook
        Returns:
        response indicating successful removal from the subscription
        Throws:
        SmartcarException - if the request is unsuccessful
      • batch

        public BatchResponse batch​(java.lang.String[] paths)
                            throws SmartcarException
        Send request to the /batch endpoint
        Parameters:
        paths - the paths of endpoints to send requests to (ex. "/odometer", "/location", ...)
        Returns:
        the BatchResponse object containing the response from all the requested endpoints
        Throws:
        SmartcarException - if the request is unsuccessful
      • request

        public VehicleResponse request​(SmartcarVehicleRequest vehicleRequest)
                                throws SmartcarException,
                                       java.io.IOException
        General purpose method to make a request to a Smartcar endpoint - can be used to make requests to brand specific endpoints.
        Parameters:
        vehicleRequest - with options for this request. See Smartcar.SmartcarVehicleRequest
        Returns:
        the VehicleResponse object containing the response from the requested endpoint
        Throws:
        SmartcarException - if the request is unsuccessful
        java.io.IOException
      • setUnitSystem

        public void setUnitSystem​(Vehicle.UnitSystem unitSystem)
        Sets the preferred unit system for subsequent API requests.
        Parameters:
        unitSystem - the desired unit system