Class: Fanforce::API::Results
- Inherits:
-
Array
- Object
- Array
- Fanforce::API::Results
- Defined in:
- lib/fanforce/api/response.rb
Instance Attribute Summary collapse
-
#requested_params ⇒ Object
readonly
Returns the value of attribute requested_params.
-
#requested_url ⇒ Object
readonly
Returns the value of attribute requested_url.
Instance Method Summary collapse
- #body ⇒ Object
- #code ⇒ Object
- #curl_command ⇒ Object
- #current_page ⇒ Object
- #current_results ⇒ Object
- #data ⇒ Object (also: #results)
-
#initialize(response_hash, response, request, requested_url, requested_params) ⇒ Results
constructor
A new instance of Results.
- #next_page ⇒ Object
- #next_page_url ⇒ Object
- #prev_page ⇒ Object
- #prev_page_url ⇒ Object
- #total_pages ⇒ Object
- #total_results ⇒ Object
Constructor Details
#initialize(response_hash, response, request, requested_url, requested_params) ⇒ Results
56 57 58 59 60 61 62 63 |
# File 'lib/fanforce/api/response.rb', line 56 def initialize(response_hash, response, request, requested_url, requested_params) @response = response @request = request @requested_url = requested_url @requested_params = requested_params @response_hash = response_hash self.replace(response_hash[:results]) end |
Instance Attribute Details
#requested_params ⇒ Object (readonly)
Returns the value of attribute requested_params.
54 55 56 |
# File 'lib/fanforce/api/response.rb', line 54 def requested_params @requested_params end |
#requested_url ⇒ Object (readonly)
Returns the value of attribute requested_url.
54 55 56 |
# File 'lib/fanforce/api/response.rb', line 54 def requested_url @requested_url end |
Instance Method Details
#body ⇒ Object
74 75 76 |
# File 'lib/fanforce/api/response.rb', line 74 def body; @response.to_s end |
#code ⇒ Object
109 |
# File 'lib/fanforce/api/response.rb', line 109 def code; @response.code end |
#curl_command ⇒ Object
70 71 72 |
# File 'lib/fanforce/api/response.rb', line 70 def curl_command @curl_command ||= Fanforce::Utils.curl_command(@request.method, @requested_url, @requested_params) end |
#current_page ⇒ Object
86 87 88 |
# File 'lib/fanforce/api/response.rb', line 86 def current_page; @current_page ||= @response_hash[:current_page] end |
#current_results ⇒ Object
78 79 80 |
# File 'lib/fanforce/api/response.rb', line 78 def current_results @current_results ||= @response_hash[:current_results] end |
#data ⇒ Object Also known as: results
65 66 67 |
# File 'lib/fanforce/api/response.rb', line 65 def data self end |
#next_page ⇒ Object
98 99 100 |
# File 'lib/fanforce/api/response.rb', line 98 def next_page @next_page ||= (@request.method == :get and total_pages > current_page) ? current_page + 1 : nil end |
#next_page_url ⇒ Object
106 107 108 |
# File 'lib/fanforce/api/response.rb', line 106 def next_page_url; @next_page_url ||= next_page ? "#{@requested_url}?#{Fanforce::Utils.to_query_string(@requested_params.merge(page: current_page+1))}" : nil end |
#prev_page ⇒ Object
94 95 96 |
# File 'lib/fanforce/api/response.rb', line 94 def prev_page @prev_page ||= (@request.method == :get and current_page > 1) ? current_page - 1 : nil end |
#prev_page_url ⇒ Object
102 103 104 |
# File 'lib/fanforce/api/response.rb', line 102 def prev_page_url; @prev_page_url ||= prev_page ? "#{@requested_url}?#{Fanforce::Utils.to_query_string(@requested_params.merge(page: current_page-1))}" : nil end |
#total_pages ⇒ Object
90 91 92 |
# File 'lib/fanforce/api/response.rb', line 90 def total_pages; @total_pages ||= @response_hash[:total_pages] end |
#total_results ⇒ Object
82 83 84 |
# File 'lib/fanforce/api/response.rb', line 82 def total_results; @total_results ||= @response_hash[:total_results] end |