spark

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2014 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

This spark client is heavily inspired by https://github.com/google/go-github The Github client is distributed under the BSD-style license found at:

https://github.com/google/go-github/blob/master/LICENSE

Due to a lack of exhaustive API documentation on http://docs.spark.io some error responses might not match the current ErrorResponse implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

Types

type AccessToken

type AccessToken struct {
	Value     string `json:"access_token,omitempty"`
	Type      string `json:"token_type,omitempty"`
	ExpiresIn uint32 `json:"expires_in,omitempty"`
}

func (AccessToken) String

func (a AccessToken) String() string

type DebugConsole

type DebugConsole struct {
}

type Device

type Device struct {
	Name      string `json:"name,omitempty"`
	Id        string `json:"id,omitempty"`
	LastApp   string `json:"last_app,omitempty"`
	LastHeard string `json:"last_heard,omitempty"`
	Connected bool   `json:"connected, omitempty"`
}

func (Device) String

func (d Device) String() string

type DevicesService

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

func (*DevicesService) Claim

func (s *DevicesService) Claim(coredId string) (*http.Response, error)

func (*DevicesService) Exec

func (s *DevicesService) Exec(coreId, funcName, params string) (ExecResponse, *http.Response, error)

func (*DevicesService) Info

func (s *DevicesService) Info(coreId string) (Info, *http.Response, error)

func (*DevicesService) List

func (s *DevicesService) List() ([]Device, *http.Response, error)

func (*DevicesService) Read

func (s *DevicesService) Read(coreId, varName string) (ReadResponse, *http.Response, error)

func (*DevicesService) Rename

func (s *DevicesService) Rename(coreId, name string) (*http.Response, error)

type Error

type Error struct {
	Description string `json:"error_description"` // resource on which the error occurred
	ErrorString string `json:"error"`             // field on which the error occurred
	Code        int32  `json:"code"`              // validation error code
}

func (*Error) Error

func (e *Error) Error() string

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error
	Message  string         `json:"message"` // error message
	Errors   []Error        `json:"errors"`  // more detail on individual errors
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type ExecResponse

type ExecResponse struct {
	Device
	ReturnValue int `json:"return_value,omitempty"`
}

type Info

type Info struct {
	Name      string            `json:"name,omitempty"`
	Id        string            `json:"id,omitempty"`
	Variables map[string]string `json:"variables,omitempty"`
	Functions []string          `json:"functions,omitempty"`
}

type ReadResponse

type ReadResponse struct {
	Device  Device `json:"coreInfo,omitempty"`
	Command string
	Name    string
	Result  interface{}
}

type SparkClient

type SparkClient struct {

	// Base URL for API requests.  Defaults to the public Spark cloud API, but can be
	// set to a domain endpoint to use with hosted cloud platform.  BaseURL should
	// always be specified with a trailing slash.
	BaseURL *url.URL

	// User agent used when communicating with the Spark.io API.
	UserAgent string
	AuthToken string

	// Services used for talking to different parts of the Spark cloud API.
	Devices *DevicesService
	Tokens  *TokensService
	// contains filtered or unexported fields
}

A SparkClient manages communication with the Spark API.

func NewClient

func NewClient(httpClient *http.Client, timeout time.Duration) *SparkClient

NewClient returns a new Spark API client. If a nil httpClient is provided, http.DefaultClient will be used. To use API methods which require authentication, provide an http.Client that will perform the authentication for you (such as that provided by the goauth2 library).

func (*SparkClient) Do

func (c *SparkClient) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

func (*SparkClient) NewRequest

func (c *SparkClient) NewRequest(method, urlStr string, body io.Reader) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the SparkClient. Relative URLs should always be specified without a preceding slash.

type Token

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

func (Token) String

func (t Token) String() string

type TokensService

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

func (*TokensService) Delete

func (s *TokensService) Delete(token, username, password string) (*http.Response, error)

func (*TokensService) List

func (s *TokensService) List(username, password string) ([]Token, *http.Response, error)

func (*TokensService) Login

func (s *TokensService) Login(username, password string) (AccessToken, *http.Response, error)

Jump to

Keyboard shortcuts

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