client

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package client provides primitives to interact with the openapi HTTP API.

Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT.

Index

Constants

This section is empty.

Variables

View Source
var AuthPayloadKey = struct{}{}

AuthPayloadKey is something we use to smuggle the auth response payload out via the auth token.

View Source
var ErrAuthenticationNeeded = errors.New("authentication needed")

ErrAuthenticationNeeded is wrapped by any errors resulting from a 401 response. You can test it using errors.Is(err, client.ErrAuthenticationNeeded).

Functions

func AsErr

func AsErr(parent error, withErrorReason interface{}) (err error)

AsErr is a helper that returns nil only if parent is nil and withErrorReason does not have a value in its ErrorReason field. Otherwise, it returns an error derived from both of these values as appropriate.

This is useful since JSON APIs have multiple ways they can return errors, and this function helps normalize them all behind an error type.

func Ensure

func Ensure(parent error, prepend string, response statusCoder, code int) error

For reference, a typical Response struct in the generated API client for a call that specifies 200 and 401 are valid responses normally looks like this:

type AuthenticateResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *Hello
	JSON401      *struct {
		ErrorReason *string `json:"error_reason,omitempty"`
		MfaToken    *string `json:"mfa_token,omitempty"`
		Status      *string `json:"status,omitempty"`
	}
	JSONDefault *Error
}

func NewAuthenticateRequestWithBody

func NewAuthenticateRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)

NewAuthenticateRequestWithBody generates requests for Authenticate with any type of body

func NewAuthenticateRequestWithFormdataBody

func NewAuthenticateRequestWithFormdataBody(server string, body AuthenticateFormdataRequestBody) (*http.Request, error)

NewAuthenticateRequestWithFormdataBody calls the generic Authenticate builder with application/x-www-form-urlencoded body

func NewGetDevicesRequest

func NewGetDevicesRequest(server string, monitorId int, params *GetDevicesParams) (*http.Request, error)

NewGetDevicesRequest generates requests for GetDevices

func NewGetEnvironmentsRequest

func NewGetEnvironmentsRequest(server string) (*http.Request, error)

NewGetEnvironmentsRequest generates requests for GetEnvironments

func NewRenewAuthTokenRequestWithBody

func NewRenewAuthTokenRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)

NewRenewAuthTokenRequestWithBody generates requests for RenewAuthToken with any type of body

func NewRenewAuthTokenRequestWithFormdataBody

func NewRenewAuthTokenRequestWithFormdataBody(server string, body RenewAuthTokenFormdataRequestBody) (*http.Request, error)

NewRenewAuthTokenRequestWithFormdataBody calls the generic RenewAuthToken builder with application/x-www-form-urlencoded body

Types

type AuthenticateFormdataBody

type AuthenticateFormdataBody struct {
	Email    *string `json:"email,omitempty"`
	MfaToken *string `json:"mfa_token,omitempty"`
	Password *string `json:"password,omitempty"`
	Totp     *string `json:"totp,omitempty"`
}

AuthenticateFormdataBody defines parameters for Authenticate.

type AuthenticateFormdataRequestBody

type AuthenticateFormdataRequestBody AuthenticateFormdataBody

AuthenticateFormdataRequestBody defines body for Authenticate for application/x-www-form-urlencoded ContentType.

type AuthenticateResponse

type AuthenticateResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *Hello
	JSON401      *struct {
		ErrorReason *string `json:"error_reason,omitempty"`
		MfaToken    *string `json:"mfa_token,omitempty"`
		Status      *string `json:"status,omitempty"`
	}
	JSONDefault *Error
}

func ParseAuthenticateResponse

func ParseAuthenticateResponse(rsp *http.Response) (*AuthenticateResponse, error)

ParseAuthenticateResponse parses an HTTP response from a AuthenticateWithResponse call

func (AuthenticateResponse) Status

func (r AuthenticateResponse) Status() string

Status returns HTTPResponse.Status

func (AuthenticateResponse) StatusCode

