Class: SearchApi::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(faraday_response) ⇒ Response

Returns a new instance of Response.



7
8
9
10
11
# File 'lib/searchapi/response.rb', line 7

def initialize(faraday_response)
  @data    = faraday_response.body
  @status  = faraday_response.status
  @headers = faraday_response.headers
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/searchapi/response.rb', line 5

def data
  @data
end

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/searchapi/response.rb', line 5

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/searchapi/response.rb', line 5

def status
  @status
end

Instance Method Details

#credits_remainingObject



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

def credits_remaining
  headers["x-remaining-credits"]&.to_i
end

#resultsObject



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

def results
  data.is_a?(Hash) ? data : {}
end

#success?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/searchapi/response.rb', line 13

def success?
  status == 200
end