Class: M2X::Client::Distribution
- Includes:
- Metadata
- Defined in:
- lib/m2x/distribution.rb
Overview
Wrapper for M2X Distribution API
Constant Summary collapse
- PATH =
"/distributions"
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
-
.create!(client, params) ⇒ Distribution
Method for Create Distribution endpoint.
-
.list(client, params = {}) ⇒ Array
(also: search)
Method for List Distributions endpoint.
Instance Method Summary collapse
-
#add_device(serial) ⇒ Device
Method for Add Device to an existing Distribution endpoint.
-
#devices(params = {}) ⇒ Array
Method for List Devices from an existing Distribution endpoint.
- #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) ⇒ Distribution
Method for Create Distribution endpoint.
34 35 36 37 38 |
# File 'lib/m2x/distribution.rb', line 34 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 = {}) ⇒ Array Also known as: search
Method for List Distributions endpoint. Retrieve list of device distributions accessible by the authenticated API key.
20 21 22 23 24 |
# File 'lib/m2x/distribution.rb', line 20 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) ⇒ Device
Method for Add Device to an existing Distribution endpoint.
63 64 65 66 67 |
# File 'lib/m2x/distribution.rb', line 63 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 = {}) ⇒ Array
Method for List Devices from an existing Distribution endpoint.
51 52 53 54 55 |
# File 'lib/m2x/distribution.rb', line 51 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
41 42 43 |
# File 'lib/m2x/distribution.rb', line 41 def path @path ||= "#{ PATH }/#{ URI.encode(@attributes.fetch("id")) }" end |