account

package
v2.0.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2016 License: MIT Imports: 16 Imported by: 49

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

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

Account is a client to an account server

func New

func New(server string) *Account

New creates a new account that will use no authentication

func NewWithAccessToken

func NewWithAccessToken(server, accessToken string) *Account

NewWithAccessToken creates a new account client that will use the accessToken to make requests to the specified account server

func NewWithBasicAuth

func NewWithBasicAuth(server, username, password string) *Account

NewWithBasicAuth creates an account client that uses basic authentication

func NewWithKey

func NewWithKey(server, accessKey string) *Account

NewWithKey creates an account client that uses an accessKey to authenticate

func NewWithManager

func NewWithManager(server, accessToken string, manager tokens.Manager) *Account

NewWithManager creates a new account client that will use the accessToken to make requests to the specified account server and the manager to request new tokens for different scopes

func NewWithPublic

func NewWithPublic(server string) *Account

NewWithPublic creates an account client that does not use authentication

func (*Account) AddAccessKey

func (a *Account) AddAccessKey(appID string, name string, rights []types.Right) (key types.AccessKey, err error)

AddAccessKey adds an access key to the application with the specified name and rights

func (*Account) AddEUI

func (a *Account) AddEUI(appID string, eui types.AppEUI) error

AddEUI adds an EUI to the applications list of EUIs

func (*Account) AppRights

func (a *Account) AppRights(appID string) (rights []types.Right, err error)

AppRights returns the rights the current account client has to a certain application

func (*Account) BrokerToken

func (a *Account) BrokerToken(id string) (token string, err error)

BrokerToken gets the specified brokers token

func (*Account) ChangeAltitude

func (a *Account) ChangeAltitude(gatewayID string, altitude float64) error

ChangeAltitude changes the altitude of the gateway with the specified ID

func (*Account) ChangeFrequencyPlan

func (a *Account) ChangeFrequencyPlan(gatewayID, plan string) error

ChangeFrequencyPlan changes the requency plan of a gateway

func (*Account) ChangeLocation

func (a *Account) ChangeLocation(gatewayID string, latitude, longitude float64) error

ChangeLocation changes the location of the gateway

func (*Account) ChangeName

func (a *Account) ChangeName(appID string, name string) error

ChangeName changes the application name

func (*Account) ChangeRouter

func (a *Account) ChangeRouter(gatewayID string, router string) error

ChangeRouter changes the router the gateway talks to

func (*Account) ComponentToken

func (a *Account) ComponentToken(typ, id string) (token string, err error)

ComponentToken fetches a token for the component with the given type and id

func (*Account) CreateApplication

func (a *Account) CreateApplication(appID string, name string, EUIs []types.AppEUI) (app Application, err error)

CreateApplication creates a new application on the account server

func (*Account) CreateBroker

func (a *Account) CreateBroker(id string) error

CreateBroker creates a broker with the specified id

func (*Account) CreateComponent

func (a *Account) CreateComponent(typ, id string) error

CreateComponent creates a component with the specified type and id

func (*Account) CreateHandler

func (a *Account) CreateHandler(id string) error

CreateHandler creates a handler with the specified id

func (*Account) CreateRouter

func (a *Account) CreateRouter(id string) error

CreateRouter creates a Router with the specified id

func (*Account) DeleteApplication

func (a *Account) DeleteApplication(appID string) error

DeleteApplication deletes an application

func (*Account) DeleteGateway

func (a *Account) DeleteGateway(gatewayID string) error

DeleteGateway removes a gateway from the account server

func (*Account) EditGateway

func (a *Account) EditGateway(gatewayID string, edits GatewayEdits) error

EditGateway edits the fields of a gateway

func (*Account) EditPassword

func (a *Account) EditPassword(oldPassword, newPassword string) error

EditPassword edits the users password, it requires the old password to be given.

func (*Account) EditProfile

func (a *Account) EditProfile(profile Profile) error

EditProfile edits the users profile. You can change only part of the profile (only the name, for instance) by omitting the other fields from the passed in Profile struct.

func (*Account) FindApplication

func (a *Account) FindApplication(appID string) (app Application, err error)

FindApplication gets a specific application from the account server

func (*Account) FindBroker

func (a *Account) FindBroker(id string) (component Component, err error)

FindBroker finds a broker with the specified id

func (*Account) FindComponent

func (a *Account) FindComponent(typ, id string) (component Component, err error)

FindComponent finds a comonent of the specified type with the specified id

func (*Account) FindGateway

