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:
64
client.go
64
client.go
@ -268,14 +268,10 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
||||
c.logger.Error("error while getting body", "error", err.Error())
|
||||
}
|
||||
|
||||
var r Response
|
||||
err = json.Unmarshal(resBytes, &r)
|
||||
if err != nil {
|
||||
c.logger.Error("error while parsing json", "request", "execute", "method", method, "url", requestUrl, "error", err.Error())
|
||||
}
|
||||
if r, ok := c.parseResponse(resBytes); ok {
|
||||
c.logger.Debug("parsed http request output", "request", "HTTP POLLING", "data", r.Data)
|
||||
|
||||
if r.Success {
|
||||
if r.DataName == "remoteServiceStatus" {
|
||||
var sr ServiceRequest
|
||||
err := json.Unmarshal(r.Data, &sr)
|
||||
if err != nil {
|
||||
@ -286,34 +282,6 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
||||
time.Sleep(3 * time.Second)
|
||||
attempts := 20
|
||||
|
||||
// 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
|
||||
// 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
|
||||
// case sr.RemoteServiceState == "started":
|
||||
// c.logger.Debug("Subaru API reports remote service request is in progress", "request id", sr.ServiceRequestID)
|
||||
// }
|
||||
// attempt++
|
||||
// }
|
||||
|
||||
poolingLoop:
|
||||
for attempts > 0 {
|
||||
resp, _ = c.httpClient.
|
||||
@ -355,6 +323,34 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
||||
time.Sleep(3 * time.Second)
|
||||
}
|
||||
}
|
||||
// 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
|
||||
// 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
|
||||
// case sr.RemoteServiceState == "started":
|
||||
// c.logger.Debug("Subaru API reports remote service request is in progress", "request id", sr.ServiceRequestID)
|
||||
// }
|
||||
// attempt++
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
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 (
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -13,6 +14,19 @@ type Response 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 .
|
||||
type Account struct {
|
||||
MarketID int `json:"marketId"`
|
||||
|
@ -775,6 +775,7 @@ func (v *Vehicle) GetVehicleCondition() {
|
||||
val.Field(i).Interface() == "-64" ||
|
||||
val.Field(i).Interface() == "" ||
|
||||
val.Field(i).Interface() == 0 ||
|
||||
val.Field(i).Interface() == float64(0) ||
|
||||
val.Field(i).Interface() == nil {
|
||||
continue
|
||||
}
|
||||
|
Reference in New Issue
Block a user