Class: LinkshareAPI::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/linkshare_api/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/linkshare_api/response.rb', line 5

def data
  @data
end

#page_numberObject (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

#requestObject (readonly)

Returns the value of attribute request.



5
6
7
# File 'lib/linkshare_api/response.rb', line 5

def request
  @request
end

#total_matchesObject (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_pagesObject (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

#allObject



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