m2x 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe1dabe03b3a24e0b5136816f19c3f6347a6498a
4
- data.tar.gz: 978105c867176fbb810ae6a511112aa637abec58
3
+ metadata.gz: 70f17c0238e0ffa54350a2b51b30cb03baaa13ce
4
+ data.tar.gz: cb0d4e1d429046af177c04941723c9eea2fb1b33
5
5
  SHA512:
6
- metadata.gz: 9160f22d3eb90282ed6ab715aec926ea0297f7405216407aed56c86b7e42c6e9f5762f79d16ced129906515471c200cd0929263390e492ebe2246a1a79e410e3
7
- data.tar.gz: 8275e6b70fe22def7e83fa2f90f7f096765fddad39ed5d30f5a1bf858fb6850a9ca8049672179af7127565e0aeacd1af083f9915d70dae4b5fba9609f53e976c
6
+ metadata.gz: 9c5a6aa82d13e07f0f88d1cc69f50d14bc002ed58a284f62cc256fbf768fcc310f6713e5b81f6e2ae66708e864a82433095d5794bcb715d6fc715814b46972f8
7
+ data.tar.gz: b520c2455cf1d4059515e8e93c71af3b1da9cb41c24e94910db81df1e2385f3adec25ba560a9a335dc17ad28679e0aa524c71cb73c56f2603fcbd936a4c4f7a4
data/lib/m2x.rb CHANGED
@@ -5,9 +5,9 @@ require_relative "m2x/response"
5
5
  require_relative "m2x/client"
6
6
 
7
7
  require_relative "m2x/collection"
8
+ require_relative "m2x/command"
8
9
  require_relative "m2x/device"
9
10
  require_relative "m2x/distribution"
10
11
  require_relative "m2x/job"
11
12
  require_relative "m2x/key"
12
13
  require_relative "m2x/stream"
13
-
@@ -57,6 +57,26 @@ class M2X::Client
57
57
  M2X::Client::Collection.list(self, params)
58
58
  end
59
59
 
60
+ # List Sent Commands
61
+ #
62
+ # See M2X::Client::Command.list for more details
63
+ def commands(params={})
64
+ M2X::Client::Command.list(self, params)
65
+ end
66
+
67
+ # View Command Details
68
+ #
69
+ # This method instantiates an instance of Command and calls `Command#view`
70
+ # method, returning the command instance with all its attributes initialized
71
+ def command(id)
72
+ M2X::Client::Command.new(self, "id" => id).tap(&:view)
73
+ end
74
+
75
+ # Send command
76
+ def send_command(params)
77
+ M2X::Client::Command.send!(self, params)
78
+ end
79
+
60
80
  # Obtain a Device from M2X
61
81
  #
62
82
  # This method instantiates an instance of Device and calls `Device#view`
@@ -1,8 +1,10 @@
1
1
  require_relative "./resource"
2
+ require_relative "./metadata"
2
3
 
3
4
  # Wrapper for AT&T M2X Collections API
4
5
  # https://m2x.att.com/developer/documentation/v2/collections
5
6
  class M2X::Client::Collection < M2X::Client::Resource
7
+ include M2X::Client::Metadata
6
8
 
7
9
  PATH = "/collections"
8
10
 
