Class: EventMachine::Smsified::IncomingMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/em-smsified/incoming_message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Object

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

Examples:

incoming_message = IncomingMessage.new(json)
puts incoming_message.message # foobar

Parameters:

  • valid (required, String)

    JSON for an Incoming Message to be parsed

Raises:

  • (ArgumentError)

    if json is not valid JSON or an Incoming Message type



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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

Instance Attribute Details

#date_timeObject (readonly)

Returns the value of attribute date_time.



41
42
43
# File 'lib/em-smsified/incoming_message.rb', line 41

def date_time
  @date_time
end

#destination_addressObject (readonly)

Returns the value of attribute destination_address.



41
42
43
# File 'lib/em-smsified/incoming_message.rb', line 41

def destination_address
  @destination_address
end

#jsonObject (readonly)

Returns the value of attribute json.



41
42
43
# File 'lib/em-smsified/incoming_message.rb', line 41

def json
  @json
end

#messageObject (readonly)

Returns the value of attribute message.



41
42
43
# File 'lib/em-smsified/incoming_message.rb', line 41

def message
  @message
end

#message_idObject (readonly)

Returns the value of attribute message_id.



41
42
43
# File 'lib/em-smsified/incoming_message.rb', line 41

def message_id
  @message_id
end

#sender_addressObject (readonly)

Returns the value of attribute sender_address.



41
42
43
# File 'lib/em-smsified/incoming_message.rb', line 41

def sender_address
  @sender_address
end