More changes
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 24s
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 24s
This commit is contained in:
54
client.go
54
client.go
@ -101,7 +101,6 @@ func New(config *config.Config) (*Client, error) {
|
||||
|
||||
// SelectVehicle .
|
||||
func (c *Client) SelectVehicle(vin string) VehicleData {
|
||||
// API > json > dataName > vehicle
|
||||
if vin == "" {
|
||||
vin = c.currentVin
|
||||
}
|
||||
@ -119,9 +118,9 @@ func (c *Client) SelectVehicle(vin string) VehicleData {
|
||||
var vd VehicleData
|
||||
err := json.Unmarshal(r.Data, &vd)
|
||||
if err != nil {
|
||||
c.logger.Error("error while parsing json", "request", "GetClimatePresets", "error", err.Error())
|
||||
c.logger.Error("error while parsing json", "request", "SelectVehicle", "error", err.Error())
|
||||
}
|
||||
// c.logger.Debug("http request output", "request", "GetVehicleStatus", "body", resp)
|
||||
// c.logger.Debug("http request output", "request", "SelectVehicle", "body", resp)
|
||||
|
||||
return vd
|
||||
} else {
|
||||
@ -233,7 +232,7 @@ func (c *Client) GetVehicleByVIN(vin string) *Vehicle {
|
||||
// func fetch() {}
|
||||
|
||||
// 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, attempts ...int) []byte {
|
||||
defer timeTrack("[TIMETRK] Executing Get Request")
|
||||
var resp *resty.Response
|
||||
|
||||
@ -292,53 +291,9 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
||||
default:
|
||||
time.Sleep(5 * 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)
|
||||
c.execute(pollingUrl, GET, map[string]string{"serviceRequestId": sr.ServiceRequestID}, pollingUrl, false, 1)
|
||||
}
|
||||
}
|
||||
|
||||
// if pollingUrl != "" {
|
||||
// time.Sleep(3 * time.Second)
|
||||
// attempts := 20
|
||||
|
||||
// poolingLoop:
|
||||
// for attempts > 0 {
|
||||
// resp, _ = c.httpClient.
|
||||
// R().
|
||||
// SetQueryParams(map[string]string{
|
||||
// "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)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
c.logger.Error("request is not successfull", "request", "execute", "method", method, "url", requestUrl, "error", err.Error())
|
||||
@ -400,7 +355,6 @@ func (c *Client) parseResponse(b []byte) (Response, bool) {
|
||||
if err != nil {
|
||||
c.logger.Error("error while parsing json", "error", err.Error())
|
||||
}
|
||||
|
||||
return r, true
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user