api

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 20 Imported by: 8

README

go-api

Client for the Cacophony API server.

Test Setup

To run the tests you need to setup a cacophony-api instance and add some entries to the SQL DB

  • Follow setup the instructions at Cacophony API server
  • Copy SQL file to API docker container sudo docker cp db-test-seed.sql cacophony-api:/db-seed.sql
  • Run SQL file sudo docker exec cacophony-api sh -c "sudo -i -u postgres psql cacophonytest -f/db-seed.sql"

Documentation

Index

Constants

This section is empty.

Variables

Functions

func IsNotRegisteredError

func IsNotRegisteredError(err error) bool

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 New

func New() (*CacophonyAPI, error)

New will get an API from the config files and authenticate. Will return an error if the device has not been registered yet.

func Register

func Register(devicename, password, group, apiURL string, saltId int) (*CacophonyAPI, error)

Register will check that there is not already device config files, will then register with the given parameters and then save them in new config files.

func (*CacophonyAPI) DeviceID

func (api *CacophonyAPI) DeviceID() int

func (*CacophonyAPI) DeviceName

func (api *CacophonyAPI) DeviceName() string

func (*CacophonyAPI) DownloadFile

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

DownloadFile specified by fileResponse and save it to filePath

func (*CacophonyAPI) GetDeviceSettings added in v1.1.0

func (api *CacophonyAPI) GetDeviceSettings() (*Settings, error)

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) GroupName

func (api *CacophonyAPI) GroupName() string

func (*CacophonyAPI) Heartbeat added in v1.0.1

func (api *CacophonyAPI) Heartbeat(nextHeartBeat time.Time) ([]byte, error)

Send heart beat from device with expected next heart beat time

func (*CacophonyAPI) Password

func (api *CacophonyAPI) Password() string

func (*CacophonyAPI) ReRegisterByAuthorized added in v1.1.0

func (api *CacophonyAPI) ReRegisterByAuthorized(newName, newGroup, newPassword, authToken string) error

This allows the device to be registered even

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) Reregister

func (api *CacophonyAPI) Reregister(newName, newGroup, newPassword string) error

Reregister will register getting a new name and/or group

func (*CacophonyAPI) UploadVideo added in v1.0.3

func (api *CacophonyAPI) UploadVideo(r io.Reader, data map[string]interface{}) (int, error)

UploadVideo uploads the file to Cacophony API as a multipartmessage

type CacophonyDevice

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

type Config

type Config struct {
	ServerURL      string
	Group          string
	DeviceName     string
	DevicePassword string
	DeviceID       int
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(configFolder string) (*Config, error)

func (*Config) Registered

func (c *Config) Registered() bool

type Dimensions added in v1.1.0

type Dimensions struct {
	Width  int
	Height int
}

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
	FileSize int
}

type Point added in v1.1.0

type Point struct {
	X int
	Y int
}

type Region added in v1.1.0

type Region struct {
	RegionData []Point `json:"regionData"`
}

type Settings added in v1.1.0

type Settings struct {
	ReferenceImagePOV            string
	ReferenceImagePOVFileSize    int
	ReferenceImageInSitu         string
	ReferenceImageInSituFileSize int
	Warp                         Warp
	MaskRegions                  []Region
	RatThresh                    interface{}
	Success                      bool
	Messages                     []string
}

type Warp added in v1.1.0

type Warp struct {
	Dimensions  Dimensions
	Origin      Point
	TopLeft     Point
	TopRight    Point
	BottomLeft  Point
	BottomRight Point
}

Jump to

Keyboard shortcuts

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