m2x-go: github.com/jsgoecke/m2x-go Index | Files | Directories

package m2x

import "github.com/jsgoecke/m2x-go"

Index

Package Files

client.go datasources.go errors.go feeds.go keys.go triggers.go

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

func ParseTriggerEvent Uses

func ParseTriggerEvent(data []byte) (map[string]interface{}, error)

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"
		}

type Batch Uses

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 Uses

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 Uses

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 Uses

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 Uses

type Client struct {
    APIBase string
    Headers map[string]string
}

Client represents a client for the M2X API (https://m2x.att.com/developer/documentation/overview)

func NewClient Uses

func NewClient(apiKey string) *Client

NewClient creates a NewClient for the M2X API

client := NewClient("<API-KEY>")

func (*Client) Batch Uses

func (c *Client) Batch(id string) (*Batch, *ErrorMessage)

Batch gets a batch

batch, err := client.Batch("1234")

func (*Client) Batches Uses

func (c *Client) Batches() (*Batches, *ErrorMessage)

Batches gets a list of batches

batches, err := client.Batches()

func (*Client) Blueprint Uses

func (c *Client) Blueprint(id string) (*Blueprint, *ErrorMessage)

Blueprint gets a blueprint

blueprint, err := client.Blueprint("1234")

func (*Client) Blueprints Uses

func (c *Client) Blueprints() (*Blueprints, *ErrorMessage)

Blueprints gets a list of blueprints

blueprints, err := client.Blueprints()

func (*Client) CreateBatch Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (c *Client) DeleteBatch(id string) (*Batch, *ErrorMessage)

DeleteBatch deletes a batch

err := client.DeleteBatch(batch.ID)

func (*Client) DeleteBlueprint Uses

func (c *Client) DeleteBlueprint(id string) *ErrorMessage

DeleteBlueprint deletes a blueprint

err := client.DeleteBlueprint(blueprint.ID)

func (*Client) DeleteKey Uses

func (c *Client) DeleteKey(id string) *ErrorMessage

DeleteKey deletes a key

err := client.DeleteKey("1234")

func (*Client) DeleteTrigger Uses

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 Uses

func (c *Client) Feed(resource string) (*Feed, *ErrorMessage)

Feed gets a feed

feed, err := client.Feed("/feeds/1234")

func (*Client) FeedLocation Uses

func (c *Client) FeedLocation(resource string) (*Location, *ErrorMessage)

FeedLocation gets a feed location

feed, err := client.FeedLocation("/feeds/1234")

func (*Client) FeedStream Uses

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 Uses

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 Uses

func (c *Client) Feeds() (*Feeds, *ErrorMessage)

Feeds gets a list of feeds

feeds, err := client.Feeds()

func (*Client) Key Uses

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 Uses

func (c *Client) Keys() (*Blueprints, *ErrorMessage)

Keys gets a list of keys from the /keys resource

keys, err := client.Keys()

func (*Client) RequestLog Uses

func (c *Client) RequestLog(resource string) (*Requests, *ErrorMessage)

RequestLog requests a log

requests, err := RequestLog("/feeds/1234")

func (*Client) Status Uses

func (c *Client) Status() (*Status, error)

Status gets the status of the M2X client

result, err := client.Status()

func (*Client) TestTrigger Uses

func (c *Client) TestTrigger(resource string, name string) *ErrorMessage

TestTrigger tests a trigger

err := client.TestTrigger("/feeds/1234", "foobar")

func (*Client) Trigger Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

type Datasource struct {
    Total        int `json:"total"`
    Registered   int `json:"registered"`
    Unregistered int `json:"unregistered"`
}

Datasource represents a single datasource

type Error Uses

type Error struct {
    Name []string `json:"name"`
}

Error is the simple error message

type ErrorMessage Uses

type ErrorMessage struct {
    Message    string `json:"message"`
    StatusCode int
    Errors     Error `json:"errors"`
    Error      error
}

ErrorMessage represents an API error message

type Feed Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

type Requests struct {
    Requests []Request
}

Requests represents a collection of request

type Status Uses

type Status struct {
    API      string `json:"api"`
    Triggers string `json:"triggers"`
}

Status represents a status returned by the /status resource

type Stream Uses

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 Uses

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 Uses

type Triggers struct {
    Triggers []Trigger
}

Triggers represents a collection of triggers (https://m2x.att.com/developer/documentation/feed#List-Triggers)

type Unit Uses

type Unit struct {
    Label  string `json:"label"`
    Symbol string `json:"symbol"`
}

Unit represents a request

type Value Uses

type Value struct {
    At    string `json:"at"`
    Value string `json:"value"`
}

Value represents a value

type Values Uses

type Values struct {
    Start  string `json:"start"`
    End    string `json:"end"`
    Limit  int    `json:"limit"`
    Values []Value
}

Values represents a collection of values

type Waypoint Uses

type Waypoint struct {
    Timestamp string `json:"timestamp"`
    Latitude  string `json:"latitude"`
    Longitude string `json:"longitude"`
    Elevation string `json:"elevation"`
}

Waypoint represents a waypoint

Directories

PathSynopsis
examples

Package m2x imports 5 packages (graph) and is imported by 1 packages. Updated 2016-07-29. Refresh now. Tools for package owners.