Class: SearchApi::Response
- Inherits:
-
Object
- Object
- SearchApi::Response
- Defined in:
- lib/searchapi/response.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #credits_remaining ⇒ Object
-
#initialize(faraday_response) ⇒ Response
constructor
A new instance of Response.
- #results ⇒ Object
- #success? ⇒ Boolean
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/searchapi/response.rb', line 5 def data @data end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/searchapi/response.rb', line 5 def headers @headers end |
#status ⇒ Object (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_remaining ⇒ Object
21 22 23 |
# File 'lib/searchapi/response.rb', line 21 def credits_remaining headers["x-remaining-credits"]&.to_i end |
#results ⇒ Object
17 18 19 |
# File 'lib/searchapi/response.rb', line 17 def results data.is_a?(Hash) ? data : {} end |
#success? ⇒ Boolean
13 14 15 |
# File 'lib/searchapi/response.rb', line 13 def success? status == 200 end |