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
69 70 71 72 73 74 75 76 |
# File 'lib/fanforce/api/response.rb', line 69 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.
67 68 69 |
# File 'lib/fanforce/api/response.rb', line 67 def requested_params @requested_params end |
#requested_url ⇒ Object (readonly)
Returns the value of attribute requested_url.
67 68 69 |
# File 'lib/fanforce/api/response.rb', line 67 def requested_url @requested_url end |
Instance Method Details
#body ⇒ Object
87 88 89 |
# File 'lib/fanforce/api/response.rb', line 87 def body; @response.to_s end |
#code ⇒ Object
122 |
# File 'lib/fanforce/api/response.rb', line 122 def code; @response.code end |
#curl_command ⇒ Object
83 84 85 |
# File 'lib/fanforce/api/response.rb', line 83 def curl_command @curl_command ||= Fanforce::Utils.curl_command(@request.method, @requested_url, @requested_params) end |
#current_page ⇒ Object
99 100 101 |
# File 'lib/fanforce/api/response.rb', line 99 def current_page; @current_page ||= @response_hash[:current_page] end |
#current_results ⇒ Object
91 92 93 |
# File 'lib/fanforce/api/response.rb', line 91 def current_results @current_results ||= @response_hash[:current_results] end |
#data ⇒ Object Also known as: results
78 79 80 |
# File 'lib/fanforce/api/response.rb', line 78 def data self end |
#next_page ⇒ Object
111 112 113 |
# File 'lib/fanforce/api/response.rb', line 111 def next_page @next_page ||= (@request.method == :get and total_pages > current_page) ? current_page + 1 : nil end |
#next_page_url ⇒ Object
119 120 121 |
# File 'lib/fanforce/api/response.rb', line 119 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
107 108 109 |
# File 'lib/fanforce/api/response.rb', line 107 def prev_page @prev_page ||= (@request.method == :get and current_page > 1) ? current_page - 1 : nil end |
#prev_page_url ⇒ Object
115 116 117 |
# File 'lib/fanforce/api/response.rb', line 115 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
103 104 105 |
# File 'lib/fanforce/api/response.rb', line 103 def total_pages; @total_pages ||= @response_hash[:total_pages] end |
#total_results ⇒ Object
95 96 97 |
# File 'lib/fanforce/api/response.rb', line 95 def total_results; @total_results ||= @response_hash[:total_results] end |