Documentation ¶
Index ¶
- Constants
- Variables
- func ParseTriggerEvent(data []byte) (map[string]interface{}, error)
- type Batch
- type Batches
- type Blueprint
- type Blueprints
- type Client
- func (c *Client) Batch(id string) (*Batch, *ErrorMessage)
- func (c *Client) Batches() (*Batches, *ErrorMessage)
- func (c *Client) Blueprint(id string) (*Blueprint, *ErrorMessage)
- func (c *Client) Blueprints() (*Blueprints, *ErrorMessage)
- func (c *Client) CreateBatch(batch map[string]string) (*Batch, *ErrorMessage)
- func (c *Client) CreateBlueprint(blueprint map[string]string) (*Blueprint, *ErrorMessage)
- func (c *Client) CreateKey(key map[string]interface{}) (*Key, *ErrorMessage)
- func (c *Client) CreateTrigger(resource string, trigger map[string]string) (*Trigger, *ErrorMessage)
- func (c *Client) DeleteBatch(id string) (*Batch, *ErrorMessage)
- func (c *Client) DeleteBlueprint(id string) *ErrorMessage
- func (c *Client) DeleteKey(id string) *ErrorMessage
- func (c *Client) DeleteTrigger(resource string, id string) *ErrorMessage
- func (c *Client) Feed(resource string) (*Feed, *ErrorMessage)
- func (c *Client) FeedLocation(resource string) (*Location, *ErrorMessage)
- func (c *Client) FeedStream(resource string, name string) (*Stream, *ErrorMessage)
- func (c *Client) FeedStreamValues(resource string, name string) (*Values, *ErrorMessage)
- func (c *Client) Feeds() (*Feeds, *ErrorMessage)
- func (c *Client) Key(id string) (*Key, *ErrorMessage)
- func (c *Client) Keys() (*Blueprints, *ErrorMessage)
- func (c *Client) RequestLog(resource string) (*Requests, *ErrorMessage)
- func (c *Client) Status() (*Status, error)
- func (c *Client) TestTrigger(resource string, name string) *ErrorMessage
- func (c *Client) Trigger(resource string, id string) (*Trigger, *ErrorMessage)
- func (c *Client) Triggers(resource string) (*Triggers, *ErrorMessage)
- func (c *Client) UpdateBatch(id string, updateData map[string]string) *ErrorMessage
- func (c *Client) UpdateBlueprint(id string, updateData map[string]string) *ErrorMessage
- func (c *Client) UpdateFeedLocation(resource string, updateData map[string]interface{}) *ErrorMessage
- func (c *Client) UpdateFeedStream(resource string, name string, updateData map[string]interface{}) *ErrorMessage
- func (c *Client) UpdateFeedStreamValues(resource string, name string, updateData map[string]interface{}) *ErrorMessage
- func (c *Client) UpdateKey(id string, updateData map[string]interface{}) *ErrorMessage
- func (c *Client) UpdateTrigger(resource string, id string, updateData map[string]string) *ErrorMessage
- type Datasource
- type Error
- type ErrorMessage
- type Feed
- type Feeds
- type Key
- type Keys
- type Location
- type Request
- type Requests
- type Status
- type Stream
- type Trigger
- type Triggers
- type Unit
- type Value
- type Values
- type Waypoint
Constants ¶
const ( // UserAgent represents the value of the HTTP user agent UserAgent = "M2X/1 (Go net/http)" // Version of the library Version = "0.3" )
Variables ¶
var APIKey string
APIKey is the key for the API
Functions ¶
func ParseTriggerEvent ¶
ParseTriggerEvent parses the JSON for an event returned by a trigger Due to inconsistent types returned, using a Map (http://forum-m2x.att.com/47j-triggers-not-firing-but-work-on-test#post14953) instead of a struct. If resolved, may change back later.
triggerEvent := m2x.ParseTriggerEvent(body)
JSON POSTed:
{ "feed_id":"12345", "stream":"call", "trigger_name":"OffCall", "trigger_description":"call < 1", "condition":"<", "threshold":"1", "value":"0", "at":"2014-01-13T14:35:23Z" }
Types ¶
type Batch ¶
type Batch struct { ID string `json:"id"` Name string `json:"name"` Description string `json:"description"` Visibility string `json:"visibility"` Serial string `json:"serial"` Status string `json:"status"` Feed string `json:"feed"` URL string `json:"url"` Key string `json:"key"` Tags []string `json:"tags"` Created string `json:"created"` Updated string `json:"updated"` Datasources Datasource `json:"datasources"` }
Batch represents a single batch
type Batches ¶
type Batches struct { Batches []Batch `json:"batches"` Total int `json:"total"` Pages int `json:"pages"` Limit int `json:"limit"` CurrentPage int `json:"current_page"` }
Batches represents a collection of batches
type Blueprint ¶
type Blueprint struct { ID string `json:"id"` Name string `json:"name"` Description string `json:"description"` Visibility string `json:"visibility"` Serial string `json:"serial"` Status string `json:"status"` Feed string `json:"feed"` URL string `json:"url"` Key string `json:"key"` Tags []string `json:"tags"` Created string `json:"created"` Updated string `json:"updated"` Datasources Datasource `json:"datasources"` }
Blueprint represents a single blueprint
type Blueprints ¶
type Blueprints struct { Blueprints []Blueprint `json:"blueprints"` Total int `json:"total"` Pages int `json:"pages"` Limit int `json:"limit"` CurrentPage int `json:"current_page"` }
Blueprints represents a collection of blueprints (https://m2x.att.com/developer/documentation/datasource)
type Client ¶
Client represents a client for the M2X API (https://m2x.att.com/developer/documentation/overview)
func (*Client) Batch ¶
func (c *Client) Batch(id string) (*Batch, *ErrorMessage)
Batch gets a batch
batch, err := client.Batch("1234")
func (*Client) Batches ¶
func (c *Client) Batches() (*Batches, *ErrorMessage)
Batches gets a list of batches
batches, err := client.Batches()
func (*Client) Blueprint ¶
func (c *Client) Blueprint(id string) (*Blueprint, *ErrorMessage)
Blueprint gets a blueprint
blueprint, err := client.Blueprint("1234")
func (*Client) Blueprints ¶
func (c *Client) Blueprints() (*Blueprints, *ErrorMessage)
Blueprints gets a list of blueprints
blueprints, err := client.Blueprints()
func (*Client) CreateBatch ¶
func (c *Client) CreateBatch(batch map[string]string) (*Batch, *ErrorMessage)
CreateBatch creates a new batch
batchData := make(map[string]string) batchData["name"] = "Go Batch" batchData["description"] = "A batch for the Go lib for M2X" batchData["visibility"] = "private" batch, err := client.CreateBatch(batch)
func (*Client) CreateBlueprint ¶
func (c *Client) CreateBlueprint(blueprint map[string]string) (*Blueprint, *ErrorMessage)
CreateBlueprint creates a new blueprint
blueprintData := make(map[string]string) blueprintData["name"] = "Go Blueprint" blueprintData["description"] = "A blueprint for the Go lib for M2X" blueprintData["visibility"] = "private" blueprint, err := client.CreateBlueprint(blueprintData)
func (*Client) CreateKey ¶
func (c *Client) CreateKey(key map[string]interface{}) (*Key, *ErrorMessage)
CreateKey creates a key
keyData := make(map[string]interface{}) name := "Go Created Key" keyData["name"] = name keyData["permissions"] = [...]string{"GET", "PUT"} key, err := client.CreateKey(keyData)
func (*Client) CreateTrigger ¶
func (c *Client) CreateTrigger(resource string, trigger map[string]string) (*Trigger, *ErrorMessage)
CreateTrigger creates a trigger on a feed stream
triggerData := make(map[string]string) triggerData["name"] = "foobar" triggerData["stream"] = "temperature" triggerData["condition"] = ">" triggerData["value"] = "30" triggerData["callback_url"] = "http://45bad07a.ngrok.com/streamEvent" triggerData["status"] = "enabled" trigger, err := client.CreateTrigger(blueprint.Feed, triggerData)
func (*Client) DeleteBatch ¶
func (c *Client) DeleteBatch(id string) (*Batch, *ErrorMessage)
DeleteBatch deletes a batch
err := client.DeleteBatch(batch.ID)
func (*Client) DeleteBlueprint ¶
func (c *Client) DeleteBlueprint(id string) *ErrorMessage
DeleteBlueprint deletes a blueprint
err := client.DeleteBlueprint(blueprint.ID)
func (*Client) DeleteKey ¶
func (c *Client) DeleteKey(id string) *ErrorMessage
DeleteKey deletes a key
err := client.DeleteKey("1234")
func (*Client) DeleteTrigger ¶
func (c *Client) DeleteTrigger(resource string, id string) *ErrorMessage
DeleteTrigger deletes a trigger from a feed stream
err := client.DeleteTrigger("/feeds/1234", "1235")
func (*Client) Feed ¶
func (c *Client) Feed(resource string) (*Feed, *ErrorMessage)
Feed gets a feed
feed, err := client.Feed("/feeds/1234")
func (*Client) FeedLocation ¶
func (c *Client) FeedLocation(resource string) (*Location, *ErrorMessage)
FeedLocation gets a feed location
feed, err := client.FeedLocation("/feeds/1234")
func (*Client) FeedStream ¶
func (c *Client) FeedStream(resource string, name string) (*Stream, *ErrorMessage)
FeedStream list a feed stream
stream, err := client.FeedStream("/feeds/1234", "temperature")
func (*Client) FeedStreamValues ¶
func (c *Client) FeedStreamValues(resource string, name string) (*Values, *ErrorMessage)
FeedStreamValues list the feeds stream values
values, err := client.FeedStreamValues("/feeds/1234", "temperature")
func (*Client) Feeds ¶
func (c *Client) Feeds() (*Feeds, *ErrorMessage)
Feeds gets a list of feeds
feeds, err := client.Feeds()
func (*Client) Key ¶
func (c *Client) Key(id string) (*Key, *ErrorMessage)
Key gets a list of blueprints from the /key resource
key, err := client.Key()
func (*Client) Keys ¶
func (c *Client) Keys() (*Blueprints, *ErrorMessage)
Keys gets a list of keys from the /keys resource
keys, err := client.Keys()
func (*Client) RequestLog ¶
func (c *Client) RequestLog(resource string) (*Requests, *ErrorMessage)
RequestLog requests a log
requests, err := RequestLog("/feeds/1234")
func (*Client) TestTrigger ¶
func (c *Client) TestTrigger(resource string, name string) *ErrorMessage
TestTrigger tests a trigger
err := client.TestTrigger("/feeds/1234", "foobar")
func (*Client) Trigger ¶
func (c *Client) Trigger(resource string, id string) (*Trigger, *ErrorMessage)
Trigger lists a trigger on a feed stream
trigger, err := client.Trigger("/feeds/1234", "1235")
func (*Client) Triggers ¶
func (c *Client) Triggers(resource string) (*Triggers, *ErrorMessage)
Triggers lists a collection of triggers on a feed stream
triggers, err := client.Triggers()
func (*Client) UpdateBatch ¶
func (c *Client) UpdateBatch(id string, updateData map[string]string) *ErrorMessage
UpdateBatch updates a batch
batchData["description"] = "A batch for the Go lib for AT&T M2X" err := client.UpdateBatch(batch.ID, batchData)
func (*Client) UpdateBlueprint ¶
func (c *Client) UpdateBlueprint(id string, updateData map[string]string) *ErrorMessage
UpdateBlueprint updates a blueprint
blueprintData["description"] = "A blueprint for the Go lib for AT&T M2X" err := client.UpdateBlueprint(blueprint.ID, blueprintData)
func (*Client) UpdateFeedLocation ¶
func (c *Client) UpdateFeedLocation(resource string, updateData map[string]interface{}) *ErrorMessage
UpdateFeedLocation create/Update a feed location
loc := make(map[string]interface{}) loc["name"] = "Storage Room in Sevilla, Spain" loc["latitude"] = "37.383055" loc["longitude"] = "-5.996392" loc["elevation"] = "5" err := client.UpdateFeedLocation("/feeds/1234", loc)
func (*Client) UpdateFeedStream ¶
func (c *Client) UpdateFeedStream(resource string, name string, updateData map[string]interface{}) *ErrorMessage
UpdateFeedStream update a feed stream
streamData := make(map[string]interface{}) unit := make(map[string]string) unit["label"] = "celcius" unit["symbol"] = "C" streamData["unit"] = unit err := client.UpdateFeedStream("/feeds/1234", "temperature", streamData)
func (*Client) UpdateFeedStreamValues ¶
func (c *Client) UpdateFeedStreamValues(resource string, name string, updateData map[string]interface{}) *ErrorMessage
UpdateFeedStreamValues update feeds stream values
values := make(map[string]interface{}) values["values"] = []*m2x.Value{ {"2013-09-09T19:15:00Z", "32"}, {"2013-09-09T19:16:00Z", "28 "}, {"2013-09-09T19:17:00Z", "25"}, {"2013-09-09T19:17:00Z", "40"}, } err := client.UpdateFeedStreamValues("/feeds/1234", "temperature", values)
func (*Client) UpdateKey ¶
func (c *Client) UpdateKey(id string, updateData map[string]interface{}) *ErrorMessage
UpdateKey updates a key
keyData["name"] = "Go key" err := client.UpdateKey("/feeds/1234", keyData)
func (*Client) UpdateTrigger ¶
func (c *Client) UpdateTrigger(resource string, id string, updateData map[string]string) *ErrorMessage
UpdateTrigger updates a trigger on a feed stream
triggerData["callback_url"] = "http://host.com/streamEvent" triggerData["status"] = "disabled" err := client.UpdateTrigger("/feeds/1234", "1235", triggerData)
type Datasource ¶
type Datasource struct { Total int `json:"total"` Registered int `json:"registered"` Unregistered int `json:"unregistered"` }
Datasource represents a single datasource
type ErrorMessage ¶
type ErrorMessage struct { Message string `json:"message"` StatusCode int Errors Error `json:"errors"` Error error }
ErrorMessage represents an API error message
type Feed ¶
type Feed struct { ID string `json:"id"` Name string `json:"name"` Description string `json:"description"` Visibility string `json:"visibility"` Status string `json:"status"` Type string `json:"type"` Tags []string `json:"tags"` URL string `json:"url"` Key string `json:"key"` Created string `json:"created"` Updated string `json:"updated"` Location Location `json:"location"` Streams []Stream `json:"streams"` Triggers []Trigger `json:"triggers"` }
Feed represents an individual feed
type Feeds ¶
type Feeds struct { Feeds []Feed `json:"feeds"` Total int `json:"total"` Pages int `json:"pages"` Limit int `json:"limit"` CurrentPage int `json:"current_page"` }
Feeds represents a collection of feeds resource (https://m2x.att.com/developer/documentation/feed)
type Key ¶
type Key struct { ID string `json:"id"` Name string `json:"name"` Key string `json:"key"` Master bool `json:"master"` Feed string `json:"feed"` Stream string `json:"stream"` ExpiresAt string `json:"expires_at"` Expired string `json:"expired"` Permissions []string `json:"permissions"` }
Key represents a single Key
type Keys ¶
type Keys struct { Keys []Key `json:"keys"` Total int `json:"total"` Pages int `json:"pages"` Limit int `json:"limit"` CurrentPage int `json:"current_page"` }
Keys represents a Keys response from the M2X API (https://m2x.att.com/developer/documentation/keys)
type Location ¶
type Location struct { Name string `json:"name"` Latitude string `json:"latitude"` Longitude string `json:"longitude"` Elevation string `json:"elevation"` Waypoints []Waypoint `json:"waypoints"` }
Location represents a location
type Request ¶
type Request struct { At string `json:"at"` Status int `json:"status"` Method string `json:"method"` Path string `json:"path"` }
Request represents a request
type Requests ¶
type Requests struct {
Requests []Request
}
Requests represents a collection of request
type Stream ¶
type Stream struct { Name string `json:"name"` Value interface{} `json:"value"` Min interface{} `json:"min"` Max interface{} `json:"max"` Unit Unit `json:"unit"` URL string `json:"url"` Created string `json:"created"` Updated string `json:"updated"` }
Stream represents a tream
type Trigger ¶
type Trigger struct { ID string `json:"id"` Name string `json:"name"` Stream string `json:"stream"` Condition string `json:"condition"` Value string `json:"value"` CallbackURL string `json:"callback_url"` URL string `json:"url"` Status string `json:"status"` Created string `json:"created"` Updated string `json:"updated"` }
Trigger represents a trigger
type Triggers ¶
type Triggers struct {
Triggers []Trigger
}
Triggers represents a collection of triggers (https://m2x.att.com/developer/documentation/feed#List-Triggers)