Documentation ¶
Overview ¶
Package rest provides the data structures and primitive mechanisms for representing and communicating framework constructs with the RESTful server.
Index ¶
- func DecodeOCError(resp *http.Response) error
- type DeviceListServiceItem
- type DeviceNode
- type Group
- type GroupCreateRequest
- type GroupNode
- type HealthCheckResponse
- type HealthStatus
- type Host
- func (host Host) DelinkService(deviceID, serviceID string) error
- func (host Host) DeviceAll() ([]NodeDescriptor, error)
- func (host Host) DeviceTransducerLastValue(deviceID, transducerID string) ([]byte, error)
- func (host Host) DeviceTransducerValues(deviceID string) ([]TransducerValue, error)
- func (host Host) ExecuteCommand(deviceID, commandID string) error
- func (host Host) GroupAll() ([]Group, error)
- func (host Host) GroupCreate(name string) error
- func (host Host) HealthCheck() (HealthStatus, error)
- func (host Host) LinkService(deviceID, serviceID string, config []KeyValuePair) error
- func (host *Host) Login(username, password string) error
- func (host Host) RequestDeviceInfo(deviceID string) (DeviceNode, error)
- func (host Host) RequestLinkedService(deviceID, serviceID string) (DeviceListServiceItem, error)
- func (host Host) RequestLocationDevices(locID string, recursive bool) ([]NodeDescriptor, error)
- func (host Host) RequestLocationInfo(locID string) (LocationNode, error)
- func (host Host) RequestServiceDeviceList(serviceID string) ([]ServiceDeviceListItem, error)
- func (host Host) RequestServiceInfo(serviceID string) (ServiceNode, error)
- func (host Host) RequestUserInfo() (UserDetails, error)
- func (host Host) ServiceCreate(name, description string, properties map[string]string, ...) (ServiceNode, error)
- func (host Host) ServiceDelete(serviceID string) error
- func (host Host) ServiceGet(serviceID string) (ServiceNode, error)
- func (host Host) ServiceList() ([]ServiceNode, error)
- func (host Host) ServiceTokenDelete(serviceID string) error
- func (host Host) ServiceTokenGenerate(serviceID string) (string, error)
- func (host Host) ServiceTokenRegenerate(serviceID string) (string, error)
- func (host Host) ServiceUpdateConfig(serviceID string, configParams []ServiceConfigParameter) (ServiceNode, error)
- func (host Host) UserAll() ([]User, error)
- func (host Host) UserCreate(email, name, password string) error
- type KeyValuePair
- type LocationNode
- type NodeDescriptor
- type Owner
- type PubSub
- type ServiceConfigParameter
- type ServiceCreateRequest
- type ServiceDeviceListItem
- type ServiceNode
- type ServicePubSub
- type ServiceUpdateRequest
- type TransducerInfo
- type TransducerValue
- type User
- type UserCreateRequest
- type UserDetails
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeOCError ¶
Types ¶
type DeviceListServiceItem ¶
type DeviceListServiceItem struct { ServiceID string `json:"service_id"` ServiceConfig []KeyValuePair `json:"config,omitempty"` }
DeviceListServiceItem represents the service and service configuration pair found in in a Device Node's service list
type DeviceNode ¶
type DeviceNode struct { NodeDescriptor // Node descriptor of Device Node Properties map[string]string `json:"properties"` Transducers []TransducerInfo `json:"transducers"` Services []DeviceListServiceItem `json:"linked_services"` }
DeviceNode is a container for Device Node object received from the RESTful JSON interface
func (*DeviceNode) Clone ¶
func (n *DeviceNode) Clone() DeviceNode
Clone creates a new copy of the DeviceNode. This is necessary because a DeviceNode has embedded slices.
type GroupCreateRequest ¶
type GroupCreateRequest struct {
Name string `json:"name"`
}
GroupCreateRequest is the container for the request to create a new group
type GroupNode ¶
type GroupNode struct { ID string `json:"group_id"` // Should really just be id Name string `json:"name"` WriteAccess bool `json:"write_access"` }
GroupNode is a container for User Group object received from the RESTful JSON interface
type HealthCheckResponse ¶
type HealthCheckResponse struct {
Status HealthStatus `json:"status"`
}
HealthCheckResponse encapsulates the response from the server health check
type HealthStatus ¶
type HealthStatus string
HealthStatus represents the result of a health check
const ( // HealthStatusUnknown indicates that the health status was not reported HealthStatusUnknown HealthStatus = "" // HealthStatusOK indicates that the server reported the status to be ok HealthStatusOK HealthStatus = "ok" // HealthStatusDegraded indicates that the server reported the status // to be degraded HealthStatusDegraded HealthStatus = "degraded" )
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host represents the RESTful HTTP server that hosts the framework
func NewHost ¶
NewHost returns an object referencing the framework server
Example ¶
package main import ( "log" "github.com/openchirp/framework/rest" ) func main() { frameworkUri := "http://localhost:7000" id := "5a1ea73df76abe01c57abfb8" token := "DJpHxwmExGbcYwsEHgQezDVeKS4N" host := rest.NewHost(frameworkUri) if err := host.Login(id, token); err != nil { log.Fatalln("Error logging in:", err) } log.Println(host) }
Output:
func (Host) DelinkService ¶
DelinkService makes an HTTP DELETE to the framework server to delink the specified serviceID from device deviceID.
func (Host) DeviceAll ¶
func (host Host) DeviceAll() ([]NodeDescriptor, error)
DeviceAll makes an HTTP GET to the framework server requesting the a list of all devices
func (Host) DeviceTransducerLastValue ¶
DeviceTransducerLastValue makes an HTTP GET to the framework server requesting the transducers last value for the device with ID deviceID and transducer with with ID or name transducerID.
func (Host) DeviceTransducerValues ¶
func (host Host) DeviceTransducerValues(deviceID string) ([]TransducerValue, error)
DeviceTransducerValues makes an HTTP GET to the framework server requesting the transducers last value list for the device with ID deviceID.
func (Host) ExecuteCommand ¶
ExecuteCommand makes an HTTP POST to the framework server to execute the specified commandID on device deviceID.
func (Host) GroupCreate ¶
GroupCreate requests for a new group to be created with the given name
func (Host) HealthCheck ¶
func (host Host) HealthCheck() (HealthStatus, error)
HealthCheck requests the health of the rest server
func (Host) LinkService ¶
func (host Host) LinkService(deviceID, serviceID string, config []KeyValuePair) error
LinkService makes an HTTP POST to the framework server to link the specified serviceID to device deviceID.
func (Host) RequestDeviceInfo ¶
func (host Host) RequestDeviceInfo(deviceID string) (DeviceNode, error)
RequestDeviceInfo makes an HTTP GET to the framework server requesting the Device Node information for the device with ID deviceID.
func (Host) RequestLinkedService ¶
func (host Host) RequestLinkedService(deviceID, serviceID string) (DeviceListServiceItem, error)
RequestLinkedService makes an HTTP POST to the framework server to link the specified serviceID to device deviceID.
func (Host) RequestLocationDevices ¶
func (host Host) RequestLocationDevices(locID string, recursive bool) ([]NodeDescriptor, error)
RequestLocationDevices makes an HTTP GET to the framework server requesting the the list of devices at the specified location. If recursive is true, devices that are located on any sublocations will be included.
func (Host) RequestLocationInfo ¶
func (host Host) RequestLocationInfo(locID string) (LocationNode, error)
RequestLocationInfo makes an HTTP GET to the framework server requesting the Location Node information for the location with ID locid.
func (Host) RequestServiceDeviceList ¶
func (host Host) RequestServiceDeviceList(serviceID string) ([]ServiceDeviceListItem, error)
RequestServiceDeviceList
func (Host) RequestServiceInfo ¶
func (host Host) RequestServiceInfo(serviceID string) (ServiceNode, error)
RequestServiceInfo makes an HTTP GET to the framework server requesting the Service Node information for service with ID serviceID.
Example ¶
package main import ( "fmt" "log" "os" "github.com/openchirp/framework/rest" ) func main() { // Get parameters from environment variables frameworkUri := os.Getenv("FRAMEWORK_SERVER") id := os.Getenv("SERVICE_ID") token := os.Getenv("SERVICE_TOKEN") host := rest.NewHost(frameworkUri) if err := host.Login(id, token); err != nil { log.Fatalln("Error logging in:", err) } sInfo, err := host.RequestServiceInfo(id) if err != nil { log.Fatalln("Error requesting service info:", err) } fmt.Println(sInfo) // Ouput: Blah }
Output:
func (Host) RequestUserInfo ¶
func (host Host) RequestUserInfo() (UserDetails, error)
RequestUserInfo makes an HTTP GET to the framework server requesting the User Node information for user authenticated.
Example ¶
package main import ( "fmt" "log" "os" "github.com/openchirp/framework/rest" ) func main() { // Get parameters from environment variables frameworkUri := os.Getenv("FRAMEWORK_SERVER") id := os.Getenv("USER_ID") token := os.Getenv("USER_TOKEN") host := rest.NewHost(frameworkUri) if err := host.Login(id, token); err != nil { log.Fatalln("Error logging in:", err) } uInfo, err := host.RequestUserInfo() if err != nil { log.Fatalln("Error requesting user info:", err) } fmt.Println(uInfo) }
Output:
func (Host) ServiceCreate ¶
func (host Host) ServiceCreate( name, description string, properties map[string]string, configParams []ServiceConfigParameter, ) (ServiceNode, error)
ServiceCreate makes an HTTP POST request to the framework server in order to create a new service with
func (Host) ServiceDelete ¶
ServiceDelete makes an HTTP DELETE request to the framework server on the specified serviceID
func (Host) ServiceGet ¶
func (host Host) ServiceGet(serviceID string) (ServiceNode, error)
ServiceGet makes an HTTP GET request to the framework server in order to get the specified service information
func (Host) ServiceList ¶
func (host Host) ServiceList() ([]ServiceNode, error)
ServiceList makes an HTTP GET request to the framework server in order to get a list of all services.
func (Host) ServiceTokenDelete ¶
ServiceTokenDelete makes an HTTP DELETE request to the framework server in order to delete the security token for the service
func (Host) ServiceTokenGenerate ¶
ServiceTokenGenerate makes an HTTP POST request to the framework server in order to generate a security token for the service
func (Host) ServiceTokenRegenerate ¶
ServiceTokenRegenerate makes an HTTP PUT request to the framework server in order to regenerate a security token for the service
func (Host) ServiceUpdateConfig ¶
func (host Host) ServiceUpdateConfig( serviceID string, configParams []ServiceConfigParameter, ) (ServiceNode, error)
ServiceUpdateConfig makes an HTTP PUT request to the framework server in order to update the service's config. This function returns the new and updated ServiceNode.
func (Host) UserAll ¶
UserAll makes an HTTP GET to the framework server requesting the all user summaries
func (Host) UserCreate ¶
UserCreate requests the new user be created with the given name, email, and password
type KeyValuePair ¶
KeyValuePair represents the REST interface's internal structure for maps. This is typically just used to parse JSON from the REST interface.
func (KeyValuePair) String ¶
func (n KeyValuePair) String() string
type LocationNode ¶
type LocationNode struct { ID string `json:"id"` Name string `json:"name"` Owner Owner `json:"owner"` Children []string `json:"children"` }
LocationNode is a container for Location Node object received from the RESTful JSON interface
func (LocationNode) String ¶
func (n LocationNode) String() string
type NodeDescriptor ¶
type NodeDescriptor struct { Name string `json:"name"` ID string `json:"id"` Pubsub PubSub `json:"pubsub"` Owner Owner `json:"owner"` }
NodeDescriptor provides the common fields that Device and Service nodes share
type ServiceConfigParameter ¶
type ServiceConfigParameter struct { Name string `json:"key_name"` // The key_ is redundant Description string `json:"key_description"` Example string `json:"key_example"` Required bool `json:"key_required"` }
ServiceConfigParameter represents one required config parameter from the service's information or create service request.
func (ServiceConfigParameter) String ¶
func (n ServiceConfigParameter) String() string
type ServiceCreateRequest ¶
type ServiceCreateRequest struct { Name string `json:"name"` Description string `json:"description"` Properties map[string]string `json:"properties,omitempty"` ConfigParameters []ServiceConfigParameter `json:"config_required,omitempty"` }
ServiceCreateRequest encapsulates the data for a request to create a service
func (ServiceCreateRequest) String ¶
func (n ServiceCreateRequest) String() string
type ServiceDeviceListItem ¶
type ServiceDeviceListItem struct { Id string `json:"id"` PubSub PubSub `json:"pubsub"` Config []KeyValuePair `json:"config"` }
ServiceDeviceListItem represents the device and service configuration pair found in a Service Node's device list
func (ServiceDeviceListItem) GetConfigMap ¶
func (i ServiceDeviceListItem) GetConfigMap() map[string]string
func (ServiceDeviceListItem) GetID ¶
func (i ServiceDeviceListItem) GetID() string
func (ServiceDeviceListItem) String ¶
func (n ServiceDeviceListItem) String() string
type ServiceNode ¶
type ServiceNode struct { NodeDescriptor // Node descriptor of Service Node Pubsub ServicePubSub `json:"pubsub"` // Override NodeDescriptor.Pubsub Description string `json:"description"` Properties map[string]string `json:"properties"` ConfigParameters []ServiceConfigParameter `json:"config_required"` }
ServiceNode is a container for Service Node object received from the REST interface
func (ServiceNode) String ¶
func (n ServiceNode) String() string
type ServicePubSub ¶
type ServicePubSub struct { PubSub TopicEvents string `json:"events_endpoint"` TopicStatus string `json:"status_endpoint"` }
ServicePubSub override the normal PubSub struct to add the two additional topic related to a service
type ServiceUpdateRequest ¶
type ServiceUpdateRequest struct { Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` Properties map[string]string `json:"properties,omitempty"` ConfigParameters []ServiceConfigParameter `json:"config_required,omitempty"` }
ServiceUpdateRequest encapsulates the data for a request to update a service
type TransducerInfo ¶
type TransducerInfo struct { Name string `json:"name"` Unit string `json:"unit"` IsActuable bool `json:"is_actuable"` }
TransducerInfo describes a transducer within a Device.
type TransducerValue ¶
type TransducerValue struct { TransducerInfo Value string `json:"value"` ValueTimestamp time.Time `json:"timestamp"` }
TransducerValue holds a transducer description with a single value and timestamp.
type User ¶
type User struct { ID string `json:"id"` Name string `json:"name"` Email string `json:"email"` UserID string `json:"userid"` }
User is a container for summary User object received from the RESTful JSON interface
type UserCreateRequest ¶
type UserDetails ¶
UserDetails is a container for User info object received from the RESTful JSON interface
func (UserDetails) String ¶
func (n UserDetails) String() string