m2x 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 113f7943534da2d33e88c0d3a6d1a9635eb978a7
4
- data.tar.gz: 8dd90a58bc94561b2bb133667ad6dfe27e16284c
3
+ metadata.gz: fe1dabe03b3a24e0b5136816f19c3f6347a6498a
4
+ data.tar.gz: 978105c867176fbb810ae6a511112aa637abec58
5
5
  SHA512:
6
- metadata.gz: d62e6954c2f678be2308ef02e12a2ef2803948f6dedeb77de0073083107577daab2c577a667add676d0ccd42db813a873da7bd4b7cc8f29ca8454735a4200d34
7
- data.tar.gz: bff82ec70417c205b14500c9aa5ba12d1000986253c32e64def2b66401688294fe2028af7346d08468b374b81aa67c133bb93a22e6bb743b91f3d2d2c60b6449
6
+ metadata.gz: 9160f22d3eb90282ed6ab715aec926ea0297f7405216407aed56c86b7e42c6e9f5762f79d16ced129906515471c200cd0929263390e492ebe2246a1a79e410e3
7
+ data.tar.gz: 8275e6b70fe22def7e83fa2f90f7f096765fddad39ed5d30f5a1bf858fb6850a9ca8049672179af7127565e0aeacd1af083f9915d70dae4b5fba9609f53e976c
data/README.md CHANGED
@@ -41,6 +41,13 @@ This provides an interface to your data in M2X
41
41
  devices = m2x.devices
42
42
  ```
43
43
 
44
+ - [Collection](lib/m2x/collection.rb)
45
+ ```ruby
46
+ collection = m2x.collection("<COLLECTION-ID>")
47
+
48
+ collections = m2x.collections
49
+ ```
50
+
44
51
  - [Key](lib/m2x/key.rb)
45
52
  ```ruby
46
53
  key = m2x.key("<KEY-TOKEN>")
@@ -48,6 +55,11 @@ This provides an interface to your data in M2X
48
55
  keys = m2x.keys
49
56
  ```
50
57
 
58
+ - [Job](lib/m2x/job.rb)
59
+ ```ruby
60
+ job = m2x.job("<JOB-ID>")
61
+ ```
62
+
51
63
  Refer to the documentation on each class for further usage instructions.
52
64
 
53
65
  ## Time
data/lib/m2x.rb CHANGED
@@ -3,8 +3,11 @@ module M2X; end
3
3
  require_relative "m2x/version"
4
4
  require_relative "m2x/response"
5
5
  require_relative "m2x/client"
6
- require_relative "m2x/resource"
7
- require_relative "m2x/key"
6
+
7
+ require_relative "m2x/collection"
8
8
  require_relative "m2x/device"
9
- require_relative "m2x/stream"
10
9
  require_relative "m2x/distribution"
10
+ require_relative "m2x/job"
11
+ require_relative "m2x/key"
12
+ require_relative "m2x/stream"
13
+
@@ -37,6 +37,26 @@ class M2X::Client
37
37
  get("/status")
38
38
  end
39
39
 
40
+ # Obtain a Collection from M2X
41
+ #
42
+ # This method instantiates an instance of Collection and calls `Collection#view`
43
+ # method, returning the collection instance with all its attributes initialized
44
+ def collection(id)
45
+ M2X::Client::Collection.new(self, "id" => id).tap(&:view)
46
+ end
47
+
48
+ # Creates a new collection on M2X with the specified parameters
49
+ def create_collection(params)
50
+ M2X::Client::Collection.create!(self, params)
51
+ end
52
+
53
+ # Retrieve the list of collections accessible by the authenticated API key
54
+ #
55
+ # See M2X::Client::Collection.list for more details
56
+ def collections(params={})
57
+ M2X::Client::Collection.list(self, params)
58
+ end
59
+
40
60
  # Obtain a Device from M2X
41
61
  #
42
62
  # This method instantiates an instance of Device and calls `Device#view`
@@ -50,14 +70,21 @@ class M2X::Client
50
70
  M2X::Client::Device.create!(self, params)
51
71
  end
52
72
 
53
- # Retrieve the list of devices accessible by the authenticated API key that
54
- # meet the search criteria.
73
+ # Retrieve the list of devices accessible by the authenticated API key
55
74
  #
56
75
  # See M2X::Client::Device.list for more details