func (a *Account) FindGateway(gatewayID string) (gateway Gateway, err error)

FindGateway returns the information about a specific gateay

func (*Account) FindHandler

func (a *Account) FindHandler(id string) (component Component, err error)

FindHandler finds a handler with the specified id

func (*Account) FindRouter

func (a *Account) FindRouter(id string) (component Component, err error)

FindRouter finds a router with the specified id

func (*Account) FrequencyPlans

func (a *Account) FrequencyPlans() (map[string]FrequencyPlan, error)

FrequencyPlans returns the frequency plans the account server supports

func (*Account) GenerateEUI

func (a *Account) GenerateEUI(appID string) (*types.AppEUI, error)

GenerateEUI creates a new EUI for the application

func (*Account) GetGatewayToken

func (a *Account) GetGatewayToken(gatewayID string) (*oauth2.Token, error)

GetGatewayToken gets the gateway token

func (*Account) Grant

func (a *Account) Grant(appID string, username string, rights []types.Right) error

Grant adds a collaborator to the application

func (*Account) GrantGatewayRights

func (a *Account) GrantGatewayRights(gatewayID string, username string, rights []types.Right) error

GrantGatewayRights grants rights to a collaborator of the gateway

func (*Account) HandlerToken

func (a *Account) HandlerToken(id string) (token string, err error)

HandlerToken gets the specified handlers token

func (*Account) ListApplications

func (a *Account) ListApplications() (apps []Application, err error)

ListApplications list all applications

func (*Account) ListComponents

func (a *Account) ListComponents() ([]Component, error)

ListComponents lists all of the users components

func (*Account) ListGateways

func (a *Account) ListGateways() (gateways []Gateway, err error)

ListGateways list all gateways

func (*Account) Profile

func (a *Account) Profile() (user Profile, err error)

Profile gets the user profile of the user that is logged in

func (*Account) RegisterGateway

func (a *Account) RegisterGateway(gatewayID string, frequencyPlan string, location *Location) (gateway Gateway, err error)

RegisterGateway registers a new gateway on the account server

func (*Account) RegisterUser

func (a *Account) RegisterUser(username, email, password string) error

RegisterUser registers a user on the account server

func (*Account) RemoveAccessKey

func (a *Account) RemoveAccessKey(appID string, name string) error

RemoveAccessKey removes the specified access key from the application

func (*Account) RemoveEUI

func (a *Account) RemoveEUI(appID string, eui types.AppEUI) error

RemoveEUI removes the specified EUI from the application

func (*Account) Retract

func (a *Account) Retract(appID string, username string) error

Retract removes rights from a collaborator of the application

func (*Account) RetractGatewayRights

func (a *Account) RetractGatewayRights(gatewayID string, username string) error

RetractGatewayRights removes rights from a collaborator of the gateway

func (*Account) RouterToken

func (a *Account) RouterToken(id string) (token string, err error)

RouterToken gets the specified routers token

func (*Account) SetPublicRights

func (a *Account) SetPublicRights(gatewayID string, rights []types.Right) error

SetPublicRights changes the publicily visible rights of the gateway

func (*Account) StreamApplications

func (a *Account) StreamApplications() (*ApplicationStream, error)

StreamGateways lists all gateways in a streaming fashion

func (*Account) StreamGateways

func (a *Account) StreamGateways() (*GatewayStream, error)

StreamGateways lists all gateways in a streaming fashion

func (*Account) TransferOwnership

func (a *Account) TransferOwnership(gatewayID, username string) error

TransferOwnership transfers the owenership of the gateway to another user

func (*Account) WithAuth

func (a *Account) WithAuth(strategy auth.Strategy) *Account

WithAuth sets the authentication strategy the account will use

func (*Account) WithHeader

func (a *Account) WithHeader(name, value string) *Account

WithHeader adds the header to every request to the account server

func (*Account) WithLogger

func (a *Account) WithLogger(logger log.Interface) *Account

WithLogger sets the logger that the account will use to log warnings

type Application

type Application struct {
	ID            string            `json:"id"   valid:"required"`
	Name          string            `json:"name" valid:"required"`
	EUIs          []types.AppEUI    `json:"euis,omitempty"`
	AccessKeys    []types.AccessKey `json:"access_keys,omitempty"`
	Created       time.Time         `json:"created,omitempty"`
	Collaborators []Collaborator    `json:"collaborators,omitempty"`
}

Application represents an application on The Things Network

type ApplicationStream

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

GatewayStream is a stream of gateways that can be closed

func (*ApplicationStream) Close

func (s *ApplicationStream) Close() error

Close closes the gateway stream

func (*ApplicationStream) Next

func (s *ApplicationStream) Next() (*Application, error)

Next requests the next gateway on the stream, blocking until there is one If there are no more gateways, the error will be io.EOF

type Collaborator

type Collaborator struct {
	Username string        `json:"username" valid:"required"`
	Rights   []types.Right `json:"rights"   valid:"required"`
}

Collaborator is a user that has rights to a certain application

func (*Collaborator) HasRight

func (c *Collaborator) HasRight(right types.Right) bool

HasRight checks if the collaborator has a specific right

type Component

type Component struct {
	Type    string    `json:"type"`
	ID      string    `json:"id"`
	Created time.Time `json:"created,omitempty"`
}

Component represents a component on the newtork

type ComponentType

type ComponentType string
const (
	Handler ComponentType = "handler"
	Router  ComponentType = "router"
	Broker  ComponentType = "broker"
)

type FrequencyPlan

type FrequencyPlan struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	URL         string `json:"url"`
}

type Gateway

type Gateway struct {
	ID               string         `json:"id" valid:"required"`
	Activated        bool           `json:"activated"`
	FrequencyPlan    string         `json:"frequency_plan"`
	FrequencyPlanURL string         `json:"frequency_plan_url"`
	PublicRights     []types.Right  `json:"public_rights"`
	LocationPublic   bool           `json:"location_public"`
	StatusPublic     bool           `json:"status_public"`
	AutoUpdate       bool           `json:"auto_update"`
	Location         *Location      `json:"location"`
	Altitude         float64        `json:"altitude"`
	Collaborators    []Collaborator `json:"collaborator"`
	Key              string         `json:"key"`

	Token      *oauth2.Token
	Attributes GatewayAttributes `json:"attributes"`
	Router     string            `json:"string"`
	// contains filtered or unexported fields
}

Gateway represents a gateway on the account server

type GatewayAttributes

type GatewayAttributes struct {
	Brand        string    `json:"brand"`
	Model        string    `json:"model"`
	Placement    Placement `json:"placement"`
	AntennaType  string    `json:"antenna_type"`
	AntennaModel string    `json:"antenna_model"`
	Description  string    `json:"description"`
}

type GatewayEdits

type GatewayEdits struct {
	Owner         string            `json:"owner,omitempty"`
	PublicRights  []types.Right     `json:"public_rights,omitempty"`
	FrequencyPlan string            `json:"frequency_plan,omitempty"`
	AutoUpdate    *bool             `json:"auto_update,omitempty"`
	Location      *Location         `json:"location,omitempty"`
	Altitude      float64           `json:"altitude,omitempty"`
	Attributes    GatewayAttributes `json:"attributes,omitempty"`
	Router        string            `json:"router,omitempty"`
}

GatewayEdits contains editable fields of gateways

type GatewayStream

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

GatewayStream is a stream of gateways that can be closed

func (*GatewayStream) Close

func (s *GatewayStream) Close() error

Close closes the gateway stream

func (*GatewayStream) Next

func (s *GatewayStream) Next() (*Gateway, error)

Next requests the next gateway on the stream, blocking until there is one If there are no more gateways, the error will be io.EOF

type Location

type Location struct {
	// Empty denotes that the location is not given as oposed to (0, 0) which is a
	// valid location
	Empty     bool    `json:"-"`
	Longitude float64 `json:"lng"`
	Latitude  float64 `json:"lat"`
}

Location is the GPS location of a gateway

func (Location) MarshalJSON

func (loc Location) MarshalJSON() ([]byte, error)

MarshalJSON is a custom json marshaller for Location that maps an empty Location to `false`

func (*Location) UnmarshalJSON

func (loc *Location) UnmarshalJSON(b []byte) error

UnmarshalJSON is a custom unmarshaller for location that allows falsy types false | {} | null -> Location{ Empty: true } ... -> Location

type Name

type Name struct {
	First string `json:"first"`
	Last  string `json:"last"`
}

Name represents the full name of a user

func (*Name) String

func (n *Name) String() string

String implements the Stringer interface for Name

type Placement

type Placement string
const (
	Indoor  Placement = "indoor"
	Outdoor Placement = "outdoor"
)

type Profile

type Profile struct {
	Username string `json:"username"`
	Email    string `json:"email"`
	Name     *Name  `json:"name"`
}

Profile represents the profile of a user

Jump to

Keyboard shortcuts

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