api

package
v0.0.0-...-9aa193b Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2020 License: MIT Imports: 9 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	//device endpoints - device UUID is inferred from token
	GetDeviceConfig(ctx context.Context) (Device, error)
	InsertReading(ctx context.Context, tCelcius float64, rh float64) (Reading, error)

	//admin endpoints
	RegisterDevice(ctx context.Context, name string, config string) (Device, error)
	ConfigureDevice(ctx context.Context, uuid string, name string, config string) (Device, error)
	GetDeviceTokenFor(ctx context.Context, uuid string) (Device, error)
	GetDeviceConfigFor(ctx context.Context, uuid string) (device Device, err error)
}

API is the client interface

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements API over HTTPs

func NewClient

func NewClient(
	host string,
	http Doer,
) Client

NewClient creates a client that directly uses the provided transport

func NewDefaultClient

func NewDefaultClient(
	host string,
	transport http.RoundTripper,
	token string,
) Client

NewDefaultClient creates a client with default middlewares

func (Client) ConfigureDevice

func (c Client) ConfigureDevice(ctx context.Context, uuid string, name string, config string) (device Device, err error)

ConfigureDevice configures the specified device

func (Client) GetDeviceConfig

func (c Client) GetDeviceConfig(ctx context.Context) (device Device, err error)

GetDeviceConfig gets the current config text for current the device

func (Client) GetDeviceConfigFor

func (c Client) GetDeviceConfigFor(ctx context.Context, uuid string) (device Device, err error)

GetDeviceConfigFor gets the current config text for the specified device

func (Client) GetDeviceTokenFor

func (c Client) GetDeviceTokenFor(ctx context.Context, uuid string) (device Device, err error)

GetDeviceTokenFor generates a token for the device

func (Client) InsertReading

func (c Client) InsertReading(ctx context.Context, tCelcius float64, rh float64) (reading Reading, err error)

InsertReading records a new sensor reading for current the device

func (Client) RegisterDevice

func (c Client) RegisterDevice(ctx context.Context, name string, config string) (device Device, err error)

RegisterDevice registers a new device

type ConfigureDeviceRequest

type ConfigureDeviceRequest struct {
	DeviceUUID string          `json:"device_uuid" binding:"required"`
	Name       string          `json:"name"`
	Config     json.RawMessage `json:"config" binding:"required"`
}

ConfigureDeviceRequest encodes a single request for user registration

type Device

type Device struct {
	DeviceUUID string           `json:"device_uuid,omitempty"`
	Name       *string          `json:"name,omitempty"`
	Token      *string          `json:"token,omitempty"`
	Config     *json.RawMessage `json:"config,omitempty"`
}

Device represents the response to a device-related endpoint

type Doer

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

Doer impelments the http Do method

type GetDeviceConfigRequest

type GetDeviceConfigRequest struct {
	DeviceUUID *string `uri:"uuid"`
}

GetDeviceConfigRequest encodes a single request for user registration

type GetDeviceTokenRequest

type GetDeviceTokenRequest struct {
	DeviceUUID string `json:"device_uuid" binding:"required"`
}

GetDeviceTokenRequest encodes a single request for user registration

type InsertReadingRequest

type InsertReadingRequest struct {
	TemperatureCelcius json.Number `json:"temperature_celcius" binding:"required"`
	RelativeHumidity   json.Number `json:"relative_humidity" binding:"required"`
}

InsertReadingRequest encodes a single request for user registration

type Reading

type Reading struct {
	DeviceUUID         string       `json:"device_uuid,omitempty"`
	ReadingUUID        string       `json:"reading_uuid,omitempty"`
	TemperatureCelcius *json.Number `json:"temperature_celcius,omitempty"`
	RelativeHumidity   *json.Number `json:"relative_humidity,omitempty"`
}

Reading represents the response to a reading-related endpoint

type RegistrationRequest

type RegistrationRequest struct {
	Name   string          `json:"name" binding:"required"`
	Config json.RawMessage `json:"config" binding:"required"`
}

RegistrationRequest encodes a single request for user registration

type RoundTripHandler

type RoundTripHandler func(req *http.Request) (*http.Response, error)

RoundTripHandler is a helper type for building RoundTrippers

func (RoundTripHandler) RoundTrip

func (h RoundTripHandler) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes the request

type RoundTripper

type RoundTripper interface {
	RoundTrip(req *http.Request) (*http.Response, error)
}

RoundTripper impelments the http RoundTrip method

func DefaultAuthorizer

func DefaultAuthorizer(next RoundTripper, token string) RoundTripper

DefaultAuthorizer returns a roundtripper to attach a bearer token to each request

func DefaultRetryer

func DefaultRetryer(next RoundTripper) RoundTripper

DefaultRetryer returns a roundtripper to retry certain response codes

Jump to

Keyboard shortcuts

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