Class: LinkshareAPI::Response
- Inherits:
-
Object
- Object
- LinkshareAPI::Response
- Defined in:
- lib/linkshare_api/response.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#page_number ⇒ Object
readonly
Returns the value of attribute page_number.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#total_matches ⇒ Object
readonly
Returns the value of attribute total_matches.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize(response, from) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(response, from) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 12 13 14 15 |
# File 'lib/linkshare_api/response.rb', line 7 def initialize(response, from) @request = response.request result = response[LinkshareAPI::RESULT[from]] @from = from @total_matches = result["TotalMatches"].to_i @total_pages = result["TotalPages"].to_i @page_number = result[LinkshareAPI::PAGE_NUMBER[from]].to_i @data = parse(result[LinkshareAPI::PARSE_RESULT[from]]) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/linkshare_api/response.rb', line 5 def data @data end |
#page_number ⇒ Object (readonly)
Returns the value of attribute page_number.
5 6 7 |
# File 'lib/linkshare_api/response.rb', line 5 def page_number @page_number end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
5 6 7 |
# File 'lib/linkshare_api/response.rb', line 5 def request @request end |
#total_matches ⇒ Object (readonly)
Returns the value of attribute total_matches.
5 6 7 |
# File 'lib/linkshare_api/response.rb', line 5 def total_matches @total_matches end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
5 6 7 |
# File 'lib/linkshare_api/response.rb', line 5 def total_pages @total_pages end |
Instance Method Details
#all ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/linkshare_api/response.rb', line 17 def all while page_number < total_pages uri = Addressable::URI.parse(request.uri) params = uri.query_values params["pagenumber"] = page_number + 1 if @from == :coupon_web_service next_page_response = LinkshareAPI::CouponWebService.new.query(params) else next_page_response = LinkshareAPI::ProductSearch.new.query(params) end @page_number = next_page_response.page_number @data += next_page_response.data end @data end |