This is a full functioning REST API for the Tesla System.
First steps are to get your auth token, see below:
package main
import (
"context"
tesla "github.com/Noy/Tesla""log"
)
funcmain() {
authToken, err:=tesla.RetrieveToken(context.Background(), "tesla@email.com", "teslaPassword")
iferr!=nil {
// error handling is option for you
}
log.Println(authToken) // log the result, which will be your auth token
}
Then, you need to retrieve your car's ID:
package main
import (
"github.com/Noy/Tesla"
)
// AuthenticationfuncgetCarId() int64 {
authToken:="abc123"// Use the auth token from before to authenticate with AuthTeslaauth:= tesla.AuthTesla{AccessToken: authToken}
id:=auth.ListVehicles()[0].IDreturnid
}
Finally, you can retrieve data about your car (or even perform actions!):
package main
import (
"github.com/Noy/Tesla"
)
// AuthenticationfuncauthTesla() *tesla.AuthTesla {
varid, authTokenstring// Use the auth token and ID from before to authenticate with AuthTeslateslaCar:= tesla.AuthTesla{ID: id, AccessToken: authToken}
return&teslaCar
}
//Then...// Use this function in your desired ways.. It'll honk your car!funchonk() {
authTesla().HonkHorn()
}