class Sms160::Message

Attributes

body[RW]
reply_to[RW]
to[RW]

Public Class Methods

new(attr = {}) click to toggle source
# File lib/sms160/message.rb, line 9
def initialize(attr = {})
  attr.each do |k, v|
    self.send("#{k}=", v)
  end
end

Public Instance Methods

bulk_send!() click to toggle source
# File lib/sms160/message.rb, line 39
def bulk_send!
  raise "Incomplete PARAMETERS errors" unless to and body and reply_to

  options = fetch_credentials.merge!(messageText: body, sms2way: reply_to)

  to.each do |recipient|
    options.merge!("mobileNumber[#{recipient.object_id}]" => recipient)
  end

  response = RestClient.post(SEND_MESSAGE_ENDPOINT, options)
  result = Hash.from_xml(response)["string"]["result"]["status"] rescue nil

  result
end
credit_balance() click to toggle source
# File lib/sms160/message.rb, line 15
def credit_balance
  response = RestClient.get(BALANCE_ENDPOINT, params: fetch_credentials)
  Hash.from_xml(response)["string"]
end
message_status(message_id) click to toggle source
# File lib/sms160/message.rb, line 54
def message_status(message_id)
  response = RestClient.get(MESSAGE_STATUS_ENDPOINT, params: fetch_credentials.merge!(messageId: message_id))
  Hash.from_xml(response)["string"]
end
send_message() click to toggle source
# File lib/sms160/message.rb, line 20
def send_message                                                                    
  raise "Incomplete Parameters ERROR" unless to and body and reply_to                  
  
  options = fetch_credentials.merge!(mobileNumber: to, messageText: body, sms2way: reply_to)
  response = RestClient.post(SEND_MESSAGE_ENDPOINT, options)

  if response.code.to_i == 200                                                         
    response = Hash.from_xml(response)["string"]                                       
      
    if response.include?("ERR") or API_ERROR.include?(response)                        
      false
    else
      response
    end
  else
    false
  end
end

Private Instance Methods

fetch_credentials() click to toggle source
# File lib/sms160/message.rb, line 61
def fetch_credentials
  { username: Sms160.configuration.username, password: Sms160.configuration.password }
end