Class: M2X::Client
- Inherits:
-
Object
- Object
- M2X::Client
- Defined in:
- lib/m2x/client.rb,
lib/m2x/version.rb
Overview
Interface for connecting with M2X API service.
This class provides convenience methods to access M2X most common resources. It can also be used to access any endpoint directly like this:
m2x = M2X::Client.new("<YOUR-API-KEY>")
m2x.get("/some_path")
Defined Under Namespace
Modules: Metadata Classes: Collection, Command, Device, Distribution, Integration, 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.8.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_integration(params) ⇒ Object
Creates a new integration 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.
-
#integration(id) ⇒ Object
Obtain an Integration from M2X.
-
#integrations ⇒ Object
Retrieve list of integrations associated with the user account.
-
#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 ⇒ Response
Returns the status of the M2X system.
-
#time ⇒ Response
Method for Time API.
-
#time_iso8601 ⇒ Response
Method for Time API.
-
#time_millis ⇒ Response
Method for Time API.
-
#time_seconds ⇒ Response
Method for Time API.
Constructor Details
#initialize(api_key = nil, api_base = nil) ⇒ Client
Returns a new instance of Client.
25 26 27 28 29 |
# File 'lib/m2x/client.rb', line 25 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
21 22 23 |
# File 'lib/m2x/client.rb', line 21 def api_base=(value) @api_base = value end |
#api_key ⇒ Object
Returns the value of attribute api_key.
20 21 22 |
# File 'lib/m2x/client.rb', line 20 def api_key @api_key end |
#api_version=(value) ⇒ Object
Sets the attribute api_version
22 23 24 |
# File 'lib/m2x/client.rb', line 22 def api_version=(value) @api_version = value end |
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
23 24 25 |
# File 'lib/m2x/client.rb', line 23 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
45 46 47 |
# File 'lib/m2x/client.rb', line 45 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
59 60 61 |
# File 'lib/m2x/client.rb', line 59 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
74 75 76 |
# File 'lib/m2x/client.rb', line 74 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
66 67 68 |
# File 'lib/m2x/client.rb', line 66 def commands(params={}) M2X::Client::Command.list(self, params) end |
#create_collection(params) ⇒ Object
Creates a new collection on M2X with the specified parameters
See M2X::Client::Collection.create! for more details
52 53 54 |
# File 'lib/m2x/client.rb', line 52 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
See M2X::Client::Device.create! for more details
96 97 98 |
# File 'lib/m2x/client.rb', line 96 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
See M2X::Client::Distribution.create! for more details.
139 140 141 |
# File 'lib/m2x/client.rb', line 139 def create_distribution(params) M2X::Client::Distribution.create!(self, params) end |
#create_integration(params) ⇒ Object
Creates a new integration on M2X with the specified parameters
See M2X::Client::Integration.create! for more details
197 198 199 |
# File 'lib/m2x/client.rb', line 197 def create_integration(params) M2X::Client::Integration.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
174 175 176 |
# File 'lib/m2x/client.rb', line 174 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
89 90 91 |
# File 'lib/m2x/client.rb', line 89 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
123 124 125 |
# File 'lib/m2x/client.rb', line 123 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
103 104 105 |
# File 'lib/m2x/client.rb', line 103 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
132 133 134 |
# File 'lib/m2x/client.rb', line 132 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
147 148 149 |
# File 'lib/m2x/client.rb', line 147 def distributions(params={}) M2X::Client::Distribution.list(self, params) end |
#integration(id) ⇒ Object
Obtain an Integration from M2X
This method instantiates an instance of Integration and calls ‘Integration#view` method, returning the integration instance with all its attributes initialized
190 191 192 |
# File 'lib/m2x/client.rb', line 190 def integration(id) M2X::Client::Integration.new(self, "id" => id).tap(&:view) end |
#integrations ⇒ Object
Retrieve list of integrations associated with the user account.
See M2X::Client::Integration.list for more details
204 205 206 |
# File 'lib/m2x/client.rb', line 204 def integrations M2X::Client::Integration.list(self) 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
155 156 157 |
# File 'lib/m2x/client.rb', line 155 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
164 165 166 |
# File 'lib/m2x/client.rb', line 164 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
181 182 183 |
# File 'lib/m2x/client.rb', line 181 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
111 112 113 |
# File 'lib/m2x/client.rb', line 111 def search_devices(params={}) M2X::Client::Device.list(self, params) end |
#send_command(params) ⇒ Object
Send command
See M2X::Client::Command.send! for more details
81 82 83 |
# File 'lib/m2x/client.rb', line 81 def send_command(params) M2X::Client::Command.send!(self, params) end |
#status ⇒ Response
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.
37 38 39 |
# File 'lib/m2x/client.rb', line 37 def status get("/status") end |
#time ⇒ Response
Method for Time API
211 212 213 |
# File 'lib/m2x/client.rb', line 211 def time get("/time").json end |
#time_iso8601 ⇒ Response
Method for Time API
232 233 234 |
# File 'lib/m2x/client.rb', line 232 def time_iso8601 get("/time/iso8601").raw end |