Class: M2X::Client
- Inherits:
-
Object
- Object
- M2X::Client
- Defined in:
- lib/m2x/client.rb,
lib/m2x/version.rb
Overview
Defined Under Namespace
Modules: Metadata Classes: Collection, Command, Device, Distribution, Job, Key, Resource, Response, Stream
Constant Summary collapse
- DEFAULT_API_BASE =
"https://api-m2x.att.com".freeze
- DEFAULT_API_VERSION =
"v2".freeze
- CA_FILE =
File.("../cacert.pem", __FILE__)
- USER_AGENT =
"M2X-Ruby/#{M2X::Client::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} (#{RUBY_PLATFORM})".freeze
- VERSION =
"2.6.0"
Instance Attribute Summary collapse
-
#api_base ⇒ Object
writeonly
Sets the attribute api_base.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_version ⇒ Object
writeonly
Sets the attribute api_version.
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
Instance Method Summary collapse
-
#collection(id) ⇒ Object
Obtain a Collection from M2X.
-
#collections(params = {}) ⇒ Object
Retrieve the list of collections accessible by the authenticated API key.
-
#command(id) ⇒ Object
View Command Details.
-
#commands(params = {}) ⇒ Object
List Sent Commands.
-
#create_collection(params) ⇒ Object
Creates a new collection on M2X with the specified parameters.
-
#create_device(params) ⇒ Object
Creates a new device on M2X with the specified parameters.
-
#create_distribution(params) ⇒ Object
Creates a new device distribution on M2X with the specified parameters.
-
#create_key(params) ⇒ Object
Create a new API Key.
-
#device(id) ⇒ Object
Obtain a Device from M2X.
-
#device_catalog(params = {}) ⇒ Object
Search the catalog of public Devices.
-
#devices(params = {}) ⇒ Object
Retrieve the list of devices accessible by the authenticated API key.
-
#distribution(id) ⇒ Object
Obtain a Distribution from M2X.
-
#distributions(params = {}) ⇒ Object
Retrieve list of device distributions accessible by the authenticated API key.
-
#initialize(api_key = nil, api_base = nil) ⇒ Client
constructor
A new instance of Client.
-
#job(id) ⇒ Object
Obtain a Job from M2X.
-
#key(key) ⇒ Object
Obtain an API Key from M2X.
-
#keys ⇒ Object
Retrieve list of keys associated with the user account.
-
#search_devices(params = {}) ⇒ Object
Retrieve the list of devices accessible by the authenticated API key that meet the search criteria.
-
#send_command(params) ⇒ Object
Send command.
-
#status ⇒ Object
Returns the status of the M2X system.
- #time ⇒ Object
- #time_iso8601 ⇒ Object
- #time_millis ⇒ Object
- #time_seconds ⇒ Object
Constructor Details
#initialize(api_key = nil, api_base = nil) ⇒ Client
Returns a new instance of Client.
26 27 28 29 30 |
# File 'lib/m2x/client.rb', line 26 def initialize(api_key=nil, api_base=nil) @api_key = api_key @api_base = api_base @api_version = api_version end |
Instance Attribute Details
#api_base=(value) ⇒ Object
Sets the attribute api_base
22 23 24 |
# File 'lib/m2x/client.rb', line 22 def api_base=(value) @api_base = value end |
#api_key ⇒ Object
Returns the value of attribute api_key.
21 22 23 |
# File 'lib/m2x/client.rb', line 21 def api_key @api_key end |
#api_version=(value) ⇒ Object
Sets the attribute api_version
23 24 25 |
# File 'lib/m2x/client.rb', line 23 def api_version=(value) @api_version = value end |
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
24 25 26 |
# File 'lib/m2x/client.rb', line 24 def last_response @last_response end |
Instance Method Details
#collection(id) ⇒ Object
Obtain a Collection from M2X
This method instantiates an instance of Collection and calls ‘Collection#view` method, returning the collection instance with all its attributes initialized
44 45 46 |
# File 'lib/m2x/client.rb', line 44 def collection(id) M2X::Client::Collection.new(self, "id" => id).tap(&:view) end |
#collections(params = {}) ⇒ Object
Retrieve the list of collections accessible by the authenticated API key
See M2X::Client::Collection.list for more details
56 57 58 |
# File 'lib/m2x/client.rb', line 56 def collections(params={}) M2X::Client::Collection.list(self, params) end |
#command(id) ⇒ Object
View Command Details
This method instantiates an instance of Command and calls ‘Command#view` method, returning the command instance with all its attributes initialized
71 72 73 |
# File 'lib/m2x/client.rb', line 71 def command(id) M2X::Client::Command.new(self, "id" => id).tap(&:view) end |
#commands(params = {}) ⇒ Object
List Sent Commands
See M2X::Client::Command.list for more details
63 64 65 |
# File 'lib/m2x/client.rb', line 63 def commands(params={}) M2X::Client::Command.list(self, params) end |
#create_collection(params) ⇒ Object
Creates a new collection on M2X with the specified parameters
49 50 51 |
# File 'lib/m2x/client.rb', line 49 def create_collection(params) M2X::Client::Collection.create!(self, params) end |
#create_device(params) ⇒ Object
Creates a new device on M2X with the specified parameters
89 90 91 |
# File 'lib/m2x/client.rb', line 89 def create_device(params) M2X::Client::Device.create!(self, params) end |
#create_distribution(params) ⇒ Object
Creates a new device distribution on M2X with the specified parameters
130 131 132 |
# File 'lib/m2x/client.rb', line 130 def create_distribution(params) M2X::Client::Distribution.create!(self, params) end |
#create_key(params) ⇒ Object
Create a new API Key
Note that, according to the parameters sent, you can create a Master API Key or a Device/Stream API Key.
See M2X::Client::Key.create! for more details
165 166 167 |
# File 'lib/m2x/client.rb', line 165 def create_key(params) M2X::Client::Key.create!(self, params) end |
#device(id) ⇒ Object
Obtain a Device from M2X
This method instantiates an instance of Device and calls ‘Device#view` method, returning the device instance with all its attributes initialized
84 85 86 |
# File 'lib/m2x/client.rb', line 84 def device(id) M2X::Client::Device.new(self, "id" => id).tap(&:view) end |
#device_catalog(params = {}) ⇒ Object
Search the catalog of public Devices.
This allows unauthenticated users to search Devices from other users that have been marked as public, allowing them to read public Device metadata, locations, streams list, and view each Devices’ stream metadata and its values.
See M2X::Client::Device.catalog for more details
116 117 118 |
# File 'lib/m2x/client.rb', line 116 def device_catalog(params={}) M2X::Client::Device.catalog(self, params) end |
#devices(params = {}) ⇒ Object
Retrieve the list of devices accessible by the authenticated API key
See M2X::Client::Device.list for more details
96 97 98 |
# File 'lib/m2x/client.rb', line 96 def devices(params={}) M2X::Client::Device.list(self, params) end |
#distribution(id) ⇒ Object
Obtain a Distribution from M2X
This method instantiates an instance of Distribution and calls ‘Distribution#view` method, returning the device instance with all its attributes initialized
125 126 127 |
# File 'lib/m2x/client.rb', line 125 def distribution(id) M2X::Client::Distribution.new(self, "id" => id).tap(&:view) end |
#distributions(params = {}) ⇒ Object
Retrieve list of device distributions accessible by the authenticated API key.
See M2X::Client::Distribution.list for more details
138 139 140 |
# File 'lib/m2x/client.rb', line 138 def distributions(params={}) M2X::Client::Distribution.list(self, params) end |
#job(id) ⇒ Object
Obtain a Job from M2X
This method instantiates an instance of Job and calls ‘Job#view` method, returning the job instance with all its attributes initialized
146 147 148 |
# File 'lib/m2x/client.rb', line 146 def job(id) M2X::Client::Job.new(self, "id" => id).tap(&:view) end |
#key(key) ⇒ Object
Obtain an API Key from M2X
This method instantiates an instance of Key and calls ‘Key#view` method, returning the key instance with all its attributes initialized
155 156 157 |
# File 'lib/m2x/client.rb', line 155 def key(key) M2X::Client::Key.new(self, "key" => key).tap(&:view) end |
#keys ⇒ Object
Retrieve list of keys associated with the user account.
See M2X::Client::Key.list for more details
172 173 174 |
# File 'lib/m2x/client.rb', line 172 def keys M2X::Client::Key.list(self) end |
#search_devices(params = {}) ⇒ Object
Retrieve the list of devices accessible by the authenticated API key that meet the search criteria.
See M2X::Client::Device.search for more details
104 105 106 |
# File 'lib/m2x/client.rb', line 104 def search_devices(params={}) M2X::Client::Device.list(self, params) end |
#send_command(params) ⇒ Object
Send command
76 77 78 |
# File 'lib/m2x/client.rb', line 76 def send_command(params) M2X::Client::Command.send!(self, params) end |
#status ⇒ Object
Returns the status of the M2X system.
The response to this endpoint is an object in which each of its attributes represents an M2X subsystem and its current status.
36 37 38 |
# File 'lib/m2x/client.rb', line 36 def status get("/status") end |
#time ⇒ Object
176 177 178 |
# File 'lib/m2x/client.rb', line 176 def time get("/time").json end |
#time_iso8601 ⇒ Object
188 189 190 |
# File 'lib/m2x/client.rb', line 188 def time_iso8601 get("/time/iso8601").raw end |
#time_millis ⇒ Object
184 185 186 |
# File 'lib/m2x/client.rb', line 184 def time_millis get("/time/millis").raw end |
#time_seconds ⇒ Object
180 181 182 |
# File 'lib/m2x/client.rb', line 180 def time_seconds get("/time/seconds").raw end |