Class: Firmenwissen::Response::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/firmenwissen/response/base.rb

Direct Known Subclasses

Mock

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Base

Returns a new instance of Base.



6
7
8
9
# File 'lib/firmenwissen/response/base.rb', line 6

def initialize(http_response)
  @http_response = http_response
  @suggestions = build_suggestions
end

Instance Attribute Details

#suggestionsObject (readonly)

Returns the value of attribute suggestions.



4
5
6
# File 'lib/firmenwissen/response/base.rb', line 4

def suggestions
  @suggestions
end

Instance Method Details

#dataObject



11
12
13
14
15
# 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_codeObject



17
18
19
# File 'lib/firmenwissen/response/base.rb', line 17

def status_code
  http_response.code
end

#successful?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/firmenwissen/response/base.rb', line 21

def successful?
  status_code == '200'
end