-
-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Seat: fix retrieving list of vehicles (#9703)
- Loading branch information
Showing
5 changed files
with
129 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package seat | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/evcc-io/evcc/util" | ||
"github.com/evcc-io/evcc/util/request" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
// BaseURL is the API base url | ||
const BaseURL = "https://mal-3a.prd.eu.dp.vwg-connect.com/api" | ||
|
||
// API provides list of vehicles for Seat cars | ||
type API struct { | ||
*request.Helper | ||
} | ||
|
||
// NewAPI creates a new vehicle | ||
func NewAPI(log *util.Logger, ts oauth2.TokenSource) *API { | ||
v := &API{ | ||
Helper: request.NewHelper(log), | ||
} | ||
|
||
v.Client.Transport = &oauth2.Transport{ | ||
Source: ts, | ||
Base: v.Client.Transport, | ||
} | ||
|
||
return v | ||
} | ||
|
||
// Vehicles implements the /vehicles response | ||
func (v *API) Vehicles(userID string) ([]string, error) { | ||
var res struct { | ||
UserVehicles struct { | ||
UserId string | ||
Vehicle []struct { | ||
Content string | ||
} | ||
} | ||
} | ||
|
||
uri := fmt.Sprintf("%s/usermanagement/users/v2/users/%s/vehicles", BaseURL, userID) | ||
err := v.GetJSON(uri, &res) | ||
|
||
var vehicles []string | ||
for _, v := range res.UserVehicles.Vehicle { | ||
vehicles = append(vehicles, v.Content) | ||
} | ||
|
||
return vehicles, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cupra | ||
|
||
import "net/url" | ||
|
||
// Authorization parameters | ||
var AuthParams = url.Values{ | ||
"response_type": {"code id_token"}, // token | ||
"client_id": {"30e33736-c537-4c72-ab60-74a7b92cfe83@apps_vw-dilab_com"}, | ||
"redirect_uri": {"cupraconnect://identity-kit/login"}, | ||
"scope": {"openid profile mbb"}, // cars birthdate nickname address phone | ||
} | ||
|
||
// TokenRefreshService parameters | ||
var TRSParams = url.Values{ | ||
"brand": {"cupra"}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters