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:
108
client.go
108
client.go
@ -268,24 +268,61 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
|||||||
c.logger.Error("error while getting body", "error", err.Error())
|
c.logger.Error("error while getting body", "error", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var r Response
|
if r, ok := c.parseResponse(resBytes); ok {
|
||||||
err = json.Unmarshal(resBytes, &r)
|
c.logger.Debug("parsed http request output", "request", "HTTP POLLING", "data", r.Data)
|
||||||
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)
|
|
||||||
|
|
||||||
if r.Success {
|
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())
|
||||||
}
|
}
|
||||||
|
|
||||||
if pollingUrl != "" {
|
if pollingUrl != "" {
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
attempts := 20
|
attempts := 20
|
||||||
|
|
||||||
|
poolingLoop:
|
||||||
|
for attempts > 0 {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
// for {
|
// for {
|
||||||
// if attempt >= attempts {
|
// if attempt >= attempts {
|
||||||
// break
|
// break
|
||||||
@ -313,47 +350,6 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
|||||||
// }
|
// }
|
||||||
// attempt++
|
// attempt++
|
||||||
// }
|
// }
|
||||||
|
|
||||||
poolingLoop:
|
|
||||||
for attempts > 0 {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.logger.Error("request is not successfull", "request", "execute", "method", method, "url", requestUrl, "error", err.Error())
|
c.logger.Error("request is not successfull", "request", "execute", "method", method, "url", requestUrl, "error", err.Error())
|
||||||
|
14
mysubaru.go
14
mysubaru.go
@ -2,6 +2,7 @@ package mysubaru
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,6 +14,19 @@ type Response struct {
|
|||||||
Data json.RawMessage `json:"data"` // Data struct
|
Data json.RawMessage `json:"data"` // Data struct
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse .
|
||||||
|
func (r *Response) parse(b []byte, logger *slog.Logger) bool {
|
||||||
|
err := json.Unmarshal(b, &r)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("error while parsing json", "error", err.Error())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unmarshal .
|
||||||
|
// func (r *Response) Unmarshal(b []byte) {}
|
||||||
|
|
||||||
// Account .
|
// Account .
|
||||||
type Account struct {
|
type Account struct {
|
||||||
MarketID int `json:"marketId"`
|
MarketID int `json:"marketId"`
|
||||||
|
@ -775,6 +775,7 @@ func (v *Vehicle) GetVehicleCondition() {
|
|||||||
val.Field(i).Interface() == "-64" ||
|
val.Field(i).Interface() == "-64" ||
|
||||||
val.Field(i).Interface() == "" ||
|
val.Field(i).Interface() == "" ||
|
||||||
val.Field(i).Interface() == 0 ||
|
val.Field(i).Interface() == 0 ||
|
||||||
|
val.Field(i).Interface() == float64(0) ||
|
||||||
val.Field(i).Interface() == nil {
|
val.Field(i).Interface() == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user