module OpenMarket module SMS module Responses class MessageStatus attr_reader :status, :headers, :body def initialize(request, service_response) @request = request @response = service_response parse_response end def success? status == 200 end def ticket_id @request.ticket_id end def message_status_code @delivery_status.dig('code')&.to_i end def message_status @delivery_status.dig('description') end def destination @delivery_status.dig('destination', 'address') end def delivery_date delivery_date = @delivery_status.dig('deliveryDate') return if delivery_date.nil? || delivery_date.empty? DateTime.parse(delivery_date) end def to_s "Response: #{status}, #{error}" end def error_message body.dig('error', 'description') end def error_code body.dig('error', 'code')&.to_i end private def parse_response @status = @response.status parse_body parse_delivery_status end def parse_body @body = \ if !@response.body || @response.body.empty? {} else JSON.parse(@response.body) end end def parse_delivery_status @delivery_status = @body.dig('mtStatus') end end end end end