gospark

package
v0.0.0-...-154c9d6 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2014 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIVersion     = "/v1"
	BaseUrl        = "https://api.spark.io"
	MaxVariableLen = 12
)
View Source
const (
	UserName          = "YOUR_EMAIL@ADDRE.SS"
	Password          = "YOUR_PASSWORD"
	BasicAuthId       = "spark"
	BasicAuthPassword = "spark"
)

Variables

This section is empty.

Functions

func GetCompleteEndpointUrl

func GetCompleteEndpointUrl(a *APIUrl) string

func GetEndpoint

func GetEndpoint(i interface{}) string

func ParseToken

func ParseToken(i interface{}) (string, error)

Types

type APIUrl

type APIUrl struct {
	BaseUrl    string
	APIVersion string
	Endpoint   string
}

type AccessToken

type AccessToken struct {
	Token     string `json:"token"`
	ExpiresAt string `json:"expires_at"`
	Client    string `json:"client"`
}

func NewAccessToken

func NewAccessToken() *AccessToken

type AccessTokenList

type AccessTokenList struct {
	Tokens []*AccessToken
}

func NewAccessTokenList

func NewAccessTokenList() *AccessTokenList

type AccessTokenService

type AccessTokenService struct {
	OaRequest  *OAuthRequest
	AToken     *AccessToken
	ATokenList *AccessTokenList
}

AccessTokenService is an entrypoint for any AccessToken related operation.

func NewAccessTokenService

func NewAccessTokenService(username, password string) *AccessTokenService

func (*AccessTokenService) DeleteAccessToken

func (s *AccessTokenService) DeleteAccessToken(a *AccessToken) (
	*DeleteAccessTokenResponse, error)

func (*AccessTokenService) GetAccessToken

func (s *AccessTokenService) GetAccessToken() (*OAuthResponse, error)

Get returns an AccessToken in the form of a OAuthResponse object.

func (*AccessTokenService) ListAllAccessTokens

func (s *AccessTokenService) ListAllAccessTokens() error

type ApiError

type ApiError struct {
	ErrorMsg string
}

func (ApiError) Error

func (e ApiError) Error() string

type CoreInfo

type CoreInfo struct {
	LastApp   string `json:"last_app, omitempty"`
	LastHeard string `json:"last_heard, omitempty"`
	Connected bool   `json:"connected, omitempty"`
	DeviceID  string `json:"deviceID, omitempty"`
}

CoreInfo is a representation of the json struct coreInfo.

type DeleteAccessTokenResponse

type DeleteAccessTokenResponse struct {
	Status bool `json:"ok"`
}

type Device

type Device struct {
	ID        string
	Functions map[string]*DeviceFunction
	Variables map[string]*DeviceVariable
}

Device is a representation of a Spark Core.

func NewDevice

func NewDevice(id string) *Device

NewDevice is a constructor for Device.

func (*Device) GetDeviceVariable

func (d *Device) GetDeviceVariable(dVar *DeviceVariable, i interface{}) (
	*GetDeviceVariableResponse, error)

GetDeviceVariable is the method to GET the value of a particular Device Variable.

func (*Device) InvokeFunction

func (d *Device) InvokeFunction(dFunc *DeviceFunction,
	i interface{}) (*InvokeFunctionResponse, error)

InvokeFunction is used to Invoke a DeviceFunction instance.

func (*Device) NewDeviceFunction

func (d *Device) NewDeviceFunction(name string, args []string)

NewDeviceFunction is a constuctor for DeviceFunction that also links the function to a Device object.

func (*Device) NewDeviceVariable

func (d *Device) NewDeviceVariable(name string)

NewDeviceVariable is a constructor for DeviceVariable and links it to a Device object.

type DeviceFunction

type DeviceFunction struct {
	Name string
	Args []string
}

DeviceFunction is a representation of a function.

type DeviceVariable

type DeviceVariable struct {
	Name string
}

DeviceVariable is a representation of a Variable that can be associated with a device.

type ErrorResponse

type ErrorResponse struct {
	Code             int32  `json:"code, omitempty"`
	Err              string `json:"error, omitempty"`
	ErrorDescription string `json:"error_description, omitempty"`
	Info             string `json:"info, omitempty"`
}

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

type GetDeviceVariableResponse

type GetDeviceVariableResponse struct {
	Cmd  string `json:"cmd, omitempty"`
	Name string `json:"name, omitempty"`
	// Result can be a string, int, float or bool. Not the best
	// way to do this here, but I'm sorry about this. Ugly I will agree.
	Result   interface{} `json:"result, omitempty"`
	CoreInfo CoreInfo    `json:"coreInfo, omitempty"`
}

GetDeviceVariableResponse is a representation of the response received on doing a GET on a Device Variable.

type InvokeFunctionResponse

type InvokeFunctionResponse struct {
	DeviceID    string `json:"id"`
	Name        string `json:name`
	Connected   bool   `json:connected`
	ReturnValue int32  `json:connected`
}

InvokeFunctionResponse is the representation of a response when a particular function is invoked via the REST API.

type OAuthRequest

type OAuthRequest struct {
	GrantType string `json:"grant_type, omitempty"`
	UserName  string `json:"username, omitoempty"`
	Password  string `json:"password, omitempty"`
}

OAuthRequest is a struct for the body of a request to get an access token.

func NewOAuthRequest

func NewOAuthRequest(username, password string) *OAuthRequest

type OAuthResponse

type OAuthResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int64  `json:"expires_in"`
}

Jump to

Keyboard shortcuts

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