Class: M2X::Client::Collection
- Includes:
- Metadata
- Defined in:
- lib/m2x/collection.rb
Overview
Wrapper for AT&T M2X Collections API m2x.att.com/developer/documentation/v2/collections
Constant Summary collapse
- PATH =
"/collections"
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
-
.create!(client, params) ⇒ Object
Create a new collection.
-
.list(client, params = {}) ⇒ Object
Retrieve the list of collections accessible by the authenticated API key.
Instance Method Summary collapse
-
#add_device(device_id) ⇒ Object
Add device to collection.
- #devices ⇒ Object
- #path ⇒ Object
-
#remove_device(device_id) ⇒ Object
Remove device from collection.
Methods included from Metadata
#metadata_path, #read_metadata, #read_metadata_field, #update_metadata, #update_metadata_field
Methods inherited from Resource
#delete!, #initialize, #inspect, #refresh, #update!, #view
Constructor Details
This class inherits a constructor from M2X::Client::Resource
Class Method Details
.create!(client, params) ⇒ Object
Create a new collection
m2x.att.com/developer/documentation/v2/collections#Create-Collection
24 25 26 27 28 |
# File 'lib/m2x/collection.rb', line 24 def create!(client, params) res = client.post(PATH, nil, params, "Content-Type" => "application/json") new(client, res.json) if res.success? end |
.list(client, params = {}) ⇒ Object
Retrieve the list of collections accessible by the authenticated API key
m2x.att.com/developer/documentation/v2/collections#List-collections
15 16 17 18 19 |
# File 'lib/m2x/collection.rb', line 15 def list(client, params={}) res = client.get(PATH, params) res.json["collections"].map{ |atts| new(client, atts) } if res.success? end |
Instance Method Details
#add_device(device_id) ⇒ Object
Add device to collection
m2x.att.com/developer/documentation/v2/collections#Add-device-to-collection
45 46 47 |
# File 'lib/m2x/collection.rb', line 45 def add_device(device_id) @client.put("#{ path }/devices/#{ device_id }") end |
#devices ⇒ Object
36 37 38 39 40 |
# File 'lib/m2x/collection.rb', line 36 def devices res = @client.get("#{path}/devices") res.json["devices"].map{ |atts| M2X::Client::Device.new(@client, atts) } if res.success? end |
#path ⇒ Object
32 33 34 |
# File 'lib/m2x/collection.rb', line 32 def path @path ||= "#{ PATH }/#{ URI.encode(@attributes.fetch("id")) }" end |
#remove_device(device_id) ⇒ Object
Remove device from collection
m2x.att.com/developer/documentation/v2/collections#Remove-device-from-collection
52 53 54 |
# File 'lib/m2x/collection.rb', line 52 def remove_device(device_id) @client.delete("#{ path }/devices/#{ device_id }") end |