Class: AdwordsApi::ServiceQuery
- Inherits:
-
Object
- Object
- AdwordsApi::ServiceQuery
- Defined in:
- lib/adwords_api/query_utils/service_query.rb
Instance Method Summary collapse
- #has_next(page) ⇒ Object
-
#has_next_landscape_page(page) ⇒ Object
Determining whether another page exists when dealing with bid landscapes is different from other types of queries.
-
#initialize(query, start_index, page_size) ⇒ ServiceQuery
constructor
A new instance of ServiceQuery.
- #next_page ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(query, start_index, page_size) ⇒ ServiceQuery
Returns a new instance of ServiceQuery.
22 23 24 25 26 |
# File 'lib/adwords_api/query_utils/service_query.rb', line 22 def initialize(query, start_index, page_size) @query = query @start_index = start_index @page_size = page_size end |
Instance Method Details
#has_next(page) ⇒ Object
28 29 30 31 32 |
# File 'lib/adwords_api/query_utils/service_query.rb', line 28 def has_next(page) raise ArgumentError, 'Cannot page through query with no LIMIT clause.' if @start_index.nil? return @start_index + @page_size < page[:total_num_entries] end |
#has_next_landscape_page(page) ⇒ Object
Determining whether another page exists when dealing with bid landscapes is different from other types of queries. Use this method for those cases.
36 37 38 39 40 41 42 43 44 |
# File 'lib/adwords_api/query_utils/service_query.rb', line 36 def has_next_landscape_page(page) raise ArgumentError, 'Cannot page through query with no LIMIT clause.' if @start_index.nil? total_landscape_points_in_page = 0 page[:entries].each do |landscape| total_landscape_points_in_page += landscape[:landscape_points].size end return total_landscape_points_in_page >= @page_size end |
#next_page ⇒ Object
46 47 48 49 50 51 |
# File 'lib/adwords_api/query_utils/service_query.rb', line 46 def next_page() raise ArgumentError, 'Cannot page through query with no LIMIT clause.' if @start_index.nil? @start_index += @page_size return self end |
#to_s ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/adwords_api/query_utils/service_query.rb', line 53 def to_s() query = @query unless @start_index.nil? query += sprintf(' LIMIT %s,%s', @start_index, @page_size) end return query end |