Class: OpenMarket::SMS::Responses::MessageStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/open_market/sms/responses/message_status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, service_response) ⇒ MessageStatus

Returns a new instance of MessageStatus.



8
9
10
11
12
13
# File 'lib/open_market/sms/responses/message_status.rb', line 8

def initialize(request, service_response)
  @request = request
  @response = service_response

  parse_response
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/open_market/sms/responses/message_status.rb', line 6

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/open_market/sms/responses/message_status.rb', line 6

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/open_market/sms/responses/message_status.rb', line 6

def status
  @status
end

Instance Method Details

#delivery_dateObject



35
36
37
38
39
40
41
# File 'lib/open_market/sms/responses/message_status.rb', line 35

def delivery_date
  delivery_date = @delivery_status.dig('deliveryDate')

  return if delivery_date.nil? || delivery_date.empty?

  DateTime.parse(delivery_date)
end

#destinationObject



31
32
33
# File 'lib/open_market/sms/responses/message_status.rb', line 31

def destination
  @delivery_status.dig('destination', 'address')
end

#error_codeObject



51
52
53
# File 'lib/open_market/sms/responses/message_status.rb', line 51

def error_code
  body.dig('error', 'code')&.to_i
end

#error_messageObject



47
48
49
# File 'lib/open_market/sms/responses/message_status.rb', line 47

def error_message
  body.dig('error', 'description')
end

#message_statusObject



27
28
29
# File 'lib/open_market/sms/responses/message_status.rb', line 27

def message_status
  @delivery_status.dig('description')
end

#message_status_codeObject



23
24
25
# File 'lib/open_market/sms/responses/message_status.rb', line 23

def message_status_code
  @delivery_status.dig('code')&.to_i
end

#success?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/open_market/sms/responses/message_status.rb', line 15

def success?
  status == 200
end

#ticket_idObject



19
20
21
# File 'lib/open_market/sms/responses/message_status.rb', line 19

def ticket_id
  @request.ticket_id
end

#to_sObject



43
44
45
# File 'lib/open_market/sms/responses/message_status.rb', line 43

def to_s
  "Response: #{status}, #{error}"
end