Documentation
¶
Overview ¶
Package smartcar is the official Go SDK of the Smartcar API. Smartcar is the only vehicle API built for developers, by developers. Learn more about Smartcar here, https://smartcar.com/
Index ¶
- Variables
- type Auth
- type AuthParams
- type AuthURLParams
- type Battery
- type BatteryCapacity
- type Charge
- type ChargeControl
- type Client
- type Data
- type Disconnect
- type ExchangeCodeParams
- type ExchangeRefreshTokenParams
- type Fuel
- type Info
- type Key
- type Location
- type MakeBypass
- type Odometer
- type Oil
- type Permissions
- type PermissionsParams
- type ResponseHeaders
- type Security
- type SingleSelect
- type TirePressure
- type Token
- type TokenExpiredParams
- type UnitSystem
- type UnitsParams
- type UserIDParams
- type VIN
- type VINCompatibleParams
- type Vehicle
- type VehicleIDsParams
- type VehicleParams
Constants ¶
This section is empty.
Variables ¶
var APIVersion string = "1.0"
APIVersion is the default version of API to use
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth interface {
GetAuthURL(*AuthURLParams) (string, error)
ExchangeCode(context.Context, *ExchangeCodeParams) (*Token, error)
ExchangeRefreshToken(context.Context, *ExchangeRefreshTokenParams) (*Token, error)
}
Auth interface is a...
type AuthParams ¶
type AuthParams struct {
ClientID string
ClientSecret string
RedirectURI string
Scope []string
TestMode bool
}
AuthParams is a param in client.NewAuth
type AuthURLParams ¶
type AuthURLParams struct {
ForceApproval bool
State string
Flags []string
MakeBypass
SingleSelect
}
AuthURLParams contains the AuthClient, Pro authorization features and all fields that can be used to construct an auth URL.
type Battery ¶
type Battery struct {
PercentRemaining float64 `json:"percentRemaining"`
Range float64 `json:"range"`
ResponseHeaders
}
Battery formats response returned from vehicle.GetBattery().
type BatteryCapacity ¶ added in v1.3.0
type BatteryCapacity struct {
Capacity float64 `json:"capacity"`
ResponseHeaders
}
BatteryCapacity formats response returned from vehicle.GetBatteryCapacity().
type Charge ¶
type Charge struct {
IsPluggedIn bool `json:"isPluggedIn"`
State string `json:"state"`
ResponseHeaders
}
Charge formats response returned from vehicle.GetCharge().
type ChargeControl ¶
type ChargeControl struct {
Status string `json:"status"`
ResponseHeaders
}
ChargeControl Charge formats response returned from the vehicle.StartCharge(), vehicle.StopCharge().
type Client ¶
type Client interface {
GetUserID(context.Context, *UserIDParams) (*string, error)
GetVehicleIDs(context.Context, *VehicleIDsParams) (*[]string, error)
IsTokenExpired(*TokenExpiredParams) bool
IsVINCompatible(context.Context, *VINCompatibleParams) (bool, error)
HasPermissions(context.Context, Vehicle, *PermissionsParams) (bool, error)
NewAuth(*AuthParams) Auth
NewVehicle(*VehicleParams) Vehicle
SetAPIVersion(string)
}
Client exposes methods that allow you to interact with Smartcar's API that are not part of Vehicle or Auth.
type Data ¶
type Data struct {
Battery *Battery `json:"battery,omitempty"`
BatteryCapacity *BatteryCapacity `json:"batteryCapacity,omitempty"`
Charge *Charge `json:"charge,omitempty"`
Fuel *Fuel `json:"fuel,omitempty"`
Info *Info `json:"info,omitempty"`
Location *Location `json:"location,omitempty"`
Odometer *Odometer `json:"odometer,omitempty"`
Oil *Oil `json:"oil,omitempty"`
Permissions *Permissions `json:"permissions,omitempty"`
TirePressure *TirePressure `json:"tirePressure,omitempty"`
VIN *VIN `json:"vin,omitempty"`
}
Data formats responses returned from vehicle.Batch().
type Disconnect ¶
type Disconnect struct {
Status string `json:"status"`
ResponseHeaders
}
Disconnect formats response returned from vehicle.Disconnect().
type ExchangeRefreshTokenParams ¶
type ExchangeRefreshTokenParams struct {
Token string
}
ExchangeRefreshTokenParams struct
type Fuel ¶
type Fuel struct {
AmountRemaining float64 `json:"amountRemaining"`
PercentRemaining float64 `json:"percentRemaining"`
Range float64 `json:"range"`
ResponseHeaders
}
Fuel formats response returned from vehicle.GetFuel().
type Info ¶
type Info struct {
ID string `json:"id"`
Make string `json:"make"`
Model string `json:"model"`
Year int `json:"year"`
ResponseHeaders
}
Info formats response returned from vehicle.GetInfo().
type Key ¶
type Key string
Key is a type to used for API endpoints
const ( BatteryPath Key = "/battery" BatteryCapacityPath Key = "/battery/capacity" ChargePath Key = "/charge" FuelPath Key = "/fuel" InfoPath Key = "/" LocationPath Key = "/location" OdometerPath Key = "/odometer" OilPath Key = "/engine/oil" PermissionsPath Key = "/permissions" TirePressurePath Key = "/tires/pressure" VINPath Key = "/vin" )
Helper types to use in vehicle.Batch()
type Location ¶
type Location struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
ResponseHeaders
}
Location formats response returned from vehicle.GetLocation().
type MakeBypass ¶
type MakeBypass struct {
Make string
}
MakeBypass uses a make to bypass the Smartcar Connect brand selector. Smartcar Pro feature.
type Odometer ¶
type Odometer struct {
Distance float64 `json:"distance"`
ResponseHeaders
}
Odometer formats response returned from vehicle.GetOdometer().
type Oil ¶
type Oil struct {
LifeRemaining float64 `json:"lifeRemaining"`
ResponseHeaders
}
Oil formats response returned from vehicle.GetOil().
type Permissions ¶
type Permissions struct {
Permissions []string `json:"permissions"`
ResponseHeaders
}
Permissions formats response returned from vehicle.GetPermissions().
type PermissionsParams ¶
type PermissionsParams struct {
Permissions []string
}
PermissionsParams is a param in client.HasPermissions
type ResponseHeaders ¶
type ResponseHeaders struct {
// Deprecated: Should use DataAge instead of Age
Age string `json:"age,omitempty"`
DataAge string `json:"dataAge,omitempty"`
RequestID string `json:"requestId,omitempty"`
UnitSystem UnitSystem `json:"unitSystem,omitempty"`
}
ResponseHeaders is a struct that has Smartcar's API response headers.
type Security ¶
type Security struct {
Status string `json:"status"`
ResponseHeaders
}
Security formats response returned from the vehicle.Lock(), vehicle.Unlock().
type SingleSelect ¶
SingleSelect will only authorize vehicles that match the given properties. Smartcar Pro feature.
type TirePressure ¶
type TirePressure struct {
FrontLeft float64 `json:"frontLeft"`
FrontRight float64 `json:"frontRight"`
BackLeft float64 `json:"backLeft"`
BackRight float64 `json:"backRight"`
ResponseHeaders
}
TirePressure formats response returned from vehicle.GetTirePressure().
type Token ¶
type Token struct {
Access string `json:"access_token"`
AccessExpiry time.Time `json:"access_expiry"`
Refresh string `json:"refresh_token"`
RefreshExpiry time.Time `json:"refresh_expiry"`
ExpiresIn int `json:"expires_in"`
}
Token is returned by auth.ExchangeCode and auth.ExchangeRefreshToken.
type TokenExpiredParams ¶
TokenExpiredParams is a param in client.IsTokenExpired
type UnitSystem ¶
type UnitSystem string
UnitSystem type that will have either imperic or metric.
const ( Metric UnitSystem = "metric" Imperial UnitSystem = "imperial" )
/ UnitSystem constants that initialize metric or imperial.
type UnitsParams ¶
type UnitsParams struct {
Units UnitSystem
}
UnitsParams struct is UnitsParam is a param in vehicle.SetUnitSystem
type UserIDParams ¶
type UserIDParams struct {
Access string
}
UserIDParams is a param in client.GetUserID
type VIN ¶
type VIN struct {
VIN string `json:"vin"`
ResponseHeaders
}
VIN formats response returned from vehicle.GetVIN().
type VINCompatibleParams ¶
type VINCompatibleParams struct {
VIN string
Scope []string
Country string
ClientID string
ClientSecret string
}
VINCompatibleParams is a param in client.IsVINCompatible
type Vehicle ¶
type Vehicle interface {
Batch(context.Context, ...Key) (*Data, error)
Disconnect(context.Context) (*Disconnect, error)
GetBattery(context.Context) (*Battery, error)
GetBatteryCapacity(context.Context) (*BatteryCapacity, error)
GetCharge(context.Context) (*Charge, error)
GetFuel(context.Context) (*Fuel, error)
GetInfo(context.Context) (*Info, error)
GetLocation(context.Context) (*Location, error)
GetOdometer(context.Context) (*Odometer, error)
GetOil(context.Context) (*Oil, error)
GetPermissions(context.Context) (*Permissions, error)
GetTiresPressure(context.Context) (*TirePressure, error)
GetVIN(context.Context) (*VIN, error)
Lock(context.Context) (*Security, error)
SetUnitSystem(*UnitsParams) error
Unlock(context.Context) (*Security, error)
StartCharge(context.Context) (*ChargeControl, error)
StopCharge(context.Context) (*ChargeControl, error)
}
Vehicle is an interface that contains all public methods available for vehicle. vehicle needs to implement this methods to be able to expose them.
type VehicleIDsParams ¶
type VehicleIDsParams struct {
Access string
}
VehicleIDsParams is a param in client.GetVehicleIDs
type VehicleParams ¶
type VehicleParams struct {
ID string
AccessToken string
UnitSystem UnitSystem
}
VehicleParams is a param in client.NewVehicle