class EventMachine::Smsified::IncomingMessage

Attributes

date_time[R]
destination_address[R]
json[R]
message[R]
message_id[R]
sender_address[R]

Public Class Methods

new(json) click to toggle source

Intantiate a new object to provide convenience methods on an Incoming Message www.smsified.com/sms-api-documentation/receiving

@param [required, String] valid JSON for an Incoming Message to be parsed @return [Object] the parsed incoming message @raise [ArgumentError] if json is not valid JSON or an Incoming Message type @example

incoming_message = IncomingMessage.new(json)
puts incoming_message.message # foobar
# File lib/em-smsified/incoming_message.rb, line 53
def initialize(json)
  begin
    @json                = JSON.parse json
    
    contents             = @json['inboundSMSMessageNotification']['inboundSMSMessage']
    
    @date_time           = Time.parse contents['dateTime']
    @destination_address = contents['destinationAddress']
    @message             = contents['message']
    @message_id          = contents['messageId']
    @sender_address      = contents['senderAddress']
  rescue => error
    raise EventMachine::Smsified::MessageError, "Not valid JSON or IncomingMessage"
  end
end