Class: M2X::Client::Distribution
- Includes:
- Metadata
- Defined in:
- lib/m2x/distribution.rb
Overview
Wrapper for AT&T M2X Distribution API m2x.att.com/developer/documentation/v2/distribution
Constant Summary collapse
- PATH =
"/distributions"
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
-
.create!(client, params) ⇒ Object
Create a new device distribution.
-
.list(client, params = {}) ⇒ Object
(also: search)
Retrieve list of device distributions accessible by the authenticated API key.
Instance Method Summary collapse
-
#add_device(serial) ⇒ Object
Add a new device to an existing distribution.
-
#devices(params = {}) ⇒ Object
Retrieve list of devices added to the specified distribution.
- #path ⇒ Object
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 device distribution
m2x.att.com/developer/documentation/v2/distribution#Create-Distribution
26 27 28 29 30 |
# File 'lib/m2x/distribution.rb', line 26 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 Also known as: search
Retrieve list of device distributions accessible by the authenticated API key.
m2x.att.com/developer/documentation/v2/distribution#List-Distributions
16 17 18 19 20 |
# File 'lib/m2x/distribution.rb', line 16 def list(client, params={}) res = client.get(PATH, params) res.json["distributions"].map{ |atts| new(client, atts) } if res.success? end |
Instance Method Details
#add_device(serial) ⇒ Object
Add a new device to an existing distribution
Accepts a ‘serial` parameter, that must be a unique identifier within this distribution.
m2x.att.com/developer/documentation/v2/distribution#Add-Device-to-an-existing-Distribution
52 53 54 55 56 |
# File 'lib/m2x/distribution.rb', line 52 def add_device(serial) res = @client.post("#{path}/devices", nil, { serial: serial }, "Content-Type" => "application/json") ::M2X::Client::Device.new(@client, res.json) if res.success? end |
#devices(params = {}) ⇒ Object
Retrieve list of devices added to the specified distribution.
m2x.att.com/developer/documentation/v2/distribution#List-Devices-from-an-existing-Distribution
40 41 42 43 44 |
# File 'lib/m2x/distribution.rb', line 40 def devices(params={}) res = @client.get("#{path}/devices", params) res.json["devices"].map{ |atts| ::M2X::Client::Device.new(@client, atts) } if res.success? end |
#path ⇒ Object
33 34 35 |
# File 'lib/m2x/distribution.rb', line 33 def path @path ||= "#{ PATH }/#{ URI.encode(@attributes.fetch("id")) }" end |