Class: M2X::Client::Command
- Inherits:
-
Object
- Object
- M2X::Client::Command
- Extended by:
- Forwardable
- Defined in:
- lib/m2x/command.rb
Overview
Wrapper for M2X Commands API
Constant Summary collapse
- PATH =
"/commands"
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
-
.list(client, params = {}) ⇒ Array
Method for List Sent Commands endpoint.
-
.send!(client, params) ⇒ Command
Method for Send Command endpoint.
Instance Method Summary collapse
-
#initialize(client, attributes) ⇒ Command
constructor
A new instance of Command.
- #inspect ⇒ Object
- #path ⇒ Object
-
#view ⇒ Command
Method for View Command Details endpoint.
Constructor Details
#initialize(client, attributes) ⇒ Command
Returns a new instance of Command.
11 12 13 14 |
# File 'lib/m2x/command.rb', line 11 def initialize(client, attributes) @client = client @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/m2x/command.rb', line 7 def attributes @attributes end |
Class Method Details
.list(client, params = {}) ⇒ Array
Method for List Sent Commands endpoint. Retrieve the list of recent commands sent by the current user (as given by the API key).
47 48 49 50 51 |
# File 'lib/m2x/command.rb', line 47 def list(client, params={}) res = client.get(PATH, params) res.json["commands"].map { |atts| new(client, atts) } if res.success? end |
.send!(client, params) ⇒ Command
Method for Send Command endpoint. Send a command with the given name to the given target devices. The name should be a custom string defined by the user and understood by the device.
63 64 65 |
# File 'lib/m2x/command.rb', line 63 def send!(client, params) client.post(PATH, nil, params, "Content-Type" => "application/json") end |
Instance Method Details
#inspect ⇒ Object
33 34 35 |
# File 'lib/m2x/command.rb', line 33 def inspect "<#{self.class.name}: #{attributes.inspect}>" end |
#path ⇒ Object
16 17 18 |
# File 'lib/m2x/command.rb', line 16 def path @path ||= "#{ PATH }/#{ URI.encode(@attributes.fetch("id")) }" end |
#view ⇒ Command
Method for View Command Details endpoint. Get details of a sent command including the delivery information for all devices that were targetted by the command at the time it was sent.
27 28 29 30 31 |
# File 'lib/m2x/command.rb', line 27 def view res = @client.get(path) @attributes = res.json if res.success? end |