Class: Foederati::Provider::Response
- Inherits:
-
Object
- Object
- Foederati::Provider::Response
- Defined in:
- lib/foederati/provider/response.rb
Overview
Contains a response from a request to a provider’s API
Returned by ‘Foederati::Provider::Request#execute`.
Instance Attribute Summary collapse
-
#faraday_response ⇒ Object
readonly
Returns the value of attribute faraday_response.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Instance Method Summary collapse
-
#initialize(provider, faraday_response) ⇒ Response
constructor
A new instance of Response.
-
#normalise ⇒ Hash
(also: #to_h)
Normalises response from provider’s API.
Constructor Details
#initialize(provider, faraday_response) ⇒ Response
Returns a new instance of Response.
16 17 18 19 |
# File 'lib/foederati/provider/response.rb', line 16 def initialize(provider, faraday_response) @provider = provider @faraday_response = faraday_response end |
Instance Attribute Details
#faraday_response ⇒ Object (readonly)
Returns the value of attribute faraday_response.
9 10 11 |
# File 'lib/foederati/provider/response.rb', line 9 def faraday_response @faraday_response end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
9 10 11 |
# File 'lib/foederati/provider/response.rb', line 9 def provider @provider end |
Instance Method Details
#normalise ⇒ Hash Also known as: to_h
Normalises response from provider’s API
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/foederati/provider/response.rb', line 25 def normalise { id => { total: fetch_from_response(results.total, body) || 0, results: items_from_response.map do |item| { title: fetch_from_response(fields.title, item), thumbnail: fetch_from_response(fields.thumbnail, item), url: fetch_from_response(fields.url, item) } end } } end |