Class: Ticketbai::Api::ResponseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ticketbai/api/response_parser.rb

Instance Method Summary collapse

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

#identifierObject



12
13
14
# File 'lib/ticketbai/api/response_parser.rb', line 12

def identifier
  @raw_response.headers['eus-bizkaia-n3-identificativo']
end

#messageObject



16
17
18
# File 'lib/ticketbai/api/response_parser.rb', line 16

def message
  @raw_response.headers['eus-bizkaia-n3-mensaje-respuesta']&.force_encoding('ISO-8859-1')&.encode('UTF-8')
end

#registriesObject



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

#statusObject



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_hObject



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: message,
    registries: registries.map(&:to_h)
  }
end