57
76
  def devices(params={})
58
77
  M2X::Client::Device.list(self, params)
59
78
  end
60
79
 
80
+ # Retrieve the list of devices accessible by the authenticated API key that
81
+ # meet the search criteria.
82
+ #
83
+ # See M2X::Client::Device.search for more details
84
+ def search_devices(params={})
85
+ M2X::Client::Device.list(self, params)
86
+ end
87
+
61
88
  # Search the catalog of public Devices.
62
89
  #
63
90
  # This allows unauthenticated users to search Devices from other users that
@@ -92,6 +119,14 @@ class M2X::Client
92
119
  M2X::Client::Distribution.list(self, params)
93
120
  end
94
121
 
122
+ # Obtain a Job from M2X
123
+ #
124
+ # This method instantiates an instance of Job and calls `Job#view`
125
+ # method, returning the job instance with all its attributes initialized
126
+ def job(id)
127
+ M2X::Client::Job.new(self, "id" => id).tap(&:view)
128
+ end
129
+
95
130
  # Obtain an API Key from M2X
96
131
  #
97
132
  # This method instantiates an instance of Key and calls
@@ -0,0 +1,32 @@
1
+ require_relative "./resource"
2
+
3
+ # Wrapper for AT&T M2X Collections API
4
+ # https://m2x.att.com/developer/documentation/v2/collections
5
+ class M2X::Client::Collection < M2X::Client::Resource
6
+
7
+ PATH = "/collections"
8
+
9
+ class << self
10
+ # Retrieve the list of collections accessible by the authenticated API key
11
+ #
12
+ # https://m2x.att.com/developer/documentation/v2/collections#List-collections
13
+ def list(client, params={})
14
+ res = client.get(PATH, params)
15
+
16
+ res.json["collections"].map{ |atts| new(client, atts) } if res.success?
17
+ end
18
+
19
+ # Create a new collection
20
+ #
21
+ # https://m2x.att.com/developer/documentation/v2/collections#Create-Collection
22
+ def create!(client, params)
23
+ res = client.post(PATH, nil, params, "Content-Type" => "application/json")
24
+
25
+ new(client, res.json) if res.success?
26
+ end
27
+ end
28
+
29
+ def path
30
+ @path ||= "#{ PATH }/#{ URI.encode(@attributes.fetch("id")) }"
31
+ end
32
+ end
@@ -1,3 +1,5 @@
1
+ require_relative "./resource"
2
+
1
3
  # Wrapper for AT&T M2X Device API
2
4
  # https://m2x.att.com/developer/documentation/v2/device
3
5
  class M2X::Client::Device < M2X::Client::Resource
@@ -5,16 +7,25 @@ class M2X::Client::Device < M2X::Client::Resource
5
7
  PATH = "/devices"
6
8
 
7
9
  class << self
8
- # Retrieve the list of devices accessible by the authenticated API key that
9
- # meet the search criteria.
10
+ # Retrieve the list of devices accessible by the authenticated API key
10
11
  #
11
- # https://m2x.att.com/developer/documentation/v2/device#List-Search-Devices
12
+ # https://m2x.att.com/developer/documentation/v2/device#List-Devices
12
13
  def list(client, params={})
13
14
  res = client.get(PATH, params)
14
15
 
15
16
  res.json["devices"].map{ |atts| new(client, atts) } if res.success?
16
17
  end
17
18
 
19
+ # Retrieve the list of devices accessible by the authenticated API key that
20
+ # meet the search criteria.
21
+ #
22
+ # https://m2x.att.com/developer/documentation/v2/device#Search-Devices
23
+ def search(client, params={})
24
+ res = client.get("#{PATH}/search", params)
25
+
26
+ res.json["devices"].map{ |atts| new(client, atts) } if res.success?
27
+ end
28
+
18
29
  # Search the catalog of public Devices.
19
30
  #
20
31
  # This allows unauthenticated users to search Devices from other users
@@ -107,6 +118,60 @@ class M2X::Client::Device < M2X::Client::Resource
107
118
  @client.post("#{path}/updates", nil, params, "Content-Type" => "application/json")
108
119
  end
109
120
 