@@ -0,0 +1,61 @@
1
+ # Wrapper for AT&T M2X Commands API
2
+ # https://m2x.att.com/developer/documentation/v2/commands
3
+ class M2X::Client::Command
4
+ extend Forwardable
5
+
6
+ PATH = "/commands"
7
+
8
+ attr_reader :attributes
9
+
10
+ def_delegator :@attributes, :[]
11
+
12
+ def initialize(client, attributes)
13
+ @client = client
14
+ @attributes = attributes
15
+ end
16
+
17
+ def path
18
+ @path ||= "#{ PATH }/#{ URI.encode(@attributes.fetch("id")) }"
19
+ end
20
+
21
+ # View Command Details
22
+ #
23
+ # Get details of a sent command including the delivery information for all
24
+ # devices that were targetted by the command at the time it was sent.
25
+ #
26
+ # https://m2x.att.com/developer/documentation/v2/commands#View-Command-Details
27
+ def view
28
+ res = @client.get(path)
29
+
30
+ @attributes = res.json if res.success?
31
+ end
32
+
33
+ def inspect
34
+ "<#{self.class.name}: #{attributes.inspect}>"
35
+ end
36
+
37
+ class << self
38
+ # List Sent Commands
39
+ #
40
+ # Retrieve the list of recent commands sent by the current user
41
+ # (as given by the API key).
42
+ #
43
+ # https://m2x.att.com/developer/documentation/v2/commands#List-Sent-Commands
44
+ def list(client, params={})
45
+ res = client.get(PATH, params)
46
+
47
+ res.json["commands"].map { |atts| new(client, atts) } if res.success?
48
+ end
49
+
50
+ # Send Command
51
+ #
52
+ # Send a command with the given name to the given target devices.
53
+ # The name should be a custom string defined by the user and understood by
54
+ # the device.
55
+ #
56
+ # https://m2x.att.com/developer/documentation/v2/commands#Send-Command
57
+ def send!(client, params)
58
+ client.post(PATH, nil, params, "Content-Type" => "application/json")
59
+ end
60
+ end
61
+ end
@@ -1,8 +1,10 @@
1
1
  require_relative "./resource"
2
+ require_relative "./metadata"
2
3
 
3
4
  # Wrapper for AT&T M2X Device API
4
5
  # https://m2x.att.com/developer/documentation/v2/device
5
6
  class M2X::Client::Device < M2X::Client::Resource
7
+ include M2X::Client::Metadata
6
8
 
7
9
  PATH = "/devices"
8
10
 
@@ -81,6 +83,15 @@ class M2X::Client::Device < M2X::Client::Resource
81
83
  @client.get("#{path}/location")
82
84
  end
83
85
 
86
+ # Read Device Location History
87
+ #
88
+ # Get location history details of an existing Device. Returns the 30 most
89
+ # recently logged locations by default.
90
+ # https://m2x.att.com/developer/documentation/v2/device#Read-Device-Location-History
91
+ def location_history(params = {})
92
+ @client.get("#{path}/location/waypoints", params)
93
+ end
94
+
84
95
  # Update the current location of the specified device.
85
96
  #
86
97
  # https://m2x.att.com/developer/documentation/v2/device#Update-Device-Location
@@ -209,4 +220,40 @@ class M2X::Client::Device < M2X::Client::Resource
209
220
  def create_key(params)
210
221
  ::M2X::Client::Key.create!(@client, params.merge(device: self["id"]))
211
222
  end
223
+
224
+ # Device's List of Received Commands
225
+ #
226
+ # Retrieve the list of recent commands sent to the current device (as given by the API key).
227
+ #
228
+ # https://m2x.att.com/developer/documentation/v2/commands#Device-s-List-of-Received-Commands
229
+ def commands(params = {})
230
+ res = @client.get("#{path}/commands", params)
231
+
232
+ res.json["commands"].map { |atts| M2X::Client::Command.new(@client, atts) } if res.success?
233
+ end
234
+
235
+ # Device's View of Command Details
236
+ #
237
+ # Get details of a received command including the delivery information for this device.
238
+ #
239
+ # https://m2x.att.com/developer/documentation/v2/commands#Device-s-View-of-Command-Details
240
+ def command(id)
241
+ res = @client.get("#{path}/commands/#{id}")
242
+
243
+ M2X::Client::Command.new(@client, res.json) if res.success?
244
+ end
245
+
246
+ # Process a command
247
+ #
248
+ # https://m2x.att.com/developer/documentation/v2/commands#Device-Marks-a-Command-as-Processed
249
+ def process_command(id, params = {})
250
+ @client.post("#{path}/commands/#{id}/process", nil, params)
251
+ end
252
+
253
+ # Reject a command
254
+ #
255
+ # https://m2x.att.com/developer/documentation/v2/commands#Device-Marks-a-Command-as-Rejected
256
+ def reject_command(id, params = {})
257
+ @client.post("#{path}/commands/#{id}/reject", nil, params)
258
+ end
212
259
  end
@@ -1,8 +1,10 @@
1
1
  require_relative "./resource"
2
+ require_relative "./metadata"
2
3
 
3
4
  # Wrapper for AT&T M2X Distribution API
4
5
  # https://m2x.att.com/developer/documentation/v2/distribution
5
6
  class M2X::Client::Distribution < M2X::Client::Resource
7
+ include M2X::Client::Metadata
6
8
 
7
9
  PATH = "/distributions"
8
10
 
@@ -0,0 +1,42 @@
1
+ module M2X::Client::Metadata
2
+
3
+ # Read an object's metadata
4
+ #
5
+ # https://m2x.att.com/developer/documentation/v2/device#Read-Device-Metadata
6
+ # https://m2x.att.com/developer/documentation/v2/distribution#Read-Distribution-Metadata
7
+ # https://m2x.att.com/developer/documentation/v2/collections#Read-Collection-Metadata
8
+ def read_metadata
9
+ @client.get(metadata_path)
10
+ end
11
+
12
+ # Read a single field of an object's metadata
13
+ #
14
+ # https://m2x.att.com/developer/documentation/v2/device#Read-Device-Metadata-Field
15
+ # https://m2x.att.com/developer/documentation/v2/distribution#Read-Distribution-Metadata-Field
16
+ # https://m2x.att.com/developer/documentation/v2/collections#Read-Collection-Metadata-Field
17
+ def read_metadata_field(field_name)
18
+ @client.get("#{metadata_path}/#{field_name}")
19
+ end
20
+
21
+ # Update an object's metadata
22
+ #
23
+ # https://m2x.att.com/developer/documentation/v2/device#Update-Device-Metadata
24
+ # https://m2x.att.com/developer/documentation/v2/distribution#Update-Distribution-Metadata
25
+ # https://m2x.att.com/developer/documentation/v2/collections#Update-Collection-Metadata
26
+ def update_metadata(params)
27
+ @client.put(metadata_path, nil, params, "Content-Type" => "application/json")
28
+ end
29
+
30
+ # Update a single field of an object's metadata
31
+ #
32
+ # https://m2x.att.com/developer/documentation/v2/device#Update-Device-Metadata-Field
33
+ # https://m2x.att.com/developer/documentation/v2/distribution#Update-Distribution-Metadata-Field
34
+ # https://m2x.att.com/developer/documentation/v2/collections#Update-Collection-Metadata-Field
35
+ def update_metadata_field(field_name, value)
36
+ @client.put("#{metadata_path}/#{field_name}", nil, { value: value }, "Content-Type" => "application/json")
37
+ end
38
+
39
+ def metadata_path
40
+ "#{path}/metadata"
41
+ end
42
+ end
@@ -1,5 +1,5 @@
1
1
  module M2X
2
2
  class Client
3
- VERSION = "2.3.0"
3
+ VERSION = "2.4.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.3.0
4
+ version: 2.4.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-08-31 00:00:00.000000000 Z
13
+ date: 2015-12-23 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
@@ -30,10 +30,12 @@ files:
30
30
  - lib/m2x/cacert.pem
31
31
  - lib/m2x/client.rb
32
32
  - lib/m2x/collection.rb
33
+ - lib/m2x/command.rb
33
34
  - lib/m2x/device.rb
34
35
  - lib/m2x/distribution.rb
35
36
  - lib/m2x/job.rb
36
37
  - lib/m2x/key.rb
38
+ - lib/m2x/metadata.rb
37
39
  - lib/m2x/resource.rb
38
40
  - lib/m2x/response.rb
39
41
  - lib/m2x/stream.rb
@@ -64,4 +66,3 @@ signing_key:
64
66
  specification_version: 4
65
67
  summary: Ruby client for AT&T M2X
66
68
  test_files: []
67
- has_rdoc: