class BrregGrunndata::Client::ResponseHeader

Represents a response header from brreg

A response header has a main status and sub statuses.

MAIN STATUS:

 0   -   OK
 1   -   OK, but some data is missing. See sub status for details
-1   -   An error as occured

@see www.brreg.no/produkter-og-tjenester/bestille/tilgang-til-enhetsregisteret-via-web-services/teknisk-beskrivelse-web-services/grunndataws/

Constants

MAIN_STATUS_SUCCESS_CODES

Public Class Methods

new(nori_response_header) click to toggle source
# File lib/brreg_grunndata/client/response_header.rb, line 18
def initialize(nori_response_header)
  @nori_response_header = nori_response_header
end

Public Instance Methods

inspect() click to toggle source

rubocop:disable Style/LineEndConcatenation

# File lib/brreg_grunndata/client/response_header.rb, line 45
def inspect
  "#<BrregGrunndata::ResponseHeader: main_status: #{main_status} " +
    "sub_statuses: #{sub_statuses}>"
end
main_status() click to toggle source
# File lib/brreg_grunndata/client/response_header.rb, line 27
def main_status
  @main_status ||= cast_to_int(@nori_response_header[:hoved_status])
end
sub_statuses() click to toggle source
# File lib/brreg_grunndata/client/response_header.rb, line 31
def sub_statuses
  return [] unless @nori_response_header.key? :under_status

  statuses = Array(@nori_response_header[:under_status][:under_status_melding])

  @sub_statuses ||= statuses.map do |status|
    {
      code: cast_to_int(status.attributes['kode']),
      message: status.to_s
    }
  end
end
success?() click to toggle source

Returns true if the brreg response header indicates success.

# File lib/brreg_grunndata/client/response_header.rb, line 23
def success?
  MAIN_STATUS_SUCCESS_CODES.include? main_status
end

Private Instance Methods

cast_to_int(v) click to toggle source

rubocop:enable Style/LineEndConcatenation

# File lib/brreg_grunndata/client/response_header.rb, line 53
def cast_to_int(v)
  Integer v, 10
end