Class: AdwordsApi::ServiceQueryBuilder
- Inherits:
-
QueryBuilder
- Object
- QueryBuilder
- AdwordsApi::ServiceQueryBuilder
- Defined in:
- lib/adwords_api/query_utils/service_query_builder.rb
Instance Method Summary collapse
- #build ⇒ Object
- #configure {|_self| ... } ⇒ Object
-
#initialize(api) {|_self| ... } ⇒ ServiceQueryBuilder
constructor
A new instance of ServiceQueryBuilder.
- #limit(start_index, page_size) ⇒ Object
- #order_by_asc(field) ⇒ Object
- #order_by_desc(field) ⇒ Object
- #select(*fields) ⇒ Object
Methods inherited from QueryBuilder
Constructor Details
#initialize(api) {|_self| ... } ⇒ ServiceQueryBuilder
Returns a new instance of ServiceQueryBuilder.
26 27 28 29 30 31 32 33 |
# File 'lib/adwords_api/query_utils/service_query_builder.rb', line 26 def initialize(api) super(api) @select = nil @order = [] @start_index = nil @page_size = nil yield self if block_given? end |
Instance Method Details
#build ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/adwords_api/query_utils/service_query_builder.rb', line 62 def build() raise ArgumentError, 'Must specify SELECT clause for valid AWQL' if @select.nil? if !@start_index.nil? && @page_size.nil? raise ArgumentError, 'Cannot specify start index without page size.' end if !@page_size.nil? && @start_index.nil? raise ArgumentError, 'Cannot specify page size without start index.' end result = sprintf('SELECT %s', @select.to_a.join(', ')) result += build_where() unless @order.empty? orders = @order.map do |o| sprintf('%s %s', o[:field], o[:direction]) end result += sprintf(' ORDER BY %s', orders.join(', ')) end @api.utils_reporter.service_query_builder_used() return ServiceQuery.new(result, @start_index, @page_size) end |
#configure {|_self| ... } ⇒ Object
35 36 37 |
# File 'lib/adwords_api/query_utils/service_query_builder.rb', line 35 def configure() yield self end |
#limit(start_index, page_size) ⇒ Object
57 58 59 60 |
# File 'lib/adwords_api/query_utils/service_query_builder.rb', line 57 def limit(start_index, page_size) @start_index = start_index @page_size = page_size end |
#order_by_asc(field) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/adwords_api/query_utils/service_query_builder.rb', line 43 def order_by_asc(field) @order << { :field => field, :direction => 'ASC' } end |
#order_by_desc(field) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/adwords_api/query_utils/service_query_builder.rb', line 50 def order_by_desc(field) @order << { :field => field, :direction => 'DESC' } end |
#select(*fields) ⇒ Object
39 40 41 |
# File 'lib/adwords_api/query_utils/service_query_builder.rb', line 39 def select(*fields) @select = Set[*fields] end |