connect

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsExpired

func IsExpired(expires *jwt.NumericDate) bool

Check if a token is expired

Types

type ApiError

type ApiError struct {
	StatusCode int        `json:"statusCode"`
	Timestamp  string     `json:"timestamp"`
	Path       string     `json:"path"`
	Message    ApiMessage `json:"message"`
}

An error response from the Connect API

type ApiMessage

type ApiMessage struct {
	StatusCode int    `json:"statusCode"`
	Message    string `json:"message"`
	Error      string `json:"error"`
}

A message from the Connect API. This is used in error responses.

type ApplicationVersion

type ApplicationVersion struct {
	Id                    string `json:"_id"`
	ApplicationName       string `json:"applicationName"`
	IosLatestVersion      string `json:"iosLatestVersion"`
	IosMinimalVersion     string `json:"iosMinimalVersion"`
	AndroidLatestVersion  string `json:"androidLatestVersion"`
	AndroidMinimalVersion string `json:"androidMinimalVersion"`
}

*

  • Contents of the X-Application-Version header

type ConnectAPI

type ConnectAPI interface {
	SetDebug()
	AssertValidToken() error
	Login() error
	Logout() error
	GetStations() ([]Station, error)
	GetStation(id string) (Station, error)
	GetTransactionStatistics(stationId string) (TransactionStats, error)
	GetAllTransactions(stationId string) ([]Transaction, error)
	GetTransactions(stationId string, limit int, offset int) ([]Transaction, error)
	GetTransaction(id string) (Transaction, error)
	ParseToken() (*jwt.Token, TokenClaims, error)
}

A Connect API client

type ConnectAPIClient

type ConnectAPIClient struct {
	Username string
	Password string
	Token    string
	Client   *resty.Client
	PageSize int
}

func NewConnectAPI

func NewConnectAPI(username, password, host string) *ConnectAPIClient

func (*ConnectAPIClient) AssertValidToken

func (c *ConnectAPIClient) AssertValidToken() error

Ensure the login token is valid

func (*ConnectAPIClient) GetAllTransactions

func (c *ConnectAPIClient) GetAllTransactions(stationId string) ([]Transaction, error)

func (*ConnectAPIClient) GetStation

func (c *ConnectAPIClient) GetStation(id string) (Station, error)

func (*ConnectAPIClient) GetStations

func (c *ConnectAPIClient) GetStations() ([]Station, error)

func (*ConnectAPIClient) GetTransaction

func (c *ConnectAPIClient) GetTransaction(id string) (Transaction, error)

func (*ConnectAPIClient) GetTransactionStatistics

func (c *ConnectAPIClient) GetTransactionStatistics(stationId string) (TransactionStats, error)

func (*ConnectAPIClient) GetTransactions

func (c *ConnectAPIClient) GetTransactions(stationId string, limit int, offset int) ([]Transaction, error)

Get a single page of transactions, defined by the limit and offset

func (*ConnectAPIClient) Login

func (c *ConnectAPIClient) Login() error

func (*ConnectAPIClient) Logout

func (c *ConnectAPIClient) Logout() error

func (*ConnectAPIClient) ParseToken

func (c *ConnectAPIClient) ParseToken() (*jwt.Token, TokenClaims, error)

func (*ConnectAPIClient) SetDebug

func (c *ConnectAPIClient) SetDebug()

Enable debug mode in the underlying resty client

type Connector

type Connector struct {
	ID        int     `json:"id"`
	Type      string  `json:"type"`
	Status    string  `json:"status"`
	Power     float64 `json:"power"`
	MaxPower  float64 `json:"maxPower"`
	ErrorCode string  `json:"errorCode"`
}

type GetStationsResponse

type GetStationsResponse struct {
	Stations []Station `json:"stations"`
}

Response type of the stations endipoint

type GetTransactionResponse

type GetTransactionResponse struct {
	Transaction Transaction `json:"transaction"`
}

type GetTransactionsResponse

type GetTransactionsResponse struct {
	Transactions []Transaction `json:"data"`
}

type LoginResponse

type LoginResponse struct {
	Token          string `json:"token"`
	IsInitialLogIn bool   `json:"isInitialLogIn"`
	User           User   `json:"user"`
}

A login response from the Connect API

type MeterValues

type MeterValues struct {
	Date                       []time.Time `json:"date"`
	CurrentImport              []float64   `json:"currentImport"`
	CurrentOffered             []float64   `json:"currentOffered"`
	EnergyActiveImportRegister []int       `json:"energyActiveImportRegister"`
	PowerActiveImport          []float64   `json:"powerActiveImport"`
	SoC                        []int       `json:"SoC"`
	Temperature                []float64   `json:"temperature"`
	Voltage                    []int       `json:"voltage"`
}

type Station

type Station struct {
	ID           string      `json:"id"`
	Identity     string      `json:"identity"`
	SerialNumber string      `json:"serialNumber"`
	Online       bool        `json:"online"`
	Mode         string      `json:"mode"`
	Status       string      `json:"status"`
	ErrorCode    string      `json:"errorCode"`
	Connectors   []Connector `json:"connectors"`
	Currency     string      `json:"currency"`
	PriceKW      float64     `json:"priceKW"`
}

type TokenClaims

type TokenClaims struct {
	jwt.RegisteredClaims
	Iat           int64  `json:"iat"`
	UserId        string `json:"userId"`
	UserSessionId string `json:"userSessionId"`
}

type Transaction

type Transaction struct {
	ID               string      `json:"_id"`
	User             string      `json:"user"`
	Station          string      `json:"station"`
	IdTag            string      `json:"idTag"`
	ConnectorId      int         `json:"connectorId"`
	StartAt          string      `json:"startAt"`
	Duration         int         `json:"duration"`
	Energy           int         `json:"energy"`
	Status           int         `json:"status"`
	Power            int         `json:"power"`
	Currency         string      `json:"currency"`
	PriceKW          float64     `json:"priceKW"`
	PriceTotal       float64     `json:"priceTotal"`
	MeterStart       int         `json:"meterStart"`
	MeterStop        int         `json:"meterStop"`
	StopAt           string      `json:"stopAt"`
	StopReason       string      `json:"stopReason"`
	AverageCurrent   float64     `json:"averageCurrent"`
	ChargingDuration int         `json:"chargingDuration"`
	MeterValues      MeterValues `json:"meterValues"`
}

type TransactionStats

type TransactionStats struct {
	TotalEnergy   int     `json:"totalEnergy"`
	Sessions      int     `json:"sessions"`
	AverageEnergy float64 `json:"averageEnergy"`
	Duration      int     `json:"duration"`
	TopSession    int     `json:"topSession"`
	Currency      string  `json:"currency"`
}

type User

type User struct {
	FirstName string `json:"firstName"`
	LastName  string `json:"lastName"`
	Email     string `json:"email"`
	Phone     string `json:"phone"`
	Language  string `json:"language"`
	ID        string `json:"id"`
}

A user object from the Connect API

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL