m2x 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -3
- data/lib/m2x/feeds.rb +86 -35
- data/lib/m2x/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f74e6a48a81266d9c0d7c858bf18fcb3d5d96ea
|
4
|
+
data.tar.gz: 25540ed2233d2319e9cc78df0c26272ebac9f0b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88aea446e4d01ae4241e82ef4aeb577e2ac2afd09bcead9605ed7b676eea453c0436732b6c23c017693489e38263515c38780ad2dba9a074d8b23fcc9b0fab49
|
7
|
+
data.tar.gz: 100c2850c65b7cb94c3a20005e8c5ce1968352838710fac14151b573cbc2a1599d45c9d6bf03fabf187d2e0cdc07e9d8e3c64f4b3df56a344c4a7b9766793fe8
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[AT&T’s M2X](https://m2x.att.com/) is a cloud-based fully managed data storage service for network connected machine-to-machine (M2M) devices. From trucks and turbines to vending machines and freight containers, M2X enables the devices that power your business to connect and share valuable data.
|
4
4
|
|
5
|
-
This
|
5
|
+
This library aims to provide a simple wrapper to interact with [AT&T M2X API](https://m2x.att.com/developer/documentation/overview). Refer to the [Glossary of Terms](https://m2x.att.com/developer/documentation/glossary) to understand the nomenclature used through this documentation.
|
6
6
|
|
7
7
|
|
8
8
|
Getting Started
|
@@ -12,10 +12,51 @@ Getting Started
|
|
12
12
|
2. Create your first [Data Source Blueprint](https://m2x.att.com/blueprints) and copy its _Feed ID_.
|
13
13
|
3. Review the [M2X API Documentation](https://m2x.att.com/developer/documentation/overview).
|
14
14
|
|
15
|
+
## Installation
|
15
16
|
|
16
|
-
|
17
|
+
```bash
|
18
|
+
$ gem install m2x
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In order to communicate with the M2X API, you need an instance of [M2X](lib/m2x.rb). You need to pass your API key in the constructor to access your data.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
m2x = M2X.new(<YOUR-API-KEY>)
|
27
|
+
```
|
28
|
+
|
29
|
+
This provides an interface to your data on M2X
|
30
|
+
|
31
|
+
- [Blueprints](lib/m2x/blueprints.rb)
|
32
|
+
```ruby
|
33
|
+
blueprints_api = m2x.blueprints
|
34
|
+
```
|
35
|
+
|
36
|
+
- [Batches](lib/m2x/batches.rb)
|
37
|
+
```ruby
|
38
|
+
batches_api = m2x.batches
|
39
|
+
```
|
40
|
+
- [Datasources](lib/m2x/datasources.rb)
|
41
|
+
```ruby
|
42
|
+
datasources_api = m2x.datasources
|
43
|
+
```
|
44
|
+
|
45
|
+
- [Feeds](lib/m2x/feeds.rb)
|
46
|
+
```ruby
|
47
|
+
feeds_api = m2x.feeds
|
48
|
+
```
|
49
|
+
|
50
|
+
- [Keys](lib/m2x/keys.rb)
|
51
|
+
```ruby
|
52
|
+
keys_api = m2x.keys
|
53
|
+
```
|
54
|
+
|
55
|
+
Refer to the documentation on each class for further usage instructions.
|
56
|
+
|
57
|
+
## Example
|
17
58
|
|
18
|
-
In order to
|
59
|
+
In order to run this example, you will need a `Feed ID` and `API Key`. If you don't have any, access your M2X account, create a new [Data Source Blueprint](https://m2x.att.com/blueprints), and copy the `Feed ID` and `API Key` values. The following script will send your CPU load average to three different streams named `load_1m`, `load_5m` and `load_15`. Check that there's no need to create a stream in order to write values into it:
|
19
60
|
|
20
61
|
```ruby
|
21
62
|
#! /usr/bin/env ruby
|
data/lib/m2x/feeds.rb
CHANGED
@@ -10,20 +10,20 @@ class M2X
|
|
10
10
|
@client = client
|
11
11
|
end
|
12
12
|
|
13
|
+
# Search the catalog of public feeds. This allows unauthenticated
|
14
|
+
# users to search feeds from other users that has been marked as
|
15
|
+
# public, allowing only to read their metadata, locations, list
|
16
|
+
# its streams, view each stream metadata and its values.
|
17
|
+
#
|
18
|
+
# Refer to the feed documentation for the full list of supported parameters
|
19
|
+
def catalog(params={})
|
20
|
+
@client.get("/feeds/catalog", params)
|
21
|
+
end
|
22
|
+
|
13
23
|
# List/search all the feeds that belong to the user associated
|
14
24
|
# with the M2X API key supplied when initializing M2X
|
15
25
|
#
|
16
|
-
#
|
17
|
-
# following optional parameters:
|
18
|
-
#
|
19
|
-
# * `q` text to search, matching the name and description.
|
20
|
-
# * `type` one of `bleuprint`, `batch` and `datasource`.
|
21
|
-
# * `tags` a comma separated list of tags.
|
22
|
-
# * `limit` how many results per page.
|
23
|
-
# * `page` the specific results page, starting by 1.
|
24
|
-
# * `latitude` and `longitude` for searching feeds geographically.
|
25
|
-
# * `distance` numeric value in `distance_unit`.
|
26
|
-
# * `distance_unit` either `miles`, `mi` or `km`.
|
26
|
+
# Refer to the feed documentation for the full list of supported parameters
|
27
27
|
def list(params={})
|
28
28
|
@client.get("/feeds", params)
|
29
29
|
end
|
@@ -62,6 +62,20 @@ class M2X
|
|
62
62
|
@client.get("/feeds/#{URI.encode(id)}/streams/#{URI.encode(name)}")
|
63
63
|
end
|
64
64
|
|
65
|
+
# Update stream's properties
|
66
|
+
#
|
67
|
+
# If the stream doesn't exist it will create it. See
|
68
|
+
# https://m2x.att.com/developer/documentation/feed#Create-Update-Data-Stream
|
69
|
+
# for details.
|
70
|
+
def update_stream(id, name, params={})
|
71
|
+
@client.put("/feeds/#{URI.encode(id)}/streams/#{URI.encode(name)}", {}, params)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Delete the stream (and all its values) from the feed
|
75
|
+
def delete_stream(id, name)
|
76
|
+
@client.delete("/feeds/#{URI.encode(id)}/streams/#{URI.encode(name)}")
|
77
|
+
end
|
78
|
+
|
65
79
|
# List values from an existing data stream associated with a
|
66
80
|
# specific feed, sorted in reverse chronological order (most
|
67
81
|
# recent values first).
|
@@ -80,36 +94,58 @@ class M2X
|
|
80
94
|
@client.get("/feeds/#{URI.encode(id)}/streams/#{URI.encode(name)}/values", params)
|
81
95
|
end
|
82
96
|
|
83
|
-
#
|
97
|
+
# Sample values from an existing data stream associated with a specific
|
98
|
+
# feed, sorted in reverse chronological order (most recent values first).
|
84
99
|
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
# for
|
88
|
-
def
|
89
|
-
@client.
|
100
|
+
# This method only works for numeric streams
|
101
|
+
#
|
102
|
+
# Refer to the sampling endpoint documentation for allowed parameters
|
103
|
+
def stream_sampling(id, name, params={})
|
104
|
+
@client.get("/feeds/#{URI.encode(id)}/streams/#{URI.encode(name)}/sampling", params)
|
90
105
|
end
|
91
106
|
|
92
|
-
#
|
93
|
-
|
94
|
-
|
107
|
+
# Return count, min, max, average and standard deviation stats for the
|
108
|
+
# values on an existing data stream.
|
109
|
+
#
|
110
|
+
# This method only works for numeric streams
|
111
|
+
#
|
112
|
+
# Refer to the stats endpoint documentation for allowed parameters
|
113
|
+
def stream_stats(id, name, params={})
|
114
|
+
@client.get("/feeds/#{URI.encode(id)}/streams/#{URI.encode(name)}/stats", params)
|
95
115
|
end
|
96
116
|
|
97
|
-
#
|
98
|
-
|
99
|
-
|
117
|
+
# Update the current value of the specified stream. The timestamp
|
118
|
+
# is optional. If ommited, the current server time will be used
|
119
|
+
def update_stream_value(id, name, value, timestamp=nil)
|
120
|
+
params = { value: value }
|
121
|
+
|
122
|
+
params[:at] = timestamp if timestamp
|
123
|
+
|
124
|
+
@client.put("/feeds/#{URI.encode(id)}/streams/#{URI.encode(name)}/value", nil, params, "Content-Type" => "application/json")
|
100
125
|
end
|
101
126
|
|
102
|
-
#
|
127
|
+
# Post multiple values to a single stream
|
103
128
|
#
|
104
|
-
#
|
105
|
-
#
|
106
|
-
|
107
|
-
|
129
|
+
# This method allows posting multiple values to a stream
|
130
|
+
# belonging to a feed. The stream should be created before
|
131
|
+
# posting values using this method. The `values` parameter is a
|
132
|
+
# hash with the following format:
|
133
|
+
#
|
134
|
+
# {
|
135
|
+
# { "at": <Time in ISO8601>, "value": x },
|
136
|
+
# { "at": <Time in ISO8601>, "value": y },
|
137
|
+
# [ ... ]
|
138
|
+
# }
|
139
|
+
def post_stream_values(id, name, values)
|
140
|
+
params = { values: values }
|
141
|
+
@client.post("/feeds/#{URI.encode(id)}/streams/#{URI.encode(name)}/values", nil, params, "Content-Type" => "application/json")
|
108
142
|
end
|
109
143
|
|
110
|
-
#
|
111
|
-
|
112
|
-
|
144
|
+
# Delete values in a stream by a date range
|
145
|
+
# The `start` and `stop` parameters should be ISO8601 timestamps
|
146
|
+
def delete_stream_values(id, name, start, stop)
|
147
|
+
params = { from: start, end: stop }
|
148
|
+
@client.delete("/feeds/#{URI.encode(id)}/streams/#{URI.encode(name)}/values", nil, params, "Content-Type" => "application/json")
|
113
149
|
end
|
114
150
|
|
115
151
|
# Post multiple values to multiple streams
|
@@ -122,18 +158,33 @@ class M2X
|
|
122
158
|
# {
|
123
159
|
# "stream-name-1": [
|
124
160
|
# { "at": <Time in ISO8601>, "value": x },
|
125
|
-
# { "value": y }
|
161
|
+
# { "at": <Time in ISO8601>, "value": y }
|
126
162
|
# ],
|
127
163
|
# "stream-name-2": [ ... ]
|
128
164
|
# }
|
129
|
-
#
|
130
|
-
# If the `at` attribute is missing the the current time of the
|
131
|
-
# server, in UTC, will be used.
|
132
165
|
def post_multiple(id, values)
|
133
166
|
params = { values: values }
|
134
167
|
@client.post("/feeds/#{URI.encode(id)}", nil, params, "Content-Type" => "application/json")
|
135
168
|
end
|
136
169
|
|
170
|
+
# Returns a list of API keys associated with the feed
|
171
|
+
def keys(id)
|
172
|
+
@client.get("/keys", feed: id)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Creates a new API key associated to the feed
|
176
|
+
#
|
177
|
+
# If a parameter named `stream` is supplied with a stream name, it
|
178
|
+
# will create an API key associated with that stream only.
|
179
|
+
def create_key(id, params)
|
180
|
+
keys_api.create(params.merge(feed: id))
|
181
|
+
end
|
182
|
+
|
183
|
+
# Updates an API key properties
|
184
|
+
def update_key(id, key, params)
|
185
|
+
keys_api.update(key, params.merge(feed: id))
|
186
|
+
end
|
187
|
+
|
137
188
|
private
|
138
189
|
|
139
190
|
def keys_api
|
data/lib/m2x/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: m2x
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro López
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: AT&T’s M2X is a cloud-based fully managed data storage service for network
|
16
16
|
connected machine-to-machine (M2M) devices. From trucks and turbines to vending
|