framework: github.com/openchirp/framework/rest Index | Examples | Files

package rest

import "github.com/openchirp/framework/rest"

Package rest provides the data structures and primitive mechanisms for representing and communicating framework constructs with the RESTful server.

Index

Examples

Package Files

check.go device.go group.go importpath.go location.go rest.go service.go user.go

func DecodeOCError Uses

func DecodeOCError(resp *http.Response) error

type DeviceListServiceItem Uses

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 Uses

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 Uses

func (n *DeviceNode) Clone() DeviceNode

Clone creates a new copy of the DeviceNode. This is necessary because a DeviceNode has embedded slices.

type Group Uses

type Group struct {
    ID   string `json:"id"`
    Name string `json:"name"`
}

Group is a container for the minimal group summary

type GroupCreateRequest Uses

type GroupCreateRequest struct {
    Name string `json:"name"`
}

GroupCreateRequest is the container for the request to create a new group

type GroupNode Uses

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

func (GroupNode) String Uses

func (n GroupNode) String() string

type HealthCheckResponse Uses

type HealthCheckResponse struct {
    Status HealthStatus `json:"status"`
}

HealthCheckResponse encapsulates the response from the server health check

type HealthStatus Uses

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 Uses

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

Host represents the RESTful HTTP server that hosts the framework

func NewHost Uses

func NewHost(uri string) Host

NewHost returns an object referencing the framework server

Code:

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)

func (Host) DelinkService Uses

func (host Host) DelinkService(deviceID, serviceID string) error

DelinkService makes an HTTP DELETE to the framework server to delink the specified serviceID from device deviceID.

func (Host) DeviceAll Uses

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 Uses

func (host Host) DeviceTransducerLastValue(deviceID, transducerID string) ([]byte, error)

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 Uses

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 Uses

func (host Host) ExecuteCommand(deviceID, commandID string) error

ExecuteCommand makes an HTTP POST to the framework server to execute the specified commandID on device deviceID.

func (Host) GroupAll Uses

func (host Host) GroupAll() ([]Group, error)

GroupAll fetches a list of all groups

func (Host) GroupCreate Uses

func (host Host) GroupCreate(name string) error

GroupCreate requests for a new group to be created with the given name

func (Host) HealthCheck Uses

func (host Host) HealthCheck() (HealthStatus, error)

HealthCheck requests the health of the rest server

func (Host) LinkService Uses

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) Login Uses

func (host *Host) Login(username, password string) error

func (Host) RequestDeviceInfo Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (host Host) RequestServiceDeviceList(serviceID string) ([]ServiceDeviceListItem, error)

RequestServiceDeviceList

func (Host) RequestServiceInfo Uses

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.

Code:

// 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

func (Host) RequestUserInfo Uses

func (host Host) RequestUserInfo() (UserDetails, error)

RequestUserInfo makes an HTTP GET to the framework server requesting the User Node information for user authenticated.

Code:

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

func (Host) ServiceCreate Uses

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 Uses

func (host Host) ServiceDelete(serviceID string) error

ServiceDelete makes an HTTP DELETE request to the framework server on the specified serviceID

func (Host) ServiceGet Uses

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 Uses

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 Uses

func (host Host) ServiceTokenDelete(serviceID string) error

ServiceTokenDelete makes an HTTP DELETE request to the framework server in order to delete the security token for the service

func (Host) ServiceTokenGenerate Uses

func (host Host) ServiceTokenGenerate(serviceID string) (string, error)

ServiceTokenGenerate makes an HTTP POST request to the framework server in order to generate a security token for the service

func (Host) ServiceTokenRegenerate Uses

func (host Host) ServiceTokenRegenerate(serviceID string) (string, error)

ServiceTokenRegenerate makes an HTTP PUT request to the framework server in order to regenerate a security token for the service

func (Host) ServiceUpdateConfig Uses

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 Uses

func (host Host) UserAll() ([]User, error)

UserAll makes an HTTP GET to the framework server requesting the all user summaries

func (Host) UserCreate Uses

func (host Host) UserCreate(email, name, password string) error

UserCreate requests the new user be created with the given name, email, and password

type KeyValuePair Uses

type KeyValuePair struct {
    Key   string `json:"key"`
    Value string `json:"value"`
}

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 Uses

func (n KeyValuePair) String() string

type LocationNode Uses

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 Uses

func (n LocationNode) String() string

type NodeDescriptor Uses

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 Owner Uses

type Owner struct {
    Id    string `json:"id"`
    Name  string `json:"name"`
    Email string `json:"email"`
}

Owner describes the owning user's details

type PubSub Uses

type PubSub struct {
    Protocol string `json:"protocol"`
    Topic    string `json:"endpoint"`
}

PubSub describes a node's pubsub endpoint

type ServiceConfigParameter Uses

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 Uses

func (n ServiceConfigParameter) String() string

type ServiceCreateRequest Uses

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 Uses

func (n ServiceCreateRequest) String() string

type ServiceDeviceListItem Uses

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 Uses

func (i ServiceDeviceListItem) GetConfigMap() map[string]string

func (ServiceDeviceListItem) GetID Uses

func (i ServiceDeviceListItem) GetID() string

func (ServiceDeviceListItem) String Uses

func (n ServiceDeviceListItem) String() string

type ServiceNode Uses

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 Uses

func (n ServiceNode) String() string

type ServicePubSub Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

func (User) String Uses

func (n User) String() string

type UserCreateRequest Uses

type UserCreateRequest struct {
    Email    string `json:"email"`
    Name     string `json:"name,omitempty"`
    Password string `json:"password"`
}

type UserDetails Uses

type UserDetails struct {
    User
    Groups []GroupNode `json:"groups"`
}

UserDetails is a container for User info object received from the RESTful JSON interface

func (UserDetails) String Uses

func (n UserDetails) String() string

Package rest imports 6 packages (graph) and is imported by 3 packages. Updated 2019-03-07. Refresh now. Tools for package owners.