Class: FavroApi::Response
- Inherits:
-
Object
- Object
- FavroApi::Response
- Extended by:
- Forwardable
- Defined in:
- lib/favro_api/response.rb
Instance Attribute Summary collapse
-
#entities ⇒ Object
Returns the value of attribute entities.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#page ⇒ Object
Returns the value of attribute page.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#request_id ⇒ Object
Returns the value of attribute request_id.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #backend_identifier ⇒ Object
- #error? ⇒ Boolean
-
#initialize(opts = {}) ⇒ Response
constructor
A new instance of Response.
- #parse(type: nil) ⇒ Object
- #parsed_response ⇒ Object
- #ratelimit ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Response
Returns a new instance of Response.
9 10 11 |
# File 'lib/favro_api/response.rb', line 9 def initialize(opts = {}) self.response = opts.delete(:response) end |
Instance Attribute Details
#entities ⇒ Object
Returns the value of attribute entities.
5 6 7 |
# File 'lib/favro_api/response.rb', line 5 def entities @entities end |
#limit ⇒ Object
Returns the value of attribute limit.
5 6 7 |
# File 'lib/favro_api/response.rb', line 5 def limit @limit end |
#page ⇒ Object
Returns the value of attribute page.
5 6 7 |
# File 'lib/favro_api/response.rb', line 5 def page @page end |
#pages ⇒ Object
Returns the value of attribute pages.
5 6 7 |
# File 'lib/favro_api/response.rb', line 5 def pages @pages end |
#request_id ⇒ Object
Returns the value of attribute request_id.
5 6 7 |
# File 'lib/favro_api/response.rb', line 5 def request_id @request_id end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/favro_api/response.rb', line 5 def response @response end |
Instance Method Details
#backend_identifier ⇒ Object
35 36 37 |
# File 'lib/favro_api/response.rb', line 35 def backend_identifier response.headers['x-favro-backend-identifier'] end |
#error? ⇒ Boolean
13 14 15 |
# File 'lib/favro_api/response.rb', line 13 def error? status >= 400 end |
#parse(type: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/favro_api/response.rb', line 17 def parse(type: nil) self.entities = if type type.send(:parse, parsed_response['entities']) else parsed_response['entities'] end self.pages = parsed_response['pages'] self.page = parsed_response['page'] self.limit = parsed_response['limit'] self.request_id = parsed_response['requestId'] self end |
#parsed_response ⇒ Object
31 32 33 |
# File 'lib/favro_api/response.rb', line 31 def parsed_response @parsed_response ||= JSON.parse(body) end |
#ratelimit ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/favro_api/response.rb', line 39 def ratelimit { limit: response.headers['x-ratelimit-limit'].to_i, remaining: response.headers['x-ratelimit-remaining'].to_i, reset: Time.parse(response.headers['x-ratelimit-reset']) } end |