From b4770174116eb6c3c2f372abd260343752b47b20 Mon Sep 17 00:00:00 2001 From: Alex Savin Date: Sun, 1 Jun 2025 12:04:24 -0400 Subject: [PATCH] Some changes --- client.go | 10 ++++------ example/example.go | 2 +- example/go.mod | 3 +-- mysubaru.go | 28 ++++++++++++++-------------- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/client.go b/client.go index dd38514..1935658 100644 --- a/client.go +++ b/client.go @@ -434,7 +434,6 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str // GET Requests if method == "GET" { resp, _ = c.httpClient. - // SetBaseURL(MOBILE_API_SERVER[c.country]). R(). SetQueryParams(params). Get(requestUrl) @@ -467,9 +466,7 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str c.logger.Error("error while parsing json", "request", "execute", "method", method, "url", requestUrl, "error", err.Error()) } - if !r.Success { - c.logger.Error("request is not successfull", "request", "execute", "method", method, "url", requestUrl, "error", err.Error()) - } else { + if r.Success { var sr ServiceRequest err := json.Unmarshal(r.Data, &sr) if err != nil { @@ -485,7 +482,7 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str SetBaseURL(MOBILE_API_SERVER[c.country]). R(). SetQueryParams(map[string]string{ - "serviceRequestId": *sr.ServiceRequestID, + "serviceRequestId": sr.ServiceRequestID, }). Get(pollingUrl) resBytes, _ := io.ReadAll(resp.Body) @@ -519,7 +516,8 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str time.Sleep(3 * time.Second) } } - + } else { + c.logger.Error("request is not successfull", "request", "execute", "method", method, "url", requestUrl, "error", err.Error()) } return resBytes diff --git a/example/example.go b/example/example.go index fc2c1a4..f120e90 100644 --- a/example/example.go +++ b/example/example.go @@ -22,7 +22,7 @@ func main() { if err != nil { log.Fatal(err) } - cfg.Logger.Debug("printting config", "config", cfg) + cfg.Logger.Debug("printing config", "config", cfg) ms, _ := mysubaru.New(cfg) diff --git a/example/go.mod b/example/go.mod index 2ef1676..4106a39 100644 --- a/example/go.mod +++ b/example/go.mod @@ -2,10 +2,9 @@ module example go 1.24 -require git.savin.nyc/alex/mysubaru v0.0.0-20250530191823-fb8f151e05c9 +require git.savin.nyc/alex/mysubaru v0.0.0-20250601152656-ef145bdf9ae5 require ( - github.com/Jeffail/gabs/v2 v2.7.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/rogpeppe/go-internal v1.9.0 // indirect golang.org/x/net v0.40.0 // indirect diff --git a/mysubaru.go b/mysubaru.go index 36c044e..31eaea4 100644 --- a/mysubaru.go +++ b/mysubaru.go @@ -150,7 +150,7 @@ type VehicleStatus struct { EventDateStrCarUser string `json:"eventDateStrCarUser"` // + 2023-12-06T21:09+0000 Latitude float64 `json:"latitude"` // + 40.700183 Longitude float64 `json:"longitude"` // + -74.401372 - Heading int `json:"positionHeadingDegree"` // + "154" + Heading int `json:"positionHeadingDegree,string"` // + "154" DistanceToEmptyFuelMiles float64 `json:"distanceToEmptyFuelMiles"` // + 209.4 DistanceToEmptyFuelKilometers int `json:"distanceToEmptyFuelKilometers"` // + 337 DistanceToEmptyFuelMiles10s int `json:"distanceToEmptyFuelMiles10s"` // + 210 @@ -158,14 +158,14 @@ type VehicleStatus struct { AvgFuelConsumptionMpg float64 `json:"avgFuelConsumptionMpg"` // + 18.4 AvgFuelConsumptionLitersPer100Kilometers float64 `json:"avgFuelConsumptionLitersPer100Kilometers"` // + 12.8 RemainingFuelPercent int `json:"remainingFuelPercent"` // + 82 - TirePressureFrontLeft string `json:"tirePressureFrontLeft"` // + "2275" - TirePressureFrontRight string `json:"tirePressureFrontRight"` // + "2344" - TirePressureRearLeft string `json:"tirePressureRearLeft"` // + "2413" - TirePressureRearRight string `json:"tirePressureRearRight"` // + "2344" - TirePressureFrontLeftPsi string `json:"tirePressureFrontLeftPsi"` // + "33" - TirePressureFrontRightPsi string `json:"tirePressureFrontRightPsi"` // + "34" - TirePressureRearLeftPsi string `json:"tirePressureRearLeftPsi"` // + "35" - TirePressureRearRightPsi string `json:"tirePressureRearRightPsi"` // + "34" + TirePressureFrontLeft int `json:"tirePressureFrontLeft,string"` // + "2275" + TirePressureFrontRight int `json:"tirePressureFrontRight,string"` // + "2344" + TirePressureRearLeft int `json:"tirePressureRearLeft,string"` // + "2413" + TirePressureRearRight int `json:"tirePressureRearRight,string"` // + "2344" + TirePressureFrontLeftPsi int `json:"tirePressureFrontLeftPsi,string"` // + "33" + TirePressureFrontRightPsi int `json:"tirePressureFrontRightPsi,string"` // + "34" + TirePressureRearLeftPsi int `json:"tirePressureRearLeftPsi,string"` // + "35" + TirePressureRearRightPsi int `json:"tirePressureRearRightPsi,string"` // + "34" TyreStatusFrontLeft string `json:"tyreStatusFrontLeft"` // + "UNKNOWN" TyreStatusFrontRight string `json:"tyreStatusFrontRight"` // + "UNKNOWN" TyreStatusRearLeft string `json:"tyreStatusRearLeft"` // + "UNKNOWN" @@ -253,15 +253,15 @@ type VehicleCondition struct { // ServiceRequest . // "dataName": "remoteServiceStatus" type ServiceRequest struct { - ServiceRequestID *string `json:"serviceRequestId,omitempty"` // 4S4BTGND8L3137058_1640294426029_19_@NGTP + ServiceRequestID string `json:"serviceRequestId,omitempty"` // 4S4BTGND8L3137058_1640294426029_19_@NGTP Success bool `json:"success"` // false | true Cancelled bool `json:"cancelled"` // false | true RemoteServiceType string `json:"remoteServiceType"` // unlock | lock | locate | vehicleStatus | lightsOnly | engineStart | engineStop | phevChargeNow | condition RemoteServiceState string `json:"remoteServiceState"` // started | finished | stopping - SubState *string `json:"subState,omitempty"` // null - ErrorCode *string `json:"errorCode,omitempty"` // null:null - Result json.RawMessage `json:"result,omitempty"` // null - UpdateTime *time.Time `json:"updateTime,omitempty"` // timestamp + SubState string `json:"subState,omitempty"` // null + ErrorCode string `json:"errorCode,omitempty"` // null:null + Result json.RawMessage `json:"result,omitempty"` // struct + UpdateTime time.Time `json:"updateTime,omitempty"` // timestamp Vin string `json:"vin"` // 4S4BTGND8L3137058 }