func (r AuthenticateResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type Client

type Client struct {
	// The endpoint of the server conforming to this interface, with scheme,
	// https://api.deepmap.com for example. This can contain a path relative
	// to the server, such as https://api.deepmap.com/dev-test, and all the
	// paths in the swagger spec will be appended to the server.
	Server string

	// Doer for performing requests, typically a *http.Client with any
	// customized settings, such as certificate chains.
	Client HttpRequestDoer

	// A list of callbacks for modifying requests which are generated before sending over
	// the network.
	RequestEditors []RequestEditorFn
}

Client which conforms to the OpenAPI3 specification for this service.

func NewClient

func NewClient(server string, opts ...ClientOption) (*Client, error)

Creates a new Client, with reasonable defaults

func (*Client) AuthenticateWithBody

func (c *Client) AuthenticateWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) AuthenticateWithFormdataBody

func (c *Client) AuthenticateWithFormdataBody(ctx context.Context, body AuthenticateFormdataRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) GetDevices

func (c *Client) GetDevices(ctx context.Context, monitorId int, params *GetDevicesParams, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) GetEnvironments

func (c *Client) GetEnvironments(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) RenewAuthTokenWithBody

func (c *Client) RenewAuthTokenWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) RenewAuthTokenWithFormdataBody

func (c *Client) RenewAuthTokenWithFormdataBody(ctx context.Context, body RenewAuthTokenFormdataRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

type ClientInterface

type ClientInterface interface {
	// GetDevices request
	GetDevices(ctx context.Context, monitorId int, params *GetDevicesParams, reqEditors ...RequestEditorFn) (*http.Response, error)

	// Authenticate request with any body
	AuthenticateWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	AuthenticateWithFormdataBody(ctx context.Context, body AuthenticateFormdataRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	// GetEnvironments request
	GetEnvironments(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

	// RenewAuthToken request with any body
	RenewAuthTokenWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	RenewAuthTokenWithFormdataBody(ctx context.Context, body RenewAuthTokenFormdataRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
}

The interface specification for the client above.

type ClientOption

type ClientOption func(*Client) error

ClientOption allows setting custom parameters during construction

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL overrides the baseURL.

func WithHTTPClient

func WithHTTPClient(doer HttpRequestDoer) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

func WithRequestEditorFn

func WithRequestEditorFn(fn RequestEditorFn) ClientOption

WithRequestEditorFn allows setting up a callback function, which will be called right before sending the request. This can be used to mutate the request.

type ClientWithResponses

type ClientWithResponses struct {
	ClientInterface
}

ClientWithResponses builds on ClientInterface to offer response payloads

func NewClientWithResponses

func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error)

NewClientWithResponses creates a new ClientWithResponses, which wraps Client with return type handling

func (*ClientWithResponses) AuthenticateWithBodyWithResponse

func (c *ClientWithResponses) AuthenticateWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AuthenticateResponse, error)

AuthenticateWithBodyWithResponse request with arbitrary body returning *AuthenticateResponse

func (*ClientWithResponses) AuthenticateWithFormdataBodyWithResponse

func (c *ClientWithResponses) AuthenticateWithFormdataBodyWithResponse(ctx context.Context, body AuthenticateFormdataRequestBody, reqEditors ...RequestEditorFn) (*AuthenticateResponse, error)

func (*ClientWithResponses) GetDevicesWithResponse

func (c *ClientWithResponses) GetDevicesWithResponse(ctx context.Context, monitorId int, params *GetDevicesParams, reqEditors ...RequestEditorFn) (*GetDevicesResponse, error)

GetDevicesWithResponse request returning *GetDevicesResponse

func (*ClientWithResponses) GetEnvironmentsWithResponse

func (c *ClientWithResponses) GetEnvironmentsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetEnvironmentsResponse, error)

GetEnvironmentsWithResponse request returning *GetEnvironmentsResponse

func (*ClientWithResponses) RenewAuthTokenWithBodyWithResponse

func (c *ClientWithResponses) RenewAuthTokenWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RenewAuthTokenResponse, error)

