class BrregGrunndata::Client::Response
Wrapper around Savon's response
Handles unwrapping of XML returned as string
Public Class Methods
new(savon_response)
click to toggle source
# File lib/brreg_grunndata/client/response.rb, line 36 def initialize(savon_response) @savon_response = savon_response end
Public Instance Methods
header()
click to toggle source
Returns the header from brreg's response
The header contains the overall success of the SOAP operation. The header is something brreg's SOAP API has, so all in all we have http status, soap status and then this status located within the header :(
# File lib/brreg_grunndata/client/response.rb, line 57 def header raise ResponseFailureError unless @savon_response.success? ResponseHeader.new response_grunndata[:response_header] end
message()
click to toggle source
Returns the header from brreg's response
Keys are symbolized.
@return Hash
# File lib/brreg_grunndata/client/response.rb, line 68 def message raise ResponseFailureError unless success? @message ||= response_grunndata[:melding] || raise(MessageEmptyError) end
success?()
click to toggle source
Do we have a successful response?
We do if:
- We have no HTTP errors or SOAP faults. Savon handles this for us. - We have a response_header in the document returned from brreg which indicates success too. I don't know why BRREG needs this in addition to HTTP status codes and SOAP faults to communicate success or not :-(
# File lib/brreg_grunndata/client/response.rb, line 48 def success? @savon_response.success? && header.success? end
Private Instance Methods
parse(xml)
click to toggle source
# File lib/brreg_grunndata/client/response.rb, line 80 def parse(xml) parser = Nori.new( strip_namespaces: true, advanced_typecasting: true, convert_tags_to: ->(tag) { tag.underscore.to_sym } ) parser.parse xml end
response_grunndata()
click to toggle source
# File lib/brreg_grunndata/client/response.rb, line 76 def response_grunndata @response_grunndata ||= parse(body.values.first[:return])[:grunndata] end