class Firmenwissen::Response::Base

Attributes

http_response[R]
suggestions[R]

Public Class Methods

new(http_response) click to toggle source
# File lib/firmenwissen/response/base.rb, line 6
def initialize(http_response)
  @http_response = http_response
  @suggestions = build_suggestions
end

Public Instance Methods

data() click to toggle source
# File lib/firmenwissen/response/base.rb, line 11
def data
  @data ||= parsed_response.map { |hash| map_keys(hash) }
rescue JSON::ParserError
  raise UnprocessableResponseError, "The response from Firmenwissen could not be processed:\n#{body}"
end
status_code() click to toggle source
# File lib/firmenwissen/response/base.rb, line 17
def status_code
  http_response.code
end
successful?() click to toggle source
# File lib/firmenwissen/response/base.rb, line 21
def successful?
  status_code == '200'
end

Private Instance Methods

body() click to toggle source
# File lib/firmenwissen/response/base.rb, line 29
def body
  http_response.body
end
build_suggestions() click to toggle source
# File lib/firmenwissen/response/base.rb, line 33
def build_suggestions
  data.map { |suggestion| Suggestion.new(suggestion) }
end
map_keys(hash) click to toggle source
# File lib/firmenwissen/response/base.rb, line 37
def map_keys(hash)
  KeyMapper.from_api(hash)
end
parsed_response() click to toggle source
# File lib/firmenwissen/response/base.rb, line 41
def parsed_response
  JSON.parse(body).fetch('companyNameSuggestions', [])
end