121
+ # Post Device Update (Single Value to Multiple Streams)
122
+ #
123
+ # This method allows posting a single value to multiple streams
124
+ # belonging to a device and optionally, the device's location.
125
+ #
126
+ # All the streams should be created before posting values using this method.
127
+ #
128
+ # The `params` parameter accepts a Hash which can contain the following keys:
129
+ # - values: A Hash in which the keys are the stream names and the values
130
+ # hold the stream values.
131
+ # - location: (optional) A hash with the current location of the specified
132
+ # device.
133
+ # - timestamp: (optional) The timestamp for all the passed values and
134
+ # location. If ommited, the M2X server's time will be used.
135
+ #
136
+ # {
137
+ # values: {
138
+ # temperature: 30,
139
+ # humidity: 80
140
+ # },
141
+ # location: {
142
+ # name: "Storage Room",
143
+ # latitude: -37.9788423562422,
144
+ # longitude: -57.5478776916862,
145
+ # elevation: 5
146
+ # }
147
+ # }
148
+ #
149
+ # https://m2x.att.com/developer/documentation/v2/device#Post-Device-Update--Single-Values-to-Multiple-Streams-
150
+ def post_update(params)
151
+ @client.post("#{path}/update", nil, params, "Content-Type" => "application/json")
152
+ end
153
+
154
+ # List Values from all Data Streams of a Device
155
+ #
156
+ # https://m2x.att.com/developer/documentation/v2/device#List-Values-from-all-Data-Streams-of-a-Device
157
+ def values(params = {})
158
+ @client.get("#{path}/values", params)
159
+ end
160
+
161
+ # Export Values from all Data Streams of a Device
162
+ #
163
+ # https://m2x.att.com/developer/documentation/v2/device#Export-Values-from-all-Data-Streams-of-a-Device
164
+ def values_export(params = {})
165
+ @client.get("#{path}/values/export.csv", params)
166
+ end
167
+
168
+ # Search Values from all Data Streams of a Device
169
+ #
170
+ # https://m2x.att.com/developer/documentation/v2/device#Search-Values-from-all-Data-Streams-of-a-Device
171
+ def values_search(params)
172
+ @client.get("#{path}/values/search", nil, params, "Content-Type" => "application/json")
173
+ end
174
+
110
175
  # Retrieve list of data streams associated with the device.
111
176
  #
112
177
  # https://m2x.att.com/developer/documentation/v2/device#List-Data-Streams
@@ -1,3 +1,5 @@
1
+ require_relative "./resource"
2
+
1
3
  # Wrapper for AT&T M2X Distribution API
2
4
  # https://m2x.att.com/developer/documentation/v2/distribution
3
5
  class M2X::Client::Distribution < M2X::Client::Resource
@@ -0,0 +1,21 @@
1
+ require_relative "./resource"
2
+
3
+ # Wrapper for AT&T M2X Job API
4
+ # https://m2x.att.com/developer/documentation/v2/jobs
5
+ class M2X::Client::Job < M2X::Client::Resource
6
+
7
+ PATH = "/jobs"
8
+
9
+ def path
10
+ @path ||= "#{PATH}/#{ URI.encode(@attributes.fetch("id")) }"
11
+ end
12
+
13
+ # Updating and deleting jobs is not supported by the M2X API
14
+ def update!(_)
15
+ fail NotImplementedError
16
+ end
17
+
18
+ def delete!
19
+ fail NotImplementedError
20
+ end
21
+ end
@@ -1,3 +1,5 @@
1
+ require_relative "./resource"
2
+
1
3
  # Wrapper for AT&T M2X Keys API
2
4
  # https://m2x.att.com/developer/documentation/v2/keys
3
5
  class M2X::Client::Key < M2X::Client::Resource
@@ -1,3 +1,5 @@
1
+ require_relative "./resource"
2
+
1
3
  # Wrapper for AT&T M2X Data Streams API
2
4
  # https://m2x.att.com/developer/documentation/v2/device
3
5
  class M2X::Client::Stream < M2X::Client::Resource
@@ -1,5 +1,5 @@
1
1
  module M2X
2
2
  class Client
3
- VERSION = "2.2.0"
3
+ VERSION = "2.3.0"
4
4
  end
5
5
  end
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: 2.2.0
4
+ version: 2.3.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: 2015-07-04 00:00:00.000000000 Z
13
+ date: 2015-08-31 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
@@ -29,14 +29,15 @@ files:
29
29
  - lib/m2x.rb
