class M2X::Client::Command

Wrapper for {m2x.att.com/developer/documentation/v2/commands M2X Commands} API

Constants

PATH

Attributes

attributes[R]

Public Class Methods

list(client, params={}) click to toggle source

Method for {m2x.att.com/developer/documentation/v2/commands#List-Sent-Commands List Sent Commands} endpoint. Retrieve the list of recent commands sent by the current user (as given by the API key).

@param {Client} client Client API @param params Query parameters passed as keyword arguments. View M2X API Docs for listing of available parameters. @return (Array) List of {Command} objects

# 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
new(client, attributes) click to toggle source
# File lib/m2x/command.rb, line 11
def initialize(client, attributes)
  @client     = client
  @attributes = attributes
end
send!(client, params) click to toggle source

Method for {m2x.att.com/developer/documentation/v2/commands#Send-Command 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.

@param {Client} client Client API @param params Query parameters passed as keyword arguments. View M2X API Docs for listing of available parameters. @return {Command} The Command that was just sent.

# File lib/m2x/command.rb, line 63
def send!(client, params)
  client.post(PATH, nil, params, "Content-Type" => "application/json")
end

Public Instance Methods

inspect() click to toggle source
# File lib/m2x/command.rb, line 33
def inspect
  "<#{self.class.name}: #{attributes.inspect}>"
end
path() click to toggle source
# File lib/m2x/command.rb, line 16
def path
  @path ||= "#{ PATH }/#{ URI.encode(@attributes.fetch("id")) }"
end
view() click to toggle source

Method for {m2x.att.com/developer/documentation/v2/commands#View-Command-Details 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.

@return {Command} The retrieved Command

# File lib/m2x/command.rb, line 27
def view
  res = @client.get(path)

  @attributes = res.json if res.success?
end