Add sandbox config for testing purposes
This commit is contained in:
parent
c0e501d654
commit
c70ef769a9
2 changed files with 18 additions and 8 deletions
|
|
@ -27,6 +27,7 @@ func NewMercedesFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
|||
embed `mapstructure:",squash"`
|
||||
ClientID, ClientSecret string
|
||||
VIN string
|
||||
Sandbox bool
|
||||
Cache time.Duration
|
||||
}{
|
||||
Cache: interval,
|
||||
|
|
@ -60,7 +61,7 @@ func NewMercedesFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
api := mercedes.NewAPI(log, identity)
|
||||
api := mercedes.NewAPI(log, identity, cc.Sandbox)
|
||||
|
||||
v := &Mercedes{
|
||||
embed: &cc.embed,
|
||||
|
|
|
|||
|
|
@ -8,18 +8,20 @@ import (
|
|||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
// const BaseURI = "https://api.mercedes-benz.com/vehicledata_tryout/v2"
|
||||
|
||||
// BaseURI is the Mercedes api base URI
|
||||
const BaseURI = "https://api.mercedes-benz.com/vehicledata/v2"
|
||||
const (
|
||||
// BaseURI is the Mercedes api base URI
|
||||
BaseURI = "https://api.mercedes-benz.com/vehicledata/v2"
|
||||
SandboxBaseURI = "https://api.mercedes-benz.com/vehicledata_tryout/v2"
|
||||
)
|
||||
|
||||
// API is the Mercedes api client
|
||||
type API struct {
|
||||
*request.Helper
|
||||
sandbox bool
|
||||
}
|
||||
|
||||
// NewAPI creates a new api client
|
||||
func NewAPI(log *util.Logger, identity *Identity) *API {
|
||||
func NewAPI(log *util.Logger, identity *Identity, sandbox bool) *API {
|
||||
v := &API{
|
||||
Helper: request.NewHelper(log),
|
||||
}
|
||||
|
|
@ -33,11 +35,18 @@ func NewAPI(log *util.Logger, identity *Identity) *API {
|
|||
return v
|
||||
}
|
||||
|
||||
func (v *API) BaseURI() string {
|
||||
if v.sandbox {
|
||||
return SandboxBaseURI
|
||||
}
|
||||
return BaseURI
|
||||
}
|
||||
|
||||
// SoC implements the /soc response
|
||||
func (v *API) SoC(vin string) (EVResponse, error) {
|
||||
var res EVResponse
|
||||
|
||||
uri := fmt.Sprintf("%s/vehicles/%s/resources/soc", BaseURI, vin)
|
||||
uri := fmt.Sprintf("%s/vehicles/%s/resources/soc", v.BaseURI(), vin)
|
||||
err := v.GetJSON(uri, &res)
|
||||
|
||||
return res, err
|
||||
|
|
@ -47,7 +56,7 @@ func (v *API) SoC(vin string) (EVResponse, error) {
|
|||
func (v *API) Range(vin string) (EVResponse, error) {
|
||||
var res EVResponse
|
||||
|
||||
uri := fmt.Sprintf("%s/vehicles/%s/resources/rangeelectric", BaseURI, vin)
|
||||
uri := fmt.Sprintf("%s/vehicles/%s/resources/rangeelectric", v.BaseURI(), vin)
|
||||
err := v.GetJSON(uri, &res)
|
||||
|
||||
return res, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue