m2x 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +9 -0
- data/lib/m2x.rb +12 -0
- data/lib/m2x/batches.rb +79 -0
- data/lib/m2x/blueprints.rb +64 -0
- data/lib/m2x/datasources.rb +64 -0
- data/lib/m2x/feeds.rb +55 -7
- data/lib/m2x/version.rb +1 -1
- metadata +10 -9
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 25f278330a6a934500906b8e3ef75ca211c22b0b
|
4
|
+
data.tar.gz: 8fd69942d389699515c974650e8161748f2121f1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b1fc80acf6e77326e23eff2912a7d3893996cfe4cf2190ac1d61a57ca2e9347c04e33d98077114678cf0c16629fab989b4cddfb5f83f20051f0a0c91d4d717d2
|
7
|
+
data.tar.gz: ae5f1b59ee38e50d98585fd22cd38bfdf037e27b10c6ca32797f401d5910b1ee34d01741bad74e20e4e08f12b598643f962a5368e0448a1ef1b63975af890785
|
data/README.md
CHANGED
@@ -4,6 +4,15 @@
|
|
4
4
|
|
5
5
|
This gem 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
|
+
|
8
|
+
Getting Started
|
9
|
+
==========================
|
10
|
+
1. Signup for an [M2X Account](https://m2x.att.com/signup).
|
11
|
+
2. Obtain your _Master Key_ from the Master Keys tab of your [Account Settings](https://m2x.att.com/account) screen.
|
12
|
+
2. Create your first [Data Source Blueprint](https://m2x.att.com/blueprints) and copy its _Feed ID_.
|
13
|
+
3. Review the [M2X API Documentation](https://m2x.att.com/developer/documentation/overview).
|
14
|
+
|
15
|
+
|
7
16
|
## Example Usage
|
8
17
|
|
9
18
|
In order to be able to use this gem you will need an [AT&T M2X](https://m2x.att.com/) API key and a Data Source ID. If you don't have an API key, create an account and, once registered and with your account activated, 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:
|
data/lib/m2x.rb
CHANGED
@@ -27,4 +27,16 @@ class M2X
|
|
27
27
|
def feeds
|
28
28
|
@feeds ||= ::M2X::Feeds.new(client)
|
29
29
|
end
|
30
|
+
|
31
|
+
def blueprints
|
32
|
+
@blueprints ||= ::M2X::Blueprints.new(client)
|
33
|
+
end
|
34
|
+
|
35
|
+
def datasources
|
36
|
+
@datasources ||= ::M2X::Datasources.new(client)
|
37
|
+
end
|
38
|
+
|
39
|
+
def batches
|
40
|
+
@batches ||= ::M2X::Batches.new(client)
|
41
|
+
end
|
30
42
|
end
|
data/lib/m2x/batches.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
class M2X
|
2
|
+
|
3
|
+
# Wrapper for AT&T M2X Batches API
|
4
|
+
#
|
5
|
+
# See https://m2x.att.com/developer/documentation/datasource
|
6
|
+
class Batches
|
7
|
+
# Creates a new M2X Batches API Wrapper
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
# List/search all the data source batches that belong to the user
|
13
|
+
# associated with the M2X API key supplied when initializing M2X
|
14
|
+
#
|
15
|
+
# The list of data source batches can be filtered by using one or
|
16
|
+
# more of the following optional parameters:
|
17
|
+
#
|
18
|
+
# * `q` text to search, matching the name and description.
|
19
|
+
# * `tags` a comma separated list of tags.
|
20
|
+
# * `limit` how many results per page.
|
21
|
+
# * `page` the specific results page, starting by 1.
|
22
|
+
# * `latitude` and `longitude` for searching feeds geographically.
|
23
|
+
# * `distance` numeric value in `distance_unit`.
|
24
|
+
# * `distance_unit` either `miles`, `mi` or `km`.
|
25
|
+
def list(params={})
|
26
|
+
@client.get("/batches", params)
|
27
|
+
end
|
28
|
+
alias_method :search, :list
|
29
|
+
|
30
|
+
# Create a new data source batch
|
31
|
+
#
|
32
|
+
# Accepts the following parameters as members of a hash:
|
33
|
+
#
|
34
|
+
# * `name` the name of the new data source.
|
35
|
+
# * `visibility` either "public" or "private".
|
36
|
+
# * `description` containing a longer description (optional).
|
37
|
+
# * `tags` a comma separated string of tags (optional).
|
38
|
+
def create(params={})
|
39
|
+
@client.post("/batches", nil, extras.merge(name: name))
|
40
|
+
end
|
41
|
+
|
42
|
+
# Retrieve information about an existing data source batch
|
43
|
+
def view(id)
|
44
|
+
@client.get("/batches/#{URI.encode(id)}")
|
45
|
+
end
|
46
|
+
|
47
|
+
# Update an existing data source batch details
|
48
|
+
#
|
49
|
+
# Accepts the following parameters as members of a hash:
|
50
|
+
#
|
51
|
+
# * `name` the name of the new data source.
|
52
|
+
# * `visibility` either "public" or "private".
|
53
|
+
# * `description` containing a longer description (optional).
|
54
|
+
# * `tags` a comma separated string of tags (optional).
|
55
|
+
def update(id, params={})
|
56
|
+
@client.put("/batches/#{URI.encode(id)}", nil, extras.merge(name: name))
|
57
|
+
end
|
58
|
+
|
59
|
+
# List/search all data sources in the batch
|
60
|
+
#
|
61
|
+
# See Datasources#search for search parameters description.
|
62
|
+
def datasources(id, params={})
|
63
|
+
@client.get("/batches/#{URI.encode(id)}/datasources", params)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Add a new data source to an existing batch
|
67
|
+
#
|
68
|
+
# Accepts a `serial` parameter, that must be a unique identifier
|
69
|
+
# within this batch.
|
70
|
+
def add_datasource(id, serial)
|
71
|
+
@client.post("/batches/#{URI.encode(id)}/datasources", nil, { serial: serial })
|
72
|
+
end
|
73
|
+
|
74
|
+
# Delete an existing data source batch
|
75
|
+
def delete(id)
|
76
|
+
@client.delete("/batches/#{URI.encode(id)}")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class M2X
|
2
|
+
|
3
|
+
# Wrapper for AT&T M2X Blueprints API
|
4
|
+
#
|
5
|
+
# See https://m2x.att.com/developer/documentation/datasource
|
6
|
+
class Blueprints
|
7
|
+
# Creates a new M2X Blueprints API Wrapper
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
# List/search all the blueprints that belong to the user associated
|
13
|
+
# with the M2X API key supplied when initializing M2X
|
14
|
+
#
|
15
|
+
# The list of blueprints can be filtered by using one or more of the
|
16
|
+
# following optional parameters:
|
17
|
+
#
|
18
|
+
# * `q` text to search, matching the name and description.
|
19
|
+
# * `tags` a comma separated list of tags.
|
20
|
+
# * `limit` how many results per page.
|
21
|
+
# * `page` the specific results page, starting by 1.
|
22
|
+
# * `latitude` and `longitude` for searching feeds geographically.
|
23
|
+
# * `distance` numeric value in `distance_unit`.
|
24
|
+
# * `distance_unit` either `miles`, `mi` or `km`.
|
25
|
+
def list(params={})
|
26
|
+
@client.get("/blueprints", params)
|
27
|
+
end
|
28
|
+
alias_method :search, :list
|
29
|
+
|
30
|
+
# Create a new data source blueprint
|
31
|
+
#
|
32
|
+
# Accepts the following parameters as members of a hash:
|
33
|
+
#
|
34
|
+
# * `name` the name of the new data source blueprint.
|
35
|
+
# * `visibility` either "public" or "private".
|
36
|
+
# * `description` containing a longer description (optional).
|
37
|
+
# * `tags` a comma separated string of tags (optional).
|
38
|
+
def create(params={})
|
39
|
+
@client.post("/blueprints", nil, extras.merge(name: name))
|
40
|
+
end
|
41
|
+
|
42
|
+
# Retrieve information about an existing data source blueprint
|
43
|
+
def view(id)
|
44
|
+
@client.get("/blueprints/#{URI.encode(id)}")
|
45
|
+
end
|
46
|
+
|
47
|
+
# Update an existing data source blueprint's information
|
48
|
+
#
|
49
|
+
# Accepts the following parameters as members of a hash:
|
50
|
+
#
|
51
|
+
# * `name` the name of the new data source blueprint.
|
52
|
+
# * `visibility` either "public" or "private".
|
53
|
+
# * `description` containing a longer description (optional).
|
54
|
+
# * `tags` a comma separated string of tags (optional).
|
55
|
+
def update(id, params={})
|
56
|
+
@client.put("/blueprints/#{URI.encode(id)}", nil, extras.merge(name: name))
|
57
|
+
end
|
58
|
+
|
59
|
+
# Delete an existing data source blueprint
|
60
|
+
def delete(id)
|
61
|
+
@client.delete("/blueprints/#{URI.encode(id)}")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class M2X
|
2
|
+
|
3
|
+
# Wrapper for AT&T M2X Data Sources API
|
4
|
+
#
|
5
|
+
# See https://m2x.att.com/developer/documentation/datasource
|
6
|
+
class Datasources
|
7
|
+
# Creates a new M2X Data Sources API Wrapper
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
# List/search all the datasources that belong to the user associated
|
13
|
+
# with the M2X API key supplied when initializing M2X
|
14
|
+
#
|
15
|
+
# The list of data sources can be filtered by using one or more of the
|
16
|
+
# following optional parameters:
|
17
|
+
#
|
18
|
+
# * `q` text to search, matching the name and description.
|
19
|
+
# * `tags` a comma separated list of tags.
|
20
|
+
# * `limit` how many results per page.
|
21
|
+
# * `page` the specific results page, starting by 1.
|
22
|
+
# * `latitude` and `longitude` for searching feeds geographically.
|
23
|
+
# * `distance` numeric value in `distance_unit`.
|
24
|
+
# * `distance_unit` either `miles`, `mi` or `km`.
|
25
|
+
def list(params={})
|
26
|
+
@client.get("/datasources", params)
|
27
|
+
end
|
28
|
+
alias_method :search, :list
|
29
|
+
|
30
|
+
# Create a new data source
|
31
|
+
#
|
32
|
+
# Accepts the following parameters as members of a hash:
|
33
|
+
#
|
34
|
+
# * `name` the name of the new data source.
|
35
|
+
# * `visibility` either "public" or "private".
|
36
|
+
# * `description` containing a longer description (optional).
|
37
|
+
# * `tags` a comma separated string of tags (optional).
|
38
|
+
def create(params={})
|
39
|
+
@client.post("/datasources", nil, extras.merge(name: name))
|
40
|
+
end
|
41
|
+
|
42
|
+
# Retrieve information about an existing data source
|
43
|
+
def view(id)
|
44
|
+
@client.get("/datasources/#{URI.encode(id)}")
|
45
|
+
end
|
46
|
+
|
47
|
+
# Update an existing data source details
|
48
|
+
#
|
49
|
+
# Accepts the following parameters as members of a hash:
|
50
|
+
#
|
51
|
+
# * `name` the name of the new data source.
|
52
|
+
# * `visibility` either "public" or "private".
|
53
|
+
# * `description` containing a longer description (optional).
|
54
|
+
# * `tags` a comma separated string of tags (optional).
|
55
|
+
def update(id, params={})
|
56
|
+
@client.put("/datasources/#{URI.encode(id)}", nil, extras.merge(name: name))
|
57
|
+
end
|
58
|
+
|
59
|
+
# Delete an existing data source
|
60
|
+
def delete(id)
|
61
|
+
@client.delete("/datasources/#{URI.encode(id)}")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/m2x/feeds.rb
CHANGED
@@ -10,11 +10,24 @@ class M2X
|
|
10
10
|
@client = client
|
11
11
|
end
|
12
12
|
|
13
|
-
# List all the feeds that belong to the user associated
|
14
|
-
# M2X API key supplied when initializing M2X
|
15
|
-
|
16
|
-
|
13
|
+
# List/search all the feeds that belong to the user associated
|
14
|
+
# with the M2X API key supplied when initializing M2X
|
15
|
+
#
|
16
|
+
# The list of feeds can be filtered by using one or more of the
|
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`.
|
27
|
+
def list(params={})
|
28
|
+
@client.get("/feeds", params)
|
17
29
|
end
|
30
|
+
alias_method :search, :list
|
18
31
|
|
19
32
|
# Return the details of the supplied feed
|
20
33
|
def view(id)
|
@@ -49,9 +62,22 @@ class M2X
|
|
49
62
|
@client.get("/feeds/#{URI.encode(id)}/streams/#{URI.encode(name)}")
|
50
63
|
end
|
51
64
|
|
52
|
-
#
|
53
|
-
|
54
|
-
|
65
|
+
# List values from an existing data stream associated with a
|
66
|
+
# specific feed, sorted in reverse chronological order (most
|
67
|
+
# recent values first).
|
68
|
+
#
|
69
|
+
# The values can be filtered by using one or more of the following
|
70
|
+
# optional parameters:
|
71
|
+
#
|
72
|
+
# * `start` An ISO 8601 timestamp specifying the start of the date
|
73
|
+
# * range to be considered.
|
74
|
+
#
|
75
|
+
# * `end` An ISO 8601 timestamp specifying the end of the date
|
76
|
+
# * range to be considered.
|
77
|
+
#
|
78
|
+
# * `limit` Maximum number of values to return.
|
79
|
+
def stream_values(id, name, params={})
|
80
|
+
@client.get("/feeds/#{URI.encode(id)}/streams/#{URI.encode(name)}/values", params)
|
55
81
|
end
|
56
82
|
|
57
83
|
# Update stream's properties
|
@@ -86,6 +112,28 @@ class M2X
|
|
86
112
|
keys_api.update(key, params.merge(feed: id))
|
87
113
|
end
|
88
114
|
|
115
|
+
# Post multiple values to multiple streams
|
116
|
+
#
|
117
|
+
# This method allows posting multiple values to multiple streams
|
118
|
+
# belonging to a feed. All the streams should be created before
|
119
|
+
# posting values using this method. The `values` parameters is a
|
120
|
+
# hash with the following format:
|
121
|
+
#
|
122
|
+
# {
|
123
|
+
# "stream-name-1": [
|
124
|
+
# { "at": <Time in ISO8601>, "value": x },
|
125
|
+
# { "value": y }
|
126
|
+
# ],
|
127
|
+
# "stream-name-2": [ ... ]
|
128
|
+
# }
|
129
|
+
#
|
130
|
+
# If the `at` attribute is missing the the current time of the
|
131
|
+
# server, in UTC, will be used.
|
132
|
+
def post_multiple(id, values)
|
133
|
+
params = { values: values }
|
134
|
+
@client.post("/feeds/#{URI.encode(id)}", nil, params, "Content-Type" => "application/json")
|
135
|
+
end
|
136
|
+
|
89
137
|
private
|
90
138
|
|
91
139
|
def keys_api
|
data/lib/m2x/version.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: m2x
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Leandro López
|
@@ -10,7 +9,7 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2013-
|
12
|
+
date: 2013-11-15 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
14
|
description: AT&T’s M2X is a cloud-based fully managed data storage service for network
|
16
15
|
connected machine-to-machine (M2M) devices. From trucks and turbines to vending
|
@@ -25,7 +24,10 @@ extra_rdoc_files: []
|
|
25
24
|
files:
|
26
25
|
- LICENSE
|
27
26
|
- README.md
|
27
|
+
- lib/m2x/batches.rb
|
28
|
+
- lib/m2x/blueprints.rb
|
28
29
|
- lib/m2x/client.rb
|
30
|
+
- lib/m2x/datasources.rb
|
29
31
|
- lib/m2x/feeds.rb
|
30
32
|
- lib/m2x/keys.rb
|
31
33
|
- lib/m2x/version.rb
|
@@ -34,26 +36,25 @@ files:
|
|
34
36
|
homepage: http://github.com/attm2x/m2x-ruby
|
35
37
|
licenses:
|
36
38
|
- MIT
|
39
|
+
metadata: {}
|
37
40
|
post_install_message:
|
38
41
|
rdoc_options: []
|
39
42
|
require_paths:
|
40
43
|
- lib
|
41
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
45
|
requirements:
|
44
|
-
- -
|
46
|
+
- - '>='
|
45
47
|
- !ruby/object:Gem::Version
|
46
48
|
version: '0'
|
47
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
50
|
requirements:
|
50
|
-
- -
|
51
|
+
- - '>='
|
51
52
|
- !ruby/object:Gem::Version
|
52
53
|
version: '0'
|
53
54
|
requirements: []
|
54
55
|
rubyforge_project:
|
55
|
-
rubygems_version:
|
56
|
+
rubygems_version: 2.0.3
|
56
57
|
signing_key:
|
57
|
-
specification_version:
|
58
|
+
specification_version: 4
|
58
59
|
summary: Ruby client for AT&T M2X
|
59
60
|
test_files: []
|