Upgraded resty to v3
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:
25
client.go
25
client.go
@ -3,6 +3,7 @@ package mysubaru
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
@ -10,7 +11,7 @@ import (
|
|||||||
|
|
||||||
"git.savin.nyc/alex/mysubaru/config"
|
"git.savin.nyc/alex/mysubaru/config"
|
||||||
"github.com/Jeffail/gabs/v2"
|
"github.com/Jeffail/gabs/v2"
|
||||||
"github.com/go-resty/resty/v2"
|
"resty.dev/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// credentials .
|
// credentials .
|
||||||
@ -252,7 +253,7 @@ func (c *Client) listDevices() {
|
|||||||
fmt.Println(" Status Code:", resp.StatusCode())
|
fmt.Println(" Status Code:", resp.StatusCode())
|
||||||
fmt.Println(" Status :", resp.Status())
|
fmt.Println(" Status :", resp.Status())
|
||||||
fmt.Println(" Proto :", resp.Proto())
|
fmt.Println(" Proto :", resp.Proto())
|
||||||
fmt.Println(" Time :", resp.Time())
|
fmt.Println(" Time :", resp.Duration())
|
||||||
fmt.Println(" Received At:", resp.ReceivedAt())
|
fmt.Println(" Received At:", resp.ReceivedAt())
|
||||||
// fmt.Println(" Body :\n", resp)
|
// fmt.Println(" Body :\n", resp)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
@ -271,7 +272,7 @@ func (c *Client) listDevices() {
|
|||||||
fmt.Println(" IsConnWasIdle :", ti.IsConnWasIdle)
|
fmt.Println(" IsConnWasIdle :", ti.IsConnWasIdle)
|
||||||
fmt.Println(" ConnIdleTime :", ti.ConnIdleTime)
|
fmt.Println(" ConnIdleTime :", ti.ConnIdleTime)
|
||||||
fmt.Println(" RequestAttempt:", ti.RequestAttempt)
|
fmt.Println(" RequestAttempt:", ti.RequestAttempt)
|
||||||
fmt.Println(" RemoteAddr :", ti.RemoteAddr.String())
|
fmt.Println(" RemoteAddr :", ti.RemoteAddr)
|
||||||
|
|
||||||
// c.log.Debug("LIST DEVICES OUTPUT", "body", string([]byte(resp.Body())))
|
// c.log.Debug("LIST DEVICES OUTPUT", "body", string([]byte(resp.Body())))
|
||||||
|
|
||||||
@ -785,20 +786,24 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
|||||||
Post(requestUrl)
|
Post(requestUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
resBytes, _ := io.ReadAll(resp.Body)
|
||||||
respParsed, err := gabs.ParseJSON([]byte(resp.Body()))
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
respParsed, err := gabs.ParseJSON(resBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.log.Debug("HTTP OUTPUT", "body", string(resp.Body()))
|
c.log.Debug("HTTP OUTPUT", "body", string(resBytes))
|
||||||
|
|
||||||
_, ok := respParsed.Path("success").Data().(bool)
|
_, ok := respParsed.Path("success").Data().(bool)
|
||||||
// value == string, ok == false
|
// value == string, ok == false
|
||||||
if !ok {
|
if !ok {
|
||||||
// TODO: Work with errorCode
|
// TODO: Work with errorCode
|
||||||
// panic(success)
|
// panic(success)
|
||||||
fmt.Printf("ERROR: %+v", string([]byte(resp.Body())))
|
fmt.Printf("ERROR: %+v", string(resBytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
if pollingUrl != "" {
|
if pollingUrl != "" {
|
||||||
@ -817,10 +822,10 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
|||||||
}).
|
}).
|
||||||
Get(pollingUrl)
|
Get(pollingUrl)
|
||||||
|
|
||||||
c.log.Debug("POLLING HTTP OUTPUT", "body", string([]byte(resp.Body())))
|
c.log.Debug("POLLING HTTP OUTPUT", "body", string(resBytes))
|
||||||
// {"success":false,"errorCode":"404-soa-unableToParseResponseBody","dataName":"errorResponse","data":{"errorLabel":"404-soa-unableToParseResponseBody","errorDescription":null}}
|
// {"success":false,"errorCode":"404-soa-unableToParseResponseBody","dataName":"errorResponse","data":{"errorLabel":"404-soa-unableToParseResponseBody","errorDescription":null}}
|
||||||
|
|
||||||
respParsed, err := gabs.ParseJSON(resp.Body())
|
respParsed, err := gabs.ParseJSON(resBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -849,7 +854,7 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
|||||||
|
|
||||||
// fmt.Printf("[DEBUG] HTTP OUTPUT >> %v\n", string([]byte(resp.Body())))
|
// fmt.Printf("[DEBUG] HTTP OUTPUT >> %v\n", string([]byte(resp.Body())))
|
||||||
|
|
||||||
return resp.Body()
|
return resBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
// isResponseSuccessfull .
|
// isResponseSuccessfull .
|
||||||
|
@ -2,7 +2,7 @@ module example
|
|||||||
|
|
||||||
go 1.24
|
go 1.24
|
||||||
|
|
||||||
require git.savin.nyc/alex/mysubaru v0.0.0-20250521042901-f241375645e3
|
require git.savin.nyc/alex/mysubaru v0.0.0-20250521052308-a803671a3ce2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Jeffail/gabs/v2 v2.7.0 // indirect
|
github.com/Jeffail/gabs/v2 v2.7.0 // indirect
|
||||||
|
13
go.mod
13
go.mod
@ -4,34 +4,23 @@ go 1.24
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Jeffail/gabs/v2 v2.7.0
|
github.com/Jeffail/gabs/v2 v2.7.0
|
||||||
github.com/go-resty/resty/v2 v2.16.5
|
|
||||||
github.com/sirupsen/logrus v1.9.3
|
|
||||||
github.com/spf13/viper v1.20.1
|
github.com/spf13/viper v1.20.1
|
||||||
|
resty.dev/v3 v3.0.0-beta.3
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||||
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
|
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
|
||||||
github.com/magiconair/properties v1.8.10 // indirect
|
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
|
||||||
github.com/pelletier/go-toml v1.9.5 // indirect
|
|
||||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||||
github.com/sagikazarmark/locafero v0.9.0 // indirect
|
github.com/sagikazarmark/locafero v0.9.0 // indirect
|
||||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
|
||||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||||
github.com/spf13/afero v1.14.0 // indirect
|
github.com/spf13/afero v1.14.0 // indirect
|
||||||
github.com/spf13/cast v1.8.0 // indirect
|
github.com/spf13/cast v1.8.0 // indirect
|
||||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
|
||||||
github.com/spf13/pflag v1.0.6 // indirect
|
github.com/spf13/pflag v1.0.6 // indirect
|
||||||
github.com/subosito/gotenv v1.6.0 // indirect
|
github.com/subosito/gotenv v1.6.0 // indirect
|
||||||
go.uber.org/atomic v1.11.0 // indirect
|
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect
|
|
||||||
golang.org/x/net v0.40.0 // indirect
|
golang.org/x/net v0.40.0 // indirect
|
||||||
golang.org/x/sys v0.33.0 // indirect
|
golang.org/x/sys v0.33.0 // indirect
|
||||||
golang.org/x/text v0.25.0 // indirect
|
golang.org/x/text v0.25.0 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
10
vehicle.go
10
vehicle.go
@ -919,7 +919,9 @@ func (v *Vehicle) GetVehicleStatus() {
|
|||||||
v.DistanceToEmpty.Kilometers = vSta.DistanceToEmptyFuelKilometers
|
v.DistanceToEmpty.Kilometers = vSta.DistanceToEmptyFuelKilometers
|
||||||
v.DistanceToEmpty.Miles10s = vSta.DistanceToEmptyFuelMiles10s
|
v.DistanceToEmpty.Miles10s = vSta.DistanceToEmptyFuelMiles10s
|
||||||
v.DistanceToEmpty.Kilometers10s = vSta.DistanceToEmptyFuelKilometers10s
|
v.DistanceToEmpty.Kilometers10s = vSta.DistanceToEmptyFuelKilometers10s
|
||||||
v.DistanceToEmpty.Percentage = vSta.RemainingFuelPercent
|
if vSta.RemainingFuelPercent >= 0 && vSta.RemainingFuelPercent <= 100 {
|
||||||
|
v.DistanceToEmpty.Percentage = vSta.RemainingFuelPercent
|
||||||
|
}
|
||||||
v.FuelConsumptionAvg.MPG = float64(vSta.AvgFuelConsumptionMpg)
|
v.FuelConsumptionAvg.MPG = float64(vSta.AvgFuelConsumptionMpg)
|
||||||
v.FuelConsumptionAvg.LP100Km = float64(vSta.AvgFuelConsumptionLitersPer100Kilometers)
|
v.FuelConsumptionAvg.LP100Km = float64(vSta.AvgFuelConsumptionLitersPer100Kilometers)
|
||||||
|
|
||||||
@ -940,11 +942,13 @@ func (v *Vehicle) GetVehicleStatus() {
|
|||||||
for _, element := range submatchall {
|
for _, element := range submatchall {
|
||||||
fmt.Println(element)
|
fmt.Println(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
door := Door{}
|
door := Door{}
|
||||||
door.Position = submatchall[0]
|
door.Position = submatchall[0]
|
||||||
if len(submatchall) >= 3 {
|
if len(submatchall) >= 3 {
|
||||||
door.SubPosition = submatchall[1]
|
door.SubPosition = submatchall[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
door.Status = child.Data().(string)
|
door.Status = child.Data().(string)
|
||||||
door.Updated = time.Now()
|
door.Updated = time.Now()
|
||||||
v.Doors = append(v.Doors, &door)
|
v.Doors = append(v.Doors, &door)
|
||||||
@ -955,11 +959,13 @@ func (v *Vehicle) GetVehicleStatus() {
|
|||||||
for _, element := range submatchall {
|
for _, element := range submatchall {
|
||||||
fmt.Println(element)
|
fmt.Println(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
door := Door{}
|
door := Door{}
|
||||||
door.Position = submatchall[0]
|
door.Position = submatchall[0]
|
||||||
if len(submatchall) >= 3 {
|
if len(submatchall) >= 3 {
|
||||||
door.SubPosition = submatchall[1]
|
door.SubPosition = submatchall[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
door.Status = child.Data().(string)
|
door.Status = child.Data().(string)
|
||||||
door.Updated = time.Now()
|
door.Updated = time.Now()
|
||||||
v.Doors = append(v.Doors, &door)
|
v.Doors = append(v.Doors, &door)
|
||||||
@ -970,11 +976,13 @@ func (v *Vehicle) GetVehicleStatus() {
|
|||||||
for _, element := range submatchall {
|
for _, element := range submatchall {
|
||||||
fmt.Println(element)
|
fmt.Println(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
window := Window{}
|
window := Window{}
|
||||||
window.Position = submatchall[0]
|
window.Position = submatchall[0]
|
||||||
if len(submatchall) >= 3 {
|
if len(submatchall) >= 3 {
|
||||||
window.SubPosition = submatchall[1]
|
window.SubPosition = submatchall[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
window.Status = child.Data().(string)
|
window.Status = child.Data().(string)
|
||||||
window.Updated = time.Now()
|
window.Updated = time.Now()
|
||||||
v.Windows = append(v.Windows, &window)
|
v.Windows = append(v.Windows, &window)
|
||||||
|
Reference in New Issue
Block a user