Beta version
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:
96
client.go
96
client.go
@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log/slog"
|
||||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -60,11 +61,11 @@ func New(config *config.Config) (*Client, error) {
|
||||
// client.logger.Debug("unmarshaled json data", "request", "auth", "type", "sessionData", "body", sd)
|
||||
|
||||
if sd.DeviceRegistered && sd.RegisteredDevicePermanent {
|
||||
client.logger.Debug("client authentication successful")
|
||||
// client.logger.Debug("client authentication successful")
|
||||
client.isAuthenticated = true
|
||||
client.isRegistered = true
|
||||
} else {
|
||||
client.logger.Debug("client authentication successful, but devices is not registered")
|
||||
// client.logger.Debug("client authentication successful, but devices is not registered")
|
||||
client.registerDevice()
|
||||
}
|
||||
|
||||
@ -140,7 +141,7 @@ func (c *Client) GetVehicles() []*Vehicle {
|
||||
// GetVehicleByVIN .
|
||||
func (c *Client) GetVehicleByVIN(vin string) *Vehicle {
|
||||
var vehicle *Vehicle
|
||||
if contains(c.listOfVins, vin) {
|
||||
if slices.Contains(c.listOfVins, vin) {
|
||||
params := map[string]string{
|
||||
"vin": vin,
|
||||
"_": timestamp()}
|
||||
@ -212,7 +213,7 @@ func (c *Client) GetVehicleByVIN(vin string) *Vehicle {
|
||||
|
||||
// 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, attempts ...int) []byte {
|
||||
defer timeTrack("[TIMETRK] Executing HTTP Request")
|
||||
// defer timeTrack("[TIMETRK] Executing HTTP Request")
|
||||
var resp *resty.Response
|
||||
|
||||
// GET Requests
|
||||
@ -290,35 +291,6 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
||||
return resBytes
|
||||
}
|
||||
|
||||
// // isResponseSuccessfull .
|
||||
// func (c *Client) isResponseSuccessfull(resp []byte) bool {
|
||||
// respParsed, err := gabs.ParseJSON(resp)
|
||||
// if err != nil {
|
||||
// c.logger.Debug("error while parsing json response", "error", err)
|
||||
// }
|
||||
|
||||
// success, ok := respParsed.Path("success").Data().(bool)
|
||||
// if !ok {
|
||||
// c.logger.Debug("response is not successful", "error", resp)
|
||||
// }
|
||||
|
||||
// // ERRORS FROM CLIENT CREATION AFTER AUTH
|
||||
// // error, _ := respParsed.Path("errorCode").Data().(string)
|
||||
// // switch {
|
||||
// // case error == apiErrors["ERROR_INVALID_ACCOUNT"]:
|
||||
// // fmt.Println("Invalid account")
|
||||
// // case error == apiErrors["ERROR_INVALID_CREDENTIALS"]:
|
||||
// // {"success":false,"errorCode":"InvalidCredentials","dataName":"remoteServiceStatus","data":{"serviceRequestId":null,"success":false,"cancelled":false,"remoteServiceType":null,"remoteServiceState":null,"subState":null,"errorCode":null,"result":null,"updateTime":null,"vin":null,"errorDescription":"The credentials supplied are invalid, tries left 2"}}
|
||||
// // fmt.Println("Client authentication failed")
|
||||
// // case error == apiErrors["ERROR_PASSWORD_WARNING"]:
|
||||
// // fmt.Println("Multiple Password Failures.")
|
||||
// // default:
|
||||
// // fmt.Println("Uknown error")
|
||||
// // }
|
||||
|
||||
// return success
|
||||
// }
|
||||
|
||||
// auth .
|
||||
func (c *Client) auth() []byte {
|
||||
params := map[string]string{
|
||||
@ -347,46 +319,28 @@ func (c *Client) parseResponse(b []byte) (Response, bool) {
|
||||
}
|
||||
|
||||
// validateSession .
|
||||
func (c *Client) validateSession() bool {
|
||||
// {
|
||||
// "success": true,
|
||||
// "errorCode": null,
|
||||
// "dataName": null,
|
||||
// "data": null
|
||||
// }
|
||||
reqURL := MOBILE_API_VERSION + apiURLs["API_VALIDATE_SESSION"]
|
||||
resp := c.execute(reqURL, GET, map[string]string{}, "", false)
|
||||
c.logger.Debug("http request output", "request", "validateSession", "body", resp)
|
||||
// func (c *Client) validateSession() bool {
|
||||
// // {
|
||||
// // "success": true,
|
||||
// // "errorCode": null,
|
||||
// // "dataName": null,
|
||||
// // "data": null
|
||||
// // }
|
||||
// reqURL := MOBILE_API_VERSION + apiURLs["API_VALIDATE_SESSION"]
|
||||
// resp := c.execute(reqURL, GET, map[string]string{}, "", false)
|
||||
// c.logger.Debug("http request output", "request", "validateSession", "body", resp)
|
||||
|
||||
var r Response
|
||||
err := json.Unmarshal(resp, &r)
|
||||
if err != nil {
|
||||
c.logger.Error("error while parsing json", "request", "validateSession", "error", err.Error())
|
||||
}
|
||||
// var r Response
|
||||
// err := json.Unmarshal(resp, &r)
|
||||
// if err != nil {
|
||||
// c.logger.Error("error while parsing json", "request", "validateSession", "error", err.Error())
|
||||
// }
|
||||
|
||||
if r.Success {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
// result = False
|
||||
// js_resp = await self.__open(API_VALIDATE_SESSION, GET)
|
||||
// _LOGGER.debug(pprint.pformat(js_resp))
|
||||
// if js_resp["success"]:
|
||||
// if vin != self._current_vin:
|
||||
// # API call for VIN that is not the current remote context.
|
||||
// _LOGGER.debug("Switching Subaru API vehicle context to: %s", vin)
|
||||
// if await self._select_vehicle(vin):
|
||||
// result = True
|
||||
// else:
|
||||
// result = True
|
||||
|
||||
// if result is False:
|
||||
// await self._authenticate(vin)
|
||||
// # New session cookie. Must call selectVehicle.json before any other API call.
|
||||
// if await self._select_vehicle(vin):
|
||||
// result = True
|
||||
}
|
||||
// if r.Success {
|
||||
// return true
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
|
||||
// GET
|
||||
// https://www.mysubaru.com/profile/verifyDeviceName.json?clientId=2574212&deviceName=Alex%20Google%20Pixel%204%20XL
|
||||
|
Reference in New Issue
Block a user