More changes
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 26s
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 26s
This commit is contained in:
128
client.go
128
client.go
@ -236,7 +236,6 @@ func (c *Client) GetVehicleByVIN(vin string) *Vehicle {
|
|||||||
// Exec method executes a Client instance with the API URL
|
// Exec method executes a Client instance with the API URL
|
||||||
func (c *Client) execute(requestUrl string, method string, params map[string]string, pollingUrl string, j bool) []byte {
|
func (c *Client) execute(requestUrl string, method string, params map[string]string, pollingUrl string, j bool) []byte {
|
||||||
defer timeTrack("[TIMETRK] Executing Get Request")
|
defer timeTrack("[TIMETRK] Executing Get Request")
|
||||||
|
|
||||||
var resp *resty.Response
|
var resp *resty.Response
|
||||||
|
|
||||||
// GET Requests
|
// GET Requests
|
||||||
@ -249,14 +248,12 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
|||||||
|
|
||||||
// POST Requests
|
// POST Requests
|
||||||
if method == "POST" {
|
if method == "POST" {
|
||||||
if j {
|
if j { // POST > JSON Body
|
||||||
// POST > JSON Body
|
|
||||||
resp, _ = c.httpClient.
|
resp, _ = c.httpClient.
|
||||||
R().
|
R().
|
||||||
SetBody(params).
|
SetBody(params).
|
||||||
Post(requestUrl)
|
Post(requestUrl)
|
||||||
} else {
|
} else { // POST > Form Data
|
||||||
// POST > Form Data
|
|
||||||
resp, _ = c.httpClient.
|
resp, _ = c.httpClient.
|
||||||
R().
|
R().
|
||||||
SetFormData(params).
|
SetFormData(params).
|
||||||
@ -271,84 +268,77 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
|||||||
if r, ok := c.parseResponse(resBytes); ok {
|
if r, ok := c.parseResponse(resBytes); ok {
|
||||||
c.logger.Debug("parsed http request output", "data", r.Data)
|
c.logger.Debug("parsed http request output", "data", r.Data)
|
||||||
|
|
||||||
|
// dataName field has the list of the states [ remoteServiceStatus | errorResponse ]
|
||||||
if r.DataName == "remoteServiceStatus" {
|
if r.DataName == "remoteServiceStatus" {
|
||||||
var sr ServiceRequest
|
var sr ServiceRequest
|
||||||
err := json.Unmarshal(r.Data, &sr)
|
err := json.Unmarshal(r.Data, &sr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Error("error while parsing json", "request", "HTTP POLLING", "error", err.Error())
|
c.logger.Error("error while parsing json", "request", "HTTP POLLING", "error", err.Error())
|
||||||
}
|
}
|
||||||
|
// {"success":false,"errorCode":"404-soa-unableToParseResponseBody","dataName":"errorResponse","data":{"errorLabel":"404-soa-unableToParseResponseBody","errorDescription":null}}
|
||||||
|
|
||||||
if pollingUrl != "" {
|
if pollingUrl != "" {
|
||||||
time.Sleep(3 * time.Second)
|
switch {
|
||||||
attempts := 20
|
case sr.RemoteServiceState == "finished":
|
||||||
|
// Finished RemoteServiceState Service Request does not include Service Request ID
|
||||||
poolingLoop:
|
c.logger.Debug("Remote service request completed successfully")
|
||||||
for attempts > 0 {
|
case sr.RemoteServiceState == "started":
|
||||||
resp, _ = c.httpClient.
|
|
||||||
SetBaseURL(MOBILE_API_SERVER[c.country]).
|
|
||||||
R().
|
|
||||||
SetQueryParams(map[string]string{
|
|
||||||
"serviceRequestId": sr.ServiceRequestID,
|
|
||||||
}).
|
|
||||||
Get(pollingUrl)
|
|
||||||
resBytes, _ := io.ReadAll(resp.Body)
|
|
||||||
c.logger.Debug("POLLING HTTP OUTPUT", "body", string(resBytes))
|
|
||||||
// {"success":false,"errorCode":"404-soa-unableToParseResponseBody","dataName":"errorResponse","data":{"errorLabel":"404-soa-unableToParseResponseBody","errorDescription":null}}
|
|
||||||
|
|
||||||
var r Response
|
|
||||||
err := json.Unmarshal(resBytes, &r)
|
|
||||||
if err != nil {
|
|
||||||
c.logger.Error("error while parsing json", "request", "HTTP POLLING", "error", err.Error())
|
|
||||||
}
|
|
||||||
c.logger.Debug("parsed loop http request output", "request", "HTTP POLLING", "data", r.Data)
|
|
||||||
|
|
||||||
if r.Success {
|
|
||||||
var sr ServiceRequest
|
|
||||||
err := json.Unmarshal(r.Data, &sr)
|
|
||||||
if err != nil {
|
|
||||||
c.logger.Error("error while parsing json", "request", "HTTP POLLING", "error", err.Error())
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case sr.RemoteServiceState == "finished":
|
|
||||||
c.logger.Debug("Remote service request completed successfully", "request id", sr.ServiceRequestID)
|
|
||||||
break poolingLoop
|
|
||||||
case sr.RemoteServiceState == "started":
|
|
||||||
c.logger.Debug("Subaru API reports remote service request is in progress", "request id", sr.ServiceRequestID)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
c.logger.Debug("Backend session expired, please try again")
|
|
||||||
break poolingLoop
|
|
||||||
}
|
|
||||||
attempts--
|
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
|
c.logger.Debug("Subaru API reports remote service request (started) is in progress", "id", sr.ServiceRequestID)
|
||||||
|
c.execute(pollingUrl, GET, map[string]string{"serviceRequestId": sr.ServiceRequestID}, pollingUrl, false)
|
||||||
|
case sr.RemoteServiceState == "stopping":
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
c.logger.Debug("Subaru API reports remote service request (stopping) is in progress", "id", sr.ServiceRequestID)
|
||||||
|
c.execute(pollingUrl, GET, map[string]string{"serviceRequestId": sr.ServiceRequestID}, pollingUrl, false)
|
||||||
|
default:
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
c.logger.Debug("Subaru API reports remote service request (stopping) is in progress")
|
||||||
|
c.execute(pollingUrl, GET, map[string]string{"serviceRequestId": sr.ServiceRequestID}, pollingUrl, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for {
|
|
||||||
// if attempt >= attempts {
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// resp := c.execute(pollingUrl, GET, map[string]string{"serviceRequestId": sr.ServiceRequestID}, pollingUrl, false)
|
|
||||||
// var r Response
|
|
||||||
// err = json.Unmarshal(resp, &r)
|
|
||||||
// if err != nil {
|
|
||||||
// c.logger.Error("error while parsing json", "request", "execute", "method", method, "url", requestUrl, "error", err.Error())
|
|
||||||
// }
|
|
||||||
// c.logger.Debug("parsed http request output", "request", "HTTP POLLING", "data", r.Data)
|
|
||||||
|
|
||||||
// var sr ServiceRequest
|
// if pollingUrl != "" {
|
||||||
// err := json.Unmarshal(r.Data, &sr)
|
// time.Sleep(3 * time.Second)
|
||||||
// if err != nil {
|
// attempts := 20
|
||||||
// c.logger.Error("error while parsing json", "request", "HTTP POLLING", "error", err.Error())
|
|
||||||
// }
|
|
||||||
|
|
||||||
// switch {
|
// poolingLoop:
|
||||||
// case sr.RemoteServiceState == "finished":
|
// for attempts > 0 {
|
||||||
// c.logger.Debug("Remote service request completed successfully", "request id", sr.ServiceRequestID)
|
// resp, _ = c.httpClient.
|
||||||
// break
|
// R().
|
||||||
// case sr.RemoteServiceState == "started":
|
// SetQueryParams(map[string]string{
|
||||||
// c.logger.Debug("Subaru API reports remote service request is in progress", "request id", sr.ServiceRequestID)
|
// "serviceRequestId": sr.ServiceRequestID,
|
||||||
|
// }).
|
||||||
|
// Get(pollingUrl)
|
||||||
|
// resBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
// c.logger.Debug("POLLING HTTP OUTPUT", "body", string(resBytes))
|
||||||
|
|
||||||
|
// var r Response
|
||||||
|
// err := json.Unmarshal(resBytes, &r)
|
||||||
|
// if err != nil {
|
||||||
|
// c.logger.Error("error while parsing json", "request", "HTTP POLLING", "error", err.Error())
|
||||||
|
// }
|
||||||
|
// c.logger.Debug("parsed loop http request output", "request", "HTTP POLLING", "data", r.Data)
|
||||||
|
|
||||||
|
// if r.Success {
|
||||||
|
// var sr ServiceRequest
|
||||||
|
// err := json.Unmarshal(r.Data, &sr)
|
||||||
|
// if err != nil {
|
||||||
|
// c.logger.Error("error while parsing json", "request", "HTTP POLLING", "error", err.Error())
|
||||||
|
// }
|
||||||
|
// switch {
|
||||||
|
// case sr.RemoteServiceState == "finished":
|
||||||
|
// c.logger.Debug("Remote service request completed successfully", "request id", sr.ServiceRequestID)
|
||||||
|
// break poolingLoop
|
||||||
|
// case sr.RemoteServiceState == "started":
|
||||||
|
// c.logger.Debug("Subaru API reports remote service request is in progress", "request id", sr.ServiceRequestID)
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// c.logger.Debug("Backend session expired, please try again")
|
||||||
|
// break poolingLoop
|
||||||
|
// }
|
||||||
|
// attempts--
|
||||||
|
// time.Sleep(3 * time.Second)
|
||||||
// }
|
// }
|
||||||
// attempt++
|
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
12
mysubaru.go
12
mysubaru.go
@ -9,7 +9,7 @@ import (
|
|||||||
type Response struct {
|
type Response struct {
|
||||||
Success bool `json:"success"` // true | false
|
Success bool `json:"success"` // true | false
|
||||||
ErrorCode string `json:"errorCode,omitempty"` // string | Error message if Success is false
|
ErrorCode string `json:"errorCode,omitempty"` // string | Error message if Success is false
|
||||||
DataName string `json:"dataName"` // string | Describes the structure which is incleded in Data field
|
DataName string `json:"dataName,omitempty"` // string | Describes the structure which is included in Data field
|
||||||
Data json.RawMessage `json:"data"` // Data struct
|
Data json.RawMessage `json:"data"` // Data struct
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ type VehicleStatus struct {
|
|||||||
DistanceToEmptyFuelKilometers10s int `json:"distanceToEmptyFuelKilometers10s"` // + 340
|
DistanceToEmptyFuelKilometers10s int `json:"distanceToEmptyFuelKilometers10s"` // + 340
|
||||||
AvgFuelConsumptionMpg float64 `json:"avgFuelConsumptionMpg"` // + 18.4
|
AvgFuelConsumptionMpg float64 `json:"avgFuelConsumptionMpg"` // + 18.4
|
||||||
AvgFuelConsumptionLitersPer100Kilometers float64 `json:"avgFuelConsumptionLitersPer100Kilometers"` // + 12.8
|
AvgFuelConsumptionLitersPer100Kilometers float64 `json:"avgFuelConsumptionLitersPer100Kilometers"` // + 12.8
|
||||||
RemainingFuelPercent int `json:"remainingFuelPercent"` // + 82
|
RemainingFuelPercent int `json:"remainingFuelPercent,string"` // + "82"
|
||||||
TirePressureFrontLeft int `json:"tirePressureFrontLeft,string"` // + "2275"
|
TirePressureFrontLeft int `json:"tirePressureFrontLeft,string"` // + "2275"
|
||||||
TirePressureFrontRight int `json:"tirePressureFrontRight,string"` // + "2344"
|
TirePressureFrontRight int `json:"tirePressureFrontRight,string"` // + "2344"
|
||||||
TirePressureRearLeft int `json:"tirePressureRearLeft,string"` // + "2413"
|
TirePressureRearLeft int `json:"tirePressureRearLeft,string"` // + "2413"
|
||||||
@ -267,9 +267,9 @@ type VehicleCondition struct {
|
|||||||
// "dataName": "remoteServiceStatus"
|
// "dataName": "remoteServiceStatus"
|
||||||
type ServiceRequest struct {
|
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
|
Success bool `json:"success"` // false | true // Could be in the false state while the executed request in the progress
|
||||||
Cancelled bool `json:"cancelled"` // false | true
|
Cancelled bool `json:"cancelled"` // false | true
|
||||||
RemoteServiceType string `json:"remoteServiceType"` // unlock | lock | locate | vehicleStatus | lightsOnly | engineStart | engineStop | phevChargeNow | condition
|
RemoteServiceType string `json:"remoteServiceType"` // vehicleStatus | condition | locate | unlock | lock | lightsOnly | engineStart | engineStop | phevChargeNow
|
||||||
RemoteServiceState string `json:"remoteServiceState"` // started | finished | stopping
|
RemoteServiceState string `json:"remoteServiceState"` // started | finished | stopping
|
||||||
SubState string `json:"subState,omitempty"` // null
|
SubState string `json:"subState,omitempty"` // null
|
||||||
ErrorCode string `json:"errorCode,omitempty"` // null:null
|
ErrorCode string `json:"errorCode,omitempty"` // null:null
|
||||||
@ -281,8 +281,8 @@ type ServiceRequest struct {
|
|||||||
// ErrorResponse .
|
// ErrorResponse .
|
||||||
// "dataName":"errorResponse"
|
// "dataName":"errorResponse"
|
||||||
type ErrorResponse struct {
|
type ErrorResponse struct {
|
||||||
ErrorLabel string `json:"errorLabel"` // "404-soa-unableToParseResponseBody"
|
ErrorLabel string `json:"errorLabel"` // "404-soa-unableToParseResponseBody"
|
||||||
ErrorDescription *string `json:"errorDescription,omitempty"` // null
|
ErrorDescription string `json:"errorDescription,omitempty"` // null
|
||||||
}
|
}
|
||||||
|
|
||||||
// climateSettings: [ climateSettings ]
|
// climateSettings: [ climateSettings ]
|
||||||
|
Reference in New Issue
Block a user