RenewAuthTokenWithBodyWithResponse request with arbitrary body returning *RenewAuthTokenResponse

func (*ClientWithResponses) RenewAuthTokenWithFormdataBodyWithResponse

func (c *ClientWithResponses) RenewAuthTokenWithFormdataBodyWithResponse(ctx context.Context, body RenewAuthTokenFormdataRequestBody, reqEditors ...RequestEditorFn) (*RenewAuthTokenResponse, error)

type ClientWithResponsesInterface

type ClientWithResponsesInterface interface {
	// GetDevices request
	GetDevicesWithResponse(ctx context.Context, monitorId int, params *GetDevicesParams, reqEditors ...RequestEditorFn) (*GetDevicesResponse, error)

	// Authenticate request with any body
	AuthenticateWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AuthenticateResponse, error)

	AuthenticateWithFormdataBodyWithResponse(ctx context.Context, body AuthenticateFormdataRequestBody, reqEditors ...RequestEditorFn) (*AuthenticateResponse, error)

	// GetEnvironments request
	GetEnvironmentsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetEnvironmentsResponse, error)

	// RenewAuthToken request with any body
	RenewAuthTokenWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RenewAuthTokenResponse, error)

	RenewAuthTokenWithFormdataBodyWithResponse(ctx context.Context, body RenewAuthTokenFormdataRequestBody, reqEditors ...RequestEditorFn) (*RenewAuthTokenResponse, error)
}

ClientWithResponsesInterface is the interface specification for the client with responses above.

type Device

type Device struct {
	Icon     *string     `json:"icon,omitempty"`
	Id       *string     `json:"id,omitempty"`
	Location *string     `json:"location,omitempty"`
	Make     *string     `json:"make,omitempty"`
	Model    *string     `json:"model,omitempty"`
	Name     *string     `json:"name,omitempty"`
	Tags     *DeviceTags `json:"tags,omitempty"`
}

Device defines model for device.

type DeviceTags

type DeviceTags map[string]interface{}

DeviceTags defines model for device_tags.

type Error

type Error struct {
	ErrorReason *string `json:"error_reason,omitempty"`
	Status      *string `json:"status,omitempty"`
}

Error defines model for error.

type GetDevicesParams

type GetDevicesParams struct {
	IncludeMerged *bool `form:"include_merged,omitempty" json:"include_merged,omitempty"`
}

GetDevicesParams defines parameters for GetDevices.

type GetDevicesResponse

type GetDevicesResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *struct {
		DeviceDataChecksum *string   `json:"device_data_checksum,omitempty"`
		Devices            *[]Device `json:"devices,omitempty"`
	}
}

func ParseGetDevicesResponse

func ParseGetDevicesResponse(rsp *http.Response) (*GetDevicesResponse, error)

ParseGetDevicesResponse parses an HTTP response from a GetDevicesWithResponse call

func (GetDevicesResponse) Status

func (r GetDevicesResponse) Status() string

Status returns HTTPResponse.Status

func (GetDevicesResponse) StatusCode

func (r GetDevicesResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type GetEnvironmentsResponse

type GetEnvironmentsResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *[]struct {
		ApiUrl              *string `json:"api_url,omitempty"`
		ClientBridgelinkUrl *string `json:"client_bridgelink_url,omitempty"`
		DisplayName         *string `json:"display_name,omitempty"`
		Environment         *string `json:"environment,omitempty"`
	}
	JSONDefault *Error
}

func ParseGetEnvironmentsResponse

func ParseGetEnvironmentsResponse(rsp *http.Response) (*GetEnvironmentsResponse, error)

ParseGetEnvironmentsResponse parses an HTTP response from a GetEnvironmentsWithResponse call

func (GetEnvironmentsResponse) Status

func (r GetEnvironmentsResponse) Status() string

Status returns HTTPResponse.Status

func (GetEnvironmentsResponse) StatusCode

func (r GetEnvironmentsResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type Hello

type Hello struct {
	AbCohort     *string       `json:"ab_cohort,omitempty"`
	AccessToken  *string       `json:"access_token,omitempty"`
	AccountId    *int          `json:"account_id,omitempty"`
	Authorized   *bool         `json:"authorized,omitempty"`
	BridgeServer *string       `json:"bridge_server,omitempty"`
	DateCreated  *time.Time    `json:"date_created,omitempty"`
	Monitors     *[]Monitor    `json:"monitors,omitempty"`
	RefreshToken *string       `json:"refresh_token,omitempty"`
	Settings     *UserSettings `json:"settings,omitempty"`
	TotpEnabled  *bool         `json:"totp_enabled,omitempty"`
	UserId       *int          `json:"user_id,omitempty"`
}

Hello defines model for hello.

type HttpRequestDoer

type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer performs HTTP requests.

The standard http.Client implements this interface.

type Monitor

type Monitor struct {
	Attributes               *MonitorAttributes `json:"attributes,omitempty"`
	AuxIgnore                *bool              `json:"aux_ignore,omitempty"`
	AuxPort                  *string            `json:"aux_port,omitempty"`
	DataSharing              *[]interface{}     `json:"data_sharing,omitempty"`
	EthernetSupported        *bool              `json:"ethernet_supported,omitempty"`
	HardwareType             *string            `json:"hardware_type,omitempty"`
	Id                       *int               `json:"id,omitempty"`
	Online                   *bool              `json:"online,omitempty"`
	SerialNumber             *string            `json:"serial_number,omitempty"`
	SignalCheckCompletedTime *time.Time         `json:"signal_check_completed_time,omitempty"`
	SolarConfigured          *bool              `json:"solar_configured,omitempty"`
	SolarConnected           *bool              `json:"solar_connected,omitempty"`
	TimeZone                 *string            `json:"time_zone,omitempty"`
	ZigbeeSupported          *bool              `json:"zigbee_supported,omitempty"`
}

Monitor defines model for monitor.

type MonitorAttributes

type MonitorAttributes struct {
	BasementType        *string      `json:"basement_type,omitempty"`
	BasementTypeKey     *interface{} `json:"basement_type_key,omitempty"`
	Cost                *float32     `json:"cost,omitempty"`
	CycleStart          *interface{} `json:"cycle_start,omitempty"`
	ElectricityCost     *interface{} `json:"electricity_cost,omitempty"`
	HomeSizeType        *string      `json:"home_size_type,omitempty"`
	HomeSizeTypeKey     *interface{} `json:"home_size_type_key,omitempty"`
	HomeType            *string      `json:"home_type,omitempty"`
	HomeTypeKey         *interface{} `json:"home_type_key,omitempty"`
	Id                  *int         `json:"id,omitempty"`
	Name                *interface{} `json:"name,omitempty"`
	NumberOfOccupants   *string      `json:"number_of_occupants,omitempty"`
	OccupancyType       *string      `json:"occupancy_type,omitempty"`
	OccupancyTypeKey    *interface{} `json:"occupancy_type_key,omitempty"`
	Panel               *interface{} `json:"panel,omitempty"`
	PostalCode          *string      `json:"postal_code,omitempty"`
	PowerRegion         *string      `json:"power_region,omitempty"`
	SellBackRate        *float32     `json:"sell_back_rate,omitempty"`
	ShowCost            *bool        `json:"show_cost,omitempty"`
	SolarTouEnabled     *bool        `json:"solar_tou_enabled,omitempty"`
	State               *interface{} `json:"state,omitempty"`
	ToGridThreshold     *interface{} `json:"to_grid_threshold,omitempty"`
	TouEnabled          *bool        `json:"tou_enabled,omitempty"`
	UserSetCost         *bool        `json:"user_set_cost,omitempty"`
	UserSetSellBackRate *bool        `json:"user_set_sell_back_rate,omitempty"`
	YearBuiltType       *string      `json:"year_built_type,omitempty"`
	YearBuiltTypeKey    *interface{} `json:"year_built_type_key,omitempty"`
}

MonitorAttributes defines model for monitor_attributes.

type NotificationSettings

type NotificationSettings struct {
	AlwaysOnChangePush       *bool `json:"always_on_change_push,omitempty"`
	ComparisonChangePush     *bool `json:"comparison_change_push,omitempty"`
	DailyChangePush          *bool `json:"daily_change_push,omitempty"`
	GeneratorOffPush         *bool `json:"generator_off_push,omitempty"`
	GeneratorOnPush          *bool `json:"generator_on_push,omitempty"`
	GridOutagePush           *bool `json:"grid_outage_push,omitempty"`
	GridRestoredPush         *bool `json:"grid_restored_push,omitempty"`
	MonitorMonthlyEmail      *bool `json:"monitor_monthly_email,omitempty"`
	MonitorOfflineEmail      *bool `json:"monitor_offline_email,omitempty"`
	MonitorOfflinePush       *bool `json:"monitor_offline_push,omitempty"`
	MonthlyChangePush        *bool `json:"monthly_change_push,omitempty"`
	NewNamedDeviceEmail      *bool `json:"new_named_device_email,omitempty"`
	NewNamedDevicePush       *bool `json:"new_named_device_push,omitempty"`
	NewPeakEmail             *bool `json:"new_peak_email,omitempty"`
	NewPeakPush              *bool `json:"new_peak_push,omitempty"`
	RelayUpdateAvailablePush *bool `json:"relay_update_available_push,omitempty"`
	RelayUpdateInstalledPush *bool `json:"relay_update_installed_push,omitempty"`
	TimeOfUse                *bool `json:"time_of_use,omitempty"`
	WeeklyChangePush         *bool `json:"weekly_change_push,omitempty"`
}

NotificationSettings defines model for notification_settings.

type RenewAuthTokenFormdataBody

type RenewAuthTokenFormdataBody struct {
	IsAccessToken *bool   `json:"is_access_token,omitempty"`
	RefreshToken  *string `json:"refresh_token,omitempty"`
	UserId        *int    `json:"user_id,omitempty"`
}

RenewAuthTokenFormdataBody defines parameters for RenewAuthToken.

type RenewAuthTokenFormdataRequestBody

type RenewAuthTokenFormdataRequestBody RenewAuthTokenFormdataBody

RenewAuthTokenFormdataRequestBody defines body for RenewAuthToken for application/x-www-form-urlencoded ContentType.

type RenewAuthTokenResponse

type RenewAuthTokenResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *struct {
		AccessToken  *string    `json:"access_token,omitempty"`
		Expires      *time.Time `json:"expires,omitempty"`
		RefreshToken *string    `json:"refresh_token,omitempty"`
	}
	JSONDefault *Error
}

func ParseRenewAuthTokenResponse

func ParseRenewAuthTokenResponse(rsp *http.Response) (*RenewAuthTokenResponse, error)

ParseRenewAuthTokenResponse parses an HTTP response from a RenewAuthTokenWithResponse call

func (RenewAuthTokenResponse) Status

func (r RenewAuthTokenResponse) Status() string

Status returns HTTPResponse.Status

func (RenewAuthTokenResponse) StatusCode

func (r RenewAuthTokenResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type RequestEditorFn

type RequestEditorFn func(ctx context.Context, req *http.Request) error

RequestEditorFn is the function signature for the RequestEditor callback function

type UserSettings

type UserSettings struct {
	Settings *struct {
		LabsEnabled   *bool                            `json:"labs_enabled,omitempty"`
		Notifications *map[string]NotificationSettings `json:"notifications,omitempty"`
	} `json:"settings,omitempty"`
	UserId  *int `json:"user_id,omitempty"`
	Version *int `json:"version,omitempty"`
}

UserSettings defines model for user_settings.

Jump to

Keyboard shortcuts

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