api

package module
v0.0.0-...-f75d610 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

README

go-api

Client for the Cacophony API server.

Documentation

Index

Constants

View Source
const (
	DeviceConfigPath     = "/etc/cacophony/device.yaml"
	RegisteredConfigPath = "/etc/cacophony/device-priv.yaml"
)

Variables

Functions

func IsPermanentError

func IsPermanentError(err error) bool

IsPermanentError examines the supplied error and returns true if it is permanent.

Types

type CacophonyAPI

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

func NewAPI

func NewAPI() (*CacophonyAPI, error)

NewAPI parses device.yaml, and creates a new CacophonyAPI and saves the generated password and ID to device-priv.yaml

func (*CacophonyAPI) DownloadFile

func (api *CacophonyAPI) DownloadFile(fileResponse *FileResponse, filePath string) error

DownloadFile specified by fileResponse and save it to filePath

func (*CacophonyAPI) GetFileDetails

func (api *CacophonyAPI) GetFileDetails(fileID int) (*FileResponse, error)

GetFileDetails of the supplied fileID from the Cacophony API and return FileResponse info. This can then be parsed into DownloadFile to download the file

func (*CacophonyAPI) GetSchedule

func (api *CacophonyAPI) GetSchedule() ([]byte, error)

GetSchedule will get the audio schedule

func (*CacophonyAPI) JustRegistered

func (api *CacophonyAPI) JustRegistered() bool

func (*CacophonyAPI) Password

func (api *CacophonyAPI) Password() string

func (*CacophonyAPI) ReportEvent

func (api *CacophonyAPI) ReportEvent(jsonDetails []byte, times []time.Time) error

ReportEvent described by jsonDetails and timestamps to the Cacophony API

func (*CacophonyAPI) UploadThermalRaw

func (api *CacophonyAPI) UploadThermalRaw(r io.Reader) error

UploadThermalRaw uploads the file to Cacophony API as a multipartmessage with data of type thermalRaw specified

type CacophonyDevice

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

type Config

type Config struct {
	ServerURL  string `yaml:"server-url" json:"serverURL"`
	Group      string `yaml:"group" json:"groupname"`
	DeviceName string `yaml:"device-name" json:"devicename"`
}

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig from deviceConfigPath with a read lock

func ParseConfig

func ParseConfig(buf []byte) (*Config, error)

ParseConfig takes supplied bytes and returns a parsed Config struct

func (*Config) Validate

func (conf *Config) Validate() error

Validate checks supplied Config contains the required data

type Error

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

Error is returned by API calling methods. As well as an error message, it includes whether the error is permanent or not.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) Permanent

func (e *Error) Permanent() bool

Permanent returns true if the error is permanent. Operations resulting in non-permanent/temporary errors may be retried.

type FileDetails

type FileDetails struct {
	Name         string
	OriginalName string
}

type FileInfo

type FileInfo struct {
	Details FileDetails
	Type    string
}

type FileResponse

type FileResponse struct {
	File FileInfo
	Jwt  string
}

type LockSafeConfig

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

func NewLockSafeConfig

func NewLockSafeConfig(filename string) *LockSafeConfig

func (*LockSafeConfig) GetExLock

func (lockSafeConfig *LockSafeConfig) GetExLock() (bool, error)

GetExLock acquires an exclusive lock on confPassword

func (*LockSafeConfig) Read

func (lockSafeConfig *LockSafeConfig) Read() (*PrivateConfig, error)

ReadPassword acquires a readlock and reads the config

func (*LockSafeConfig) Unlock

func (lockSafeConfig *LockSafeConfig) Unlock()

func (*LockSafeConfig) Write

func (lockSafeConfig *LockSafeConfig) Write(deviceID int, password string) error

WritePassword checks the file is locked and writes the password

type PrivateConfig

type PrivateConfig struct {
	Password string `yaml:"password"`
	DeviceID int    `yaml:"device-id" json:"deviceID"`
}

func LoadPrivateConfig

func LoadPrivateConfig() (*PrivateConfig, error)

LoadPrivateConfig acquires a readlock and reads private config

func (*PrivateConfig) IsValid

func (conf *PrivateConfig) IsValid() bool

Validate checks supplied Config contains the required data

Jump to

Keyboard shortcuts

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