30
30
  - lib/m2x/cacert.pem
31
31
  - lib/m2x/client.rb
32
+ - lib/m2x/collection.rb
32
33
  - lib/m2x/device.rb
33
34
  - lib/m2x/distribution.rb
35
+ - lib/m2x/job.rb
34
36
  - lib/m2x/key.rb
35
37
  - lib/m2x/resource.rb
36
38
  - lib/m2x/response.rb
37
39
  - lib/m2x/stream.rb
38
40
  - lib/m2x/version.rb
39
- - lib/megatest.rb
40
41
  - m2x.gemspec
41
42
  homepage: http://github.com/attm2x/m2x-ruby
42
43
  licenses:
@@ -58,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
59
  version: '0'
59
60
  requirements: []
60
61
  rubyforge_project:
61
- rubygems_version: 2.4.5
62
+ rubygems_version: 2.4.5.1
62
63
  signing_key:
63
64
  specification_version: 4
64
65
  summary: Ruby client for AT&T M2X
@@ -1,80 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "time"
4
- require "pp"
5
-
6
- require_relative "./m2x"
7
-
8
- $m2x = M2X::Client.new("cdc032a8d7bfbf1ce5948a8c474eaa25", "http://staging-api.m2x.sl.attcompute.com")
9
- $running = true
10
-
11
- stop = Proc.new { $running = false }
12
-
13
- trap(:INT, &stop)
14
- trap(:TERM, &stop)
15
-
16
- 5.times do |i|
17
- break unless $running
18
- puts "Creating device #{i}"
19
-
20
- device = $m2x.create_device(name: "Test Device #{i}", description: "Some test device", visibility: "private")
21
- fail $m2x.last_response.inspect if $m2x.last_response.error?
22
-
23
- device = $m2x.device(device["id"])
24
- fail $m2x.last_response.inspect if $m2x.last_response.error?
25
-
26
- device.create_stream("testdevicestream", type: "numeric", unit: { label: "points", symbol: "pt" })
27
- fail $m2x.last_response.inspect if $m2x.last_response.error?
28
-
29
- stream = device.stream("testdevicestream")
30
-
31
- values = 2.times.map{ sleep 0.001; { timestamp: Time.now.utc.iso8601(3), value: rand(0..999999) } }
32
-
33
- stream.post_values(values)
34
- fail $m2x.last_response.inspect if $m2x.last_response.error?
35
- end
36
-
37
- puts "All devices created"
38
-
39
- arduino = $m2x.create_device(name: "My Arduinos", description: "Some test device", visibility: "private")
40
- puts arduino.create_stream("temperature")
41
- puts arduino.create_stream("humidity")
42
- puts arduino.create_stream("loudness")
43
-
44
- arduino.post_updates({
45
- values: {
46
- temperature: [
47
- { timestamp: (Time.now - 2).iso8601, value: rand(0..37) },
48
- { timestamp: (Time.now + 2).iso8601, value: rand(0..37) }
49
- ],
50
- humidity: [
51
- { timestamp: (Time.now - 3).iso8601, value: rand(0..100) },
52
- { timestamp: (Time.now + 3).iso8601, value: rand(0..100) }
53
- ]
54
- },
55
- location: { latitude: 80.3712, longitude: 100, elevation: 300 }
56
- })
57
-
58
- loudness = arduino.stream("loudness")
59
-
60
- loudness.post_values(1000.times.map{ |i| { timestamp: (Time.now + i).iso8601, value: rand(0..120) } })
61
-
62
- loudness.update_value(rand(90..9999))
63
-
64
- raspberries = $m2x.create_distribution(name: "Raspberries", description: "Group of raspberries", visibility: "private")
65
-
66
- all_raspberries = 10.times.map{ |i| raspberries.add_device(i.to_s) }
67
-
68
- all_raspberries.each do |device|
69
- device.update_location(latitude: rand(-90..90), longitude: rand(-180..180), elevation: rand(0..7000))
70
- end
71
-
72
- pp loudness.stats.json
73
- pp loudness.sampling(interval: 1).json
74
- pp loudness.values.json
75
-
76
- loudness.delete_values!((Time.now - 3600).iso8601, Time.now.iso8601)
77
-
78
- loudness.delete!
79
- arduino.delete!
80
- raspberries.delete!