Method: TextMagic::API#message_status

Defined in:
lib/textmagic/api.rb

#message_status(*ids) ⇒ Object Also known as: status

Executes a message_status command by sending a request to the TextMagic’s SMS gateway.

If called with a single id, this method returns a single string value denoting the message status. This string is extended with custom attributes text, status, created_time, completed_time, reply_number and credits_cost. If called with multiple ids, it returns a hash of such strings with message ids as keys. In case the request to the SMS gateway is not successful or the server returns an error response, an Error is raised.

Example usage:

status = api.message_status("141421")
# => "d"
status.completed_time
# => Fri May 22 10:10:18 +0200 2009

Example with multiple ids:

statuses = api.message_status("141421", "173205")
# => { "141421" => "r", "173205" => "d" }
statuses["141421"].text
# => "Hi Wilma"
statuses["173205"].created_time
# => Thu May 28 16:41:45 +0200 2009

Multiple ids can be supplied as an array or as a list of arguments:

api.send("Hello everybody", ["999314159265", "999271828182"])
api.send("Hello everybody", "999314159265", "999271828182")

If you want to request status for a single message but still want to get a hash response, put the id in an array:

api.message_status(["141421"])

It is strongly encouraged to setup callbacks to receive updates on message status instead of using this method.



140
141
142
143
144
145
146
# File 'lib/textmagic/api.rb', line 140

def message_status(*ids)
  single = ids.size == 1 && ids.first.is_a?(String)
  ids.flatten!
  raise TextMagic::API::Error.new(4, "Insufficient parameters") if ids.empty?
  hash = Executor.execute("message_status", @username, @password, ids: ids.join(","))
  TextMagic::API::Response.message_status(hash, single)
end