Class: Ticketbai::Api::ResponseParser
- Inherits:
-
Object
- Object
- Ticketbai::Api::ResponseParser
- Defined in:
- lib/ticketbai/api/response_parser.rb
Instance Method Summary collapse
- #identifier ⇒ Object
-
#initialize(raw_response) ⇒ ResponseParser
constructor
A new instance of ResponseParser.
- #message ⇒ Object
- #registries ⇒ Object
- #status ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(raw_response) ⇒ ResponseParser
Returns a new instance of ResponseParser.
4 5 6 |
# File 'lib/ticketbai/api/response_parser.rb', line 4 def initialize(raw_response) @raw_response = raw_response end |
Instance Method Details
#identifier ⇒ Object
12 13 14 |
# File 'lib/ticketbai/api/response_parser.rb', line 12 def identifier @raw_response.headers['eus-bizkaia-n3-identificativo'] end |
#message ⇒ Object
16 17 18 |
# File 'lib/ticketbai/api/response_parser.rb', line 16 def @raw_response.headers['eus-bizkaia-n3-mensaje-respuesta']&.force_encoding('ISO-8859-1')&.encode('UTF-8') end |
#registries ⇒ Object
20 21 22 23 24 |
# File 'lib/ticketbai/api/response_parser.rb', line 20 def registries return [] unless @raw_response.body Nokogiri::XML(@raw_response.body).css('Registros Registro').map { |attributes| Registry.new(attributes) } end |
#status ⇒ Object
8 9 10 |
# File 'lib/ticketbai/api/response_parser.rb', line 8 def status @raw_response.headers['eus-bizkaia-n3-tipo-respuesta'].downcase.to_sym end |
#to_h ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/ticketbai/api/response_parser.rb', line 26 def to_h { status: status, identifier: identifier, message: , registries: registries.map(&:to_h) } end |