Class: M2X::Client::Command
- Inherits:
-
Object
- Object
- M2X::Client::Command
- Extended by:
- Forwardable
- Defined in:
- lib/m2x/command.rb
Overview
Wrapper for AT&T M2X Commands API m2x.att.com/developer/documentation/v2/commands
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 = {}) ⇒ Object
List Sent Commands.
-
.send!(client, params) ⇒ Object
Send Command.
Instance Method Summary collapse
-
#initialize(client, attributes) ⇒ Command
constructor
A new instance of Command.
- #inspect ⇒ Object
- #path ⇒ Object
-
#view ⇒ Object
View Command Details.
Constructor Details
#initialize(client, attributes) ⇒ Command
Returns a new instance of Command.
12 13 14 15 |
# File 'lib/m2x/command.rb', line 12 def initialize(client, attributes) @client = client @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/m2x/command.rb', line 8 def attributes @attributes end |
Class Method Details
.list(client, params = {}) ⇒ Object
List Sent Commands
Retrieve the list of recent commands sent by the current user (as given by the API key).
m2x.att.com/developer/documentation/v2/commands#List-Sent-Commands
44 45 46 47 48 |
# File 'lib/m2x/command.rb', line 44 def list(client, params={}) res = client.get(PATH, params) res.json["commands"].map { |atts| new(client, atts) } if res.success? end |
.send!(client, params) ⇒ Object
Send Command
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.
m2x.att.com/developer/documentation/v2/commands#Send-Command
57 58 59 |
# File 'lib/m2x/command.rb', line 57 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
17 18 19 |
# File 'lib/m2x/command.rb', line 17 def path @path ||= "#{ PATH }/#{ URI.encode(@attributes.fetch("id")) }" end |
#view ⇒ Object
View Command Details
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.
m2x.att.com/developer/documentation/v2/commands#View-Command-Details
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 |