Class: EventMachine::Smsified::DeliveryInfoNotification

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 a Delivery Info Notification. Note: This class only pulls the first delivery info object from the notification. There can be more as per the spec. smsified.com/sms-api-documentation/sending#checking_status

Examples:

del = DeliveryInfoNotification.new(json)
puts del.message # foobar

Parameters:

  • valid (required, String)

    JSON for an Delivery Info Notifcation to be parsed

Raises:

  • (ArgumentError)

    if json is not valid JSON or an Delivery Info Notifcation type



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/em-smsified/incoming_message.rb', line 20

def initialize(json)
  begin
    @json = JSON.parse json
    contents = @json['deliveryInfoNotification']['deliveryInfo']

    @delivery_status = contents['deliveryStatus']
    @code = contents['code']
    @message_id = contents['messageId']
    @sender_address = contents['senderAddress']
    @address = contents['address']
    @created_date_time = Time.parse contents['createdDateTime']
    @sent_date_time = Time.parse contents['sentDateTime']
    @parts = contents['parts']
    @direction = contents['direction']
    @message = contents['message']
  rescue => error
    raise EventMachine::Smsified::MessageError, "Not valid JSON or DeliveryInfoNotification"
  end          
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



7
8
9
# File 'lib/em-smsified/incoming_message.rb', line 7

def address
  @address
end

#codeObject (readonly)

Returns the value of attribute code.



7
8
9
# File 'lib/em-smsified/incoming_message.rb', line 7

def code
  @code
end

#created_date_timeObject (readonly)

Returns the value of attribute created_date_time.



7
8
9
# File 'lib/em-smsified/incoming_message.rb', line 7

def created_date_time
  @created_date_time
end

#delivery_statusObject (readonly)

Returns the value of attribute delivery_status.



7
8
9
# File 'lib/em-smsified/incoming_message.rb', line 7

def delivery_status
  @delivery_status
end

#directionObject (readonly)

Returns the value of attribute direction.



7
8
9
# File 'lib/em-smsified/incoming_message.rb', line 7

def direction
  @direction
end

#messageObject (readonly)

Returns the value of attribute message.



7
8
9
# File 'lib/em-smsified/incoming_message.rb', line 7

def message
  @message
end

#message_idObject (readonly)

Returns the value of attribute message_id.



7
8
9
# File 'lib/em-smsified/incoming_message.rb', line 7

def message_id
  @message_id
end

#partsObject (readonly)

Returns the value of attribute parts.



7
8
9
# File 'lib/em-smsified/incoming_message.rb', line 7

def parts
  @parts
end

#sender_addressObject (readonly)

Returns the value of attribute sender_address.



7
8
9
# File 'lib/em-smsified/incoming_message.rb', line 7

def sender_address
  @sender_address
end

#sent_date_timeObject (readonly)

Returns the value of attribute sent_date_time.



7
8
9
# File 'lib/em-smsified/incoming_message.rb', line 7

def sent_date_time
  @sent_date_time
end