google-adwords-api 0.14.2 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +8 -8
  2. data/ChangeLog +7 -0
  3. data/README.md +3 -3
  4. data/adwords_api.yml +5 -0
  5. data/examples/v201409/account_management/get_account_hierarchy.rb +2 -2
  6. data/examples/v201409/advanced_operations/{add_ad_customizer.rb → add_ad_customizers.rb} +4 -4
  7. data/examples/v201409/extensions/add_site_links_using_feeds.rb +12 -12
  8. data/examples/v201409/migration/migrate_to_extension_settings.rb +29 -2
  9. data/examples/v201409/reporting/parallel_report_download.rb +1 -1
  10. data/examples/v201502/advanced_operations/{add_ad_customizer.rb → add_ad_customizers.rb} +37 -125
  11. data/examples/v201502/extensions/add_site_links_using_feeds.rb +22 -52
  12. data/examples/v201502/migration/migrate_to_extension_settings.rb +29 -2
  13. data/lib/adwords_api.rb +9 -29
  14. data/lib/adwords_api/api_config.rb +0 -80
  15. data/lib/adwords_api/credential_handler.rb +8 -9
  16. data/lib/adwords_api/report_header_handler.rb +6 -2
  17. data/lib/adwords_api/version.rb +1 -1
  18. data/test/adwords_api/test_adwords_api.rb +0 -9
  19. data/test/adwords_api/test_api_config.rb +8 -8
  20. data/test/adwords_api/test_credential_handler.rb +17 -0
  21. data/test/adwords_api/test_report_utils.rb +1 -1
  22. data/test/templates/v201409/basic_operations_get_campaigns.def +1 -1
  23. data/test/templates/v201409/misc_use_oauth2_jwt.def +1 -1
  24. data/test/templates/v201502/basic_operations_get_campaigns.def +1 -1
  25. data/test/templates/v201502/misc_use_oauth2_jwt.def +1 -1
  26. metadata +4 -153
  27. data/examples/v201406/account_management/create_account.rb +0 -92
  28. data/examples/v201406/account_management/get_account_alerts.rb +0 -122
  29. data/examples/v201406/account_management/get_account_changes.rb +0 -145
  30. data/examples/v201406/account_management/get_account_hierarchy.rb +0 -103
  31. data/examples/v201406/advanced_operations/add_ad_customizer.rb +0 -277
  32. data/examples/v201406/advanced_operations/add_ad_group_bid_modifier.rb +0 -105
  33. data/examples/v201406/advanced_operations/add_click_to_download_ad.rb +0 -137
  34. data/examples/v201406/advanced_operations/add_google_my_business_location_extensions.rb +0 -167
  35. data/examples/v201406/advanced_operations/add_site_links.rb +0 -306
  36. data/examples/v201406/advanced_operations/add_text_ad_with_upgraded_urls.rb +0 -137
  37. data/examples/v201406/advanced_operations/get_ad_group_bid_modifiers.rb +0 -106
  38. data/examples/v201406/advanced_operations/upload_offline_conversions.rb +0 -117
  39. data/examples/v201406/advanced_operations/use_shared_bidding_strategy.rb +0 -164
  40. data/examples/v201406/basic_operations/add_ad_groups.rb +0 -144
  41. data/examples/v201406/basic_operations/add_campaigns.rb +0 -153
  42. data/examples/v201406/basic_operations/add_keywords.rb +0 -116
  43. data/examples/v201406/basic_operations/add_text_ads.rb +0 -113
  44. data/examples/v201406/basic_operations/get_ad_groups.rb +0 -106
  45. data/examples/v201406/basic_operations/get_campaigns.rb +0 -101
  46. data/examples/v201406/basic_operations/get_campaigns_with_awql.rb +0 -93
  47. data/examples/v201406/basic_operations/get_keywords.rb +0 -112
  48. data/examples/v201406/basic_operations/get_text_ads.rb +0 -114
  49. data/examples/v201406/basic_operations/pause_ad.rb +0 -92
  50. data/examples/v201406/basic_operations/remove_ad.rb +0 -93
  51. data/examples/v201406/basic_operations/remove_ad_group.rb +0 -89
  52. data/examples/v201406/basic_operations/remove_campaign.rb +0 -91
  53. data/examples/v201406/basic_operations/remove_keyword.rb +0 -98
  54. data/examples/v201406/basic_operations/update_ad_group.rb +0 -89
  55. data/examples/v201406/basic_operations/update_campaign.rb +0 -90
  56. data/examples/v201406/basic_operations/update_keyword.rb +0 -110
  57. data/examples/v201406/campaign_management/add_campaign_labels.rb +0 -86
  58. data/examples/v201406/campaign_management/add_experiment.rb +0 -166
  59. data/examples/v201406/campaign_management/add_keywords_in_bulk.rb +0 -158
  60. data/examples/v201406/campaign_management/add_location_extension.rb +0 -125
  61. data/examples/v201406/campaign_management/get_all_disapproved_ads.rb +0 -101
  62. data/examples/v201406/campaign_management/get_all_disapproved_ads_with_awql.rb +0 -93
  63. data/examples/v201406/campaign_management/get_campaigns_by_label.rb +0 -112
  64. data/examples/v201406/campaign_management/promote_experiment.rb +0 -85
  65. data/examples/v201406/campaign_management/set_ad_parameters.rb +0 -122
  66. data/examples/v201406/campaign_management/set_criterion_bid_modifier.rb +0 -108
  67. data/examples/v201406/campaign_management/validate_text_ad.rb +0 -114
  68. data/examples/v201406/error_handling/handle_captcha_challenge.rb +0 -93
  69. data/examples/v201406/error_handling/handle_partial_failures.rb +0 -134
  70. data/examples/v201406/error_handling/handle_policy_violation_error.rb +0 -145
  71. data/examples/v201406/error_handling/handle_two_factor_authorization_error.rb +0 -88
  72. data/examples/v201406/misc/create_ad_words_session_without_properties_file.rb +0 -94
  73. data/examples/v201406/misc/get_all_images_and_videos.rb +0 -108
  74. data/examples/v201406/misc/setup_oauth2.rb +0 -88
  75. data/examples/v201406/misc/upload_image.rb +0 -97
  76. data/examples/v201406/misc/use_oauth2_jwt.rb +0 -97
  77. data/examples/v201406/optimization/estimate_keyword_traffic.rb +0 -155
  78. data/examples/v201406/optimization/get_keyword_bid_simulations.rb +0 -100
  79. data/examples/v201406/optimization/get_keyword_ideas.rb +0 -130
  80. data/examples/v201406/optimization/get_placement_ideas.rb +0 -112
  81. data/examples/v201406/remarketing/add_audience.rb +0 -123
  82. data/examples/v201406/remarketing/add_conversion_tracker.rb +0 -105
  83. data/examples/v201406/reporting/download_criteria_report.rb +0 -87
  84. data/examples/v201406/reporting/download_criteria_report_with_awql.rb +0 -86
  85. data/examples/v201406/reporting/get_report_fields.rb +0 -79
  86. data/examples/v201406/reporting/parallel_report_download.rb +0 -171
  87. data/examples/v201406/shopping_campaigns/add_product_partition_tree.rb +0 -269
  88. data/examples/v201406/shopping_campaigns/add_product_scope.rb +0 -133
  89. data/examples/v201406/shopping_campaigns/add_shopping_campaign.rb +0 -135
  90. data/examples/v201406/shopping_campaigns/get_product_category_taxonomy.rb +0 -117
  91. data/examples/v201406/shopping_campaigns/set_product_sales_channel.rb +0 -98
  92. data/examples/v201406/targeting/add_campaign_targeting_criteria.rb +0 -173
  93. data/examples/v201406/targeting/add_demographic_targeting_criteria.rb +0 -116
  94. data/examples/v201406/targeting/get_campaign_targeting_criteria.rb +0 -110
  95. data/examples/v201406/targeting/get_targetable_languages_and_carriers.rb +0 -94
  96. data/examples/v201406/targeting/lookup_location.rb +0 -112
  97. data/examples/v201502/campaign_management/add_location_extension.rb +0 -125
  98. data/lib/adwords_api/v201406/ad_group_ad_service.rb +0 -46
  99. data/lib/adwords_api/v201406/ad_group_ad_service_registry.rb +0 -46
  100. data/lib/adwords_api/v201406/ad_group_bid_modifier_service.rb +0 -42
  101. data/lib/adwords_api/v201406/ad_group_bid_modifier_service_registry.rb +0 -46
  102. data/lib/adwords_api/v201406/ad_group_criterion_service.rb +0 -46
  103. data/lib/adwords_api/v201406/ad_group_criterion_service_registry.rb +0 -46
  104. data/lib/adwords_api/v201406/ad_group_feed_service.rb +0 -42
  105. data/lib/adwords_api/v201406/ad_group_feed_service_registry.rb +0 -46
  106. data/lib/adwords_api/v201406/ad_group_service.rb +0 -46
  107. data/lib/adwords_api/v201406/ad_group_service_registry.rb +0 -46
  108. data/lib/adwords_api/v201406/ad_param_service.rb +0 -38
  109. data/lib/adwords_api/v201406/ad_param_service_registry.rb +0 -46
  110. data/lib/adwords_api/v201406/adwords_user_list_service.rb +0 -38
  111. data/lib/adwords_api/v201406/adwords_user_list_service_registry.rb +0 -46
  112. data/lib/adwords_api/v201406/alert_service.rb +0 -34
  113. data/lib/adwords_api/v201406/alert_service_registry.rb +0 -46
  114. data/lib/adwords_api/v201406/bidding_strategy_service.rb +0 -42
  115. data/lib/adwords_api/v201406/bidding_strategy_service_registry.rb +0 -46
  116. data/lib/adwords_api/v201406/budget_order_service.rb +0 -42
  117. data/lib/adwords_api/v201406/budget_order_service_registry.rb +0 -46
  118. data/lib/adwords_api/v201406/budget_service.rb +0 -42
  119. data/lib/adwords_api/v201406/budget_service_registry.rb +0 -46
  120. data/lib/adwords_api/v201406/campaign_ad_extension_service.rb +0 -38
  121. data/lib/adwords_api/v201406/campaign_ad_extension_service_registry.rb +0 -46
  122. data/lib/adwords_api/v201406/campaign_criterion_service.rb +0 -42
  123. data/lib/adwords_api/v201406/campaign_criterion_service_registry.rb +0 -46
  124. data/lib/adwords_api/v201406/campaign_feed_service.rb +0 -42
  125. data/lib/adwords_api/v201406/campaign_feed_service_registry.rb +0 -46
  126. data/lib/adwords_api/v201406/campaign_service.rb +0 -46
  127. data/lib/adwords_api/v201406/campaign_service_registry.rb +0 -46
  128. data/lib/adwords_api/v201406/campaign_shared_set_service.rb +0 -38
  129. data/lib/adwords_api/v201406/campaign_shared_set_service_registry.rb +0 -47
  130. data/lib/adwords_api/v201406/constant_data_service.rb +0 -66
  131. data/lib/adwords_api/v201406/constant_data_service_registry.rb +0 -46
  132. data/lib/adwords_api/v201406/conversion_tracker_service.rb +0 -38
  133. data/lib/adwords_api/v201406/conversion_tracker_service_registry.rb +0 -46
  134. data/lib/adwords_api/v201406/customer_feed_service.rb +0 -42
  135. data/lib/adwords_api/v201406/customer_feed_service_registry.rb +0 -46
  136. data/lib/adwords_api/v201406/customer_service.rb +0 -38
  137. data/lib/adwords_api/v201406/customer_service_registry.rb +0 -46
  138. data/lib/adwords_api/v201406/customer_sync_service.rb +0 -34
  139. data/lib/adwords_api/v201406/customer_sync_service_registry.rb +0 -47
  140. data/lib/adwords_api/v201406/data_service.rb +0 -54
  141. data/lib/adwords_api/v201406/data_service_registry.rb +0 -46
  142. data/lib/adwords_api/v201406/experiment_service.rb +0 -38
  143. data/lib/adwords_api/v201406/experiment_service_registry.rb +0 -46
  144. data/lib/adwords_api/v201406/feed_item_service.rb +0 -42
  145. data/lib/adwords_api/v201406/feed_item_service_registry.rb +0 -46
  146. data/lib/adwords_api/v201406/feed_mapping_service.rb +0 -42
  147. data/lib/adwords_api/v201406/feed_mapping_service_registry.rb +0 -46
  148. data/lib/adwords_api/v201406/feed_service.rb +0 -42
  149. data/lib/adwords_api/v201406/feed_service_registry.rb +0 -46
  150. data/lib/adwords_api/v201406/geo_location_service.rb +0 -34
  151. data/lib/adwords_api/v201406/geo_location_service_registry.rb +0 -46
  152. data/lib/adwords_api/v201406/label_service.rb +0 -42
  153. data/lib/adwords_api/v201406/label_service_registry.rb +0 -46
  154. data/lib/adwords_api/v201406/location_criterion_service.rb +0 -38
  155. data/lib/adwords_api/v201406/location_criterion_service_registry.rb +0 -46
  156. data/lib/adwords_api/v201406/managed_customer_service.rb +0 -50
  157. data/lib/adwords_api/v201406/managed_customer_service_registry.rb +0 -46
  158. data/lib/adwords_api/v201406/media_service.rb +0 -42
  159. data/lib/adwords_api/v201406/media_service_registry.rb +0 -46
  160. data/lib/adwords_api/v201406/mutate_job_service.rb +0 -42
  161. data/lib/adwords_api/v201406/mutate_job_service_registry.rb +0 -46
  162. data/lib/adwords_api/v201406/offline_conversion_feed_service.rb +0 -34
  163. data/lib/adwords_api/v201406/offline_conversion_feed_service_registry.rb +0 -46
  164. data/lib/adwords_api/v201406/report_definition_service.rb +0 -34
  165. data/lib/adwords_api/v201406/report_definition_service_registry.rb +0 -46
  166. data/lib/adwords_api/v201406/shared_criterion_service.rb +0 -38
  167. data/lib/adwords_api/v201406/shared_criterion_service_registry.rb +0 -47
  168. data/lib/adwords_api/v201406/shared_set_service.rb +0 -38
  169. data/lib/adwords_api/v201406/shared_set_service_registry.rb +0 -47
  170. data/lib/adwords_api/v201406/targeting_idea_service.rb +0 -38
  171. data/lib/adwords_api/v201406/targeting_idea_service_registry.rb +0 -46
  172. data/lib/adwords_api/v201406/traffic_estimator_service.rb +0 -34
  173. data/lib/adwords_api/v201406/traffic_estimator_service_registry.rb +0 -46
  174. data/test/templates/v201406/basic_operations_get_campaigns.def +0 -114
  175. data/test/templates/v201406/misc_use_oauth2_jwt.def +0 -131
@@ -1,171 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
- #
6
- # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
7
- #
8
- # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
- # implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
- # This example gets and downloads an Ad Hoc report from a XML report definition
22
- # for all accounts in hierarchy in multiple parallel threads.
23
- #
24
- # Note: This code example uses MCC-level calls and won't work with Test
25
- # Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
26
-
27
- require 'thread'
28
-
29
- require 'adwords_api'
30
- require 'adwords_api/utils'
31
-
32
- def parallel_report_download()
33
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
34
- # when called without parameters.
35
- adwords = AdwordsApi::Api.new
36
-
37
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
38
- # the configuration file or provide your own logger:
39
- # adwords.logger = Logger.new('adwords_xml.log')
40
-
41
- # Determine list of customer IDs to retrieve report for. For this example we
42
- # will use ManagedCustomerService to get all IDs in hierarchy.
43
-
44
- managed_customer_srv = adwords.service(:ManagedCustomerService, API_VERSION)
45
-
46
- # Get the account hierarchy for this account.
47
- selector = {:fields => ['CustomerId']}
48
-
49
- # Run the request at the MCC level.
50
- graph = adwords.use_mcc() {managed_customer_srv.get(selector)}
51
-
52
- # Using queue to balance load between threads.
53
- queue = Queue.new()
54
-
55
- if graph and graph[:entries] and !graph[:entries].empty?
56
- graph[:entries].each {|account| queue << account[:customer_id]}
57
- else
58
- raise StandardError, 'Can not retrieve any customer ID'
59
- end
60
-
61
- # Get report utilities for the version.
62
- report_utils = adwords.report_utils(API_VERSION)
63
-
64
- # Define report definition. You can also pass your own XML text as a string.
65
- report_definition = {
66
- :selector => {
67
- :fields => ['CampaignId', 'Id', 'Impressions', 'Clicks', 'Cost'],
68
- # Predicates are optional.
69
- :predicates => {
70
- :field => 'Status',
71
- :operator => 'IN',
72
- :values => ['ENABLED', 'PAUSED']
73
- }
74
- },
75
- :report_name => 'Custom ADGROUP_PERFORMANCE_REPORT',
76
- :report_type => 'ADGROUP_PERFORMANCE_REPORT',
77
- :download_format => 'CSV',
78
- :date_range_type => 'LAST_7_DAYS',
79
- # Enable to get rows with zero impressions.
80
- :include_zero_impressions => false
81
- }
82
-
83
- puts 'Retrieving %d reports with %d threads:' % [queue.size, THREADS]
84
-
85
- reports_succeeded = Queue.new()
86
- reports_failed = Queue.new()
87
-
88
- # Creating a mutex to control access to the queue.
89
- queue_mutex = Mutex.new
90
-
91
- # Start all the threads.
92
- threads = (1..THREADS).map do |thread_id|
93
- Thread.new(report_definition) do |local_def|
94
- cid = nil
95
- begin
96
- cid = queue_mutex.synchronize {(queue.empty?) ? nil : queue.pop(true)}
97
- if cid
98
- retry_count = 0
99
- file_name = 'adgroup_%010d.csv' % cid
100
- puts "[%2d/%d] Loading report for customer ID %s into '%s'..." %
101
- [thread_id, retry_count,
102
- AdwordsApi::Utils.format_id(cid), file_name]
103
- begin
104
- report_utils.download_report_as_file(local_def, file_name, cid)
105
- reports_succeeded << {:cid => cid, :file_name => file_name}
106
- rescue AdwordsApi::Errors::ReportError => e
107
- if e.http_code == 500 && retry_count < MAX_RETRIES
108
- retry_count += 1
109
- sleep(retry_count * BACKOFF_FACTOR)
110
- retry
111
- else
112
- puts(('Report failed for customer ID %s with code %d after %d ' +
113
- 'retries.') % [cid, e.http_code, retry_count + 1])
114
- reports_failed <<
115
- {:cid => cid, :http_code => e.http_code, :message => e.message}
116
- end
117
- end
118
- end
119
- end while (cid != nil)
120
- end
121
- end
122
-
123
- # Wait for all threads to finish.
124
- threads.each { |aThread| aThread.join }
125
-
126
- puts 'Download completed, results:'
127
- puts 'Successful reports:'
128
- while !reports_succeeded.empty? do
129
- result = reports_succeeded.pop()
130
- puts "\tClient ID %s => '%s'" %
131
- [AdwordsApi::Utils.format_id(result[:cid]), result[:file_name]]
132
- end
133
- puts 'Failed reports:'
134
- while !reports_failed.empty? do
135
- result = reports_failed.pop()
136
- puts "\tClient ID %s => Code: %d, Message: '%s'" %
137
- [AdwordsApi::Utils.format_id(result[:cid]),
138
- result[:http_code], result[:message]]
139
- end
140
- puts 'End of results.'
141
- end
142
-
143
- if __FILE__ == $0
144
- API_VERSION = :v201406
145
- # Number of parallel threads to spawn.
146
- THREADS = 10
147
- # Maximum number of retries for 500 errors.
148
- MAX_RETRIES = 5
149
- # Timeout between retries in seconds.
150
- BACKOFF_FACTOR = 5
151
-
152
- begin
153
- parallel_report_download()
154
-
155
- # Authorization error.
156
- rescue AdsCommon::Errors::OAuth2VerificationRequired => e
157
- puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
158
- "OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
159
- "to retrieve and store OAuth2 tokens."
160
- puts "See this wiki page for more details:\n\n " +
161
- 'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
162
-
163
- # HTTP errors.
164
- rescue AdsCommon::Errors::HttpError => e
165
- puts 'HTTP Error: %s' % e
166
-
167
- # API errors.
168
- rescue AdwordsApi::Errors::ReportError => e
169
- puts 'Reporting Error: %s' % e.message
170
- end
171
- end
@@ -1,269 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Author:: api.mcloonan@gmail.com (Michael Cloonan)
5
- #
6
- # Copyright:: Copyright 2014, Google Inc. All Rights Reserved.
7
- #
8
- # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
- # implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
- # This example creates a ProductPartition tree.
22
-
23
- require 'adwords_api'
24
-
25
- class ProductPartitionHelper
26
- attr_reader :operations
27
-
28
- def initialize(ad_group_id)
29
- # The next temporary criterion ID to be used.
30
- #
31
- # When creating our tree we need to specify the parent-child relationships
32
- # between nodes. However, until a criterion has been created on the server
33
- # we do not have a criterionId with which to refer to it.
34
- #
35
- # Instead we can specify temporary IDs that are specific to a single mutate
36
- # request. Once the criteria have been created they are assigned an ID as
37
- # normal and the temporary ID will no longer refer to it.
38
- #
39
- # A valid temporary ID is any negative integer.
40
- @next_id = -1
41
-
42
- # The set of mutate operations needed to create the current tree.
43
- @operations = []
44
-
45
- # The ID of the AdGroup that we wish to attach the partition tree to.
46
- @ad_group_id = ad_group_id
47
- end
48
-
49
- def create_subdivision(parent = nil, value = nil)
50
- division = {
51
- :xsi_type => 'ProductPartition',
52
- :partition_type => 'SUBDIVISION',
53
- :id => @next_id
54
- }
55
-
56
- @next_id -= 1
57
-
58
- unless parent.nil? || value.nil?
59
- division[:parent_criterion_id] = parent[:id]
60
- division[:case_value] = value
61
- end
62
-
63
- ad_group_criterion = {
64
- :xsi_type => 'BiddableAdGroupCriterion',
65
- :ad_group_id => @ad_group_id,
66
- :criterion => division
67
- }
68
-
69
- create_add_operation(ad_group_criterion)
70
-
71
- return division
72
- end
73
-
74
- def create_unit(parent = nil, value = nil, bid_amount = nil)
75
- unit = {
76
- :xsi_type => 'ProductPartition',
77
- :partition_type => 'UNIT'
78
- }
79
-
80
- unless parent.nil? || value.nil?
81
- unit[:parent_criterion_id] = parent[:id]
82
- unit[:case_value] = value
83
- end
84
-
85
- ad_group_criterion = {}
86
- if bid_amount && bid_amount > 0
87
- bidding_strategy_configuration = {
88
- :bids => [{
89
- :xsi_type => 'CpcBid',
90
- :bid => {
91
- :xsi_type => 'Money',
92
- :micro_amount => bid_amount
93
- }
94
- }]
95
- }
96
- ad_group_criterion[:xsi_type] = 'BiddableAdGroupCriterion'
97
- ad_group_criterion[:bidding_strategy_configuration] =
98
- bidding_strategy_configuration
99
- else
100
- ad_group_criterion[:xsi_type] = 'NegativeAdGroupCriterion'
101
- end
102
- ad_group_criterion[:ad_group_id] = @ad_group_id
103
- ad_group_criterion[:criterion] = unit
104
-
105
- create_add_operation(ad_group_criterion)
106
-
107
- return unit
108
- end
109
-
110
- private
111
-
112
- def create_add_operation(ad_group_criterion)
113
- operation = {
114
- :operator => 'ADD',
115
- :operand => ad_group_criterion
116
- }
117
-
118
- @operations << operation
119
- end
120
- end
121
-
122
- def display_tree(node, children, level = 0)
123
- value = ''
124
- type = ''
125
-
126
- if node[:case_value]
127
- type = node[:case_value][:product_dimension_type]
128
-
129
- value = case type
130
- when 'ProductCanonicalCondition'
131
- node[:case_value][:condition]
132
- when 'ProductBiddingCategory'
133
- "%s(%s)" % [node[:case_value][:type], node[:case_value][:value]]
134
- else
135
- node[:case_value][:value]
136
- end
137
- end
138
-
139
- puts "%sid: %s, type: %s, value: %s" %
140
- [' ' * level, node[:id], type, value]
141
-
142
- children[node[:id]].each do |child_node|
143
- display_tree(child_node, children, level + 1)
144
- end
145
- end
146
-
147
- def add_product_partition_tree(ad_group_id)
148
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
149
- # when called without parameters.
150
- adwords = AdwordsApi::Api.new
151
-
152
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
153
- # the configuration file or provide your own logger:
154
- # adwords.logger = Logger.new('adwords_xml.log')
155
-
156
- ad_group_criterion_srv =
157
- adwords.service(:AdGroupCriterionService, API_VERSION)
158
-
159
- helper = ProductPartitionHelper.new(ad_group_id)
160
-
161
- root = helper.create_subdivision()
162
-
163
- new_product_canonical_condition = {
164
- :xsi_type => 'ProductCanonicalCondition',
165
- :condition => 'NEW'
166
- }
167
-
168
- used_product_canonical_condition = {
169
- :xsi_type => 'ProductCanonicalCondition',
170
- :condition => 'USED'
171
- }
172
-
173
- other_product_canonical_condition = {
174
- :xsi_type => 'ProductCanonicalCondition'
175
- }
176
-
177
- helper.create_unit(root, new_product_canonical_condition, 200000)
178
- helper.create_unit(root, used_product_canonical_condition, 100000)
179
- other_condition =
180
- helper.create_subdivision(root, other_product_canonical_condition)
181
-
182
- cool_product_brand = {
183
- :xsi_type => 'ProductBrand',
184
- :value => 'CoolBrand'
185
- }
186
-
187
- cheap_product_brand = {
188
- :xsi_type => 'ProductBrand',
189
- :value => 'CheapBrand'
190
- }
191
-
192
- other_product_brand = {
193
- :xsi_type => 'ProductBrand'
194
- }
195
-
196
- helper.create_unit(other_condition, cool_product_brand, 900000)
197
- helper.create_unit(other_condition, cheap_product_brand, 10000)
198
- other_brand = helper.create_subdivision(other_condition, other_product_brand)
199
-
200
- # The value for the bidding category is a fixed ID for the 'Luggage & Bags'
201
- # category. You can retrieve IDs for categories from the ConstantDataService.
202
- # See the get_product_taxonomy example for more details.
203
- luggage_category = {
204
- :xsi_type => 'ProductBiddingCategory',
205
- :type => 'BIDDING_CATEGORY_L1',
206
- :value => '-5914235892932915235'
207
- }
208
-
209
- generic_category = {
210
- :xsi_type => 'ProductBiddingCategory',
211
- :type => 'BIDDING_CATEGORY_L1'
212
- }
213
-
214
- helper.create_unit(other_brand, luggage_category, 750000)
215
- helper.create_unit(other_brand, generic_category, 110000)
216
-
217
- # Make the mutate request.
218
- result = ad_group_criterion_srv.mutate(helper.operations)
219
-
220
- children = {}
221
- root_node = nil
222
- # For each criterion, make an array containing each of its children.
223
- # We always create the parent before the child, so we can rely on that here.
224
- result[:value].each do |criterion|
225
- children[criterion[:criterion][:id]] = []
226
-
227
- if criterion[:criterion][:parent_criterion_id]
228
- children[criterion[:criterion][:parent_criterion_id]] <<
229
- criterion[:criterion]
230
- else
231
- root_node = criterion[:criterion]
232
- end
233
- end
234
-
235
- display_tree(root_node, children)
236
- end
237
-
238
- if __FILE__ == $0
239
- API_VERSION = :v201406
240
-
241
- begin
242
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
243
-
244
- add_product_partition_tree(ad_group_id)
245
-
246
- # Authorization error.
247
- rescue AdsCommon::Errors::OAuth2VerificationRequired => e
248
- puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
249
- "OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
250
- "to retrieve and store OAuth2 tokens."
251
- puts "See this wiki page for more details:\n\n " +
252
- 'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
253
-
254
- # HTTP errors.
255
- rescue AdsCommon::Errors::HttpError => e
256
- puts "HTTP Error: %s" % e
257
-
258
- # API errors.
259
- rescue AdwordsApi::Errors::ApiException => e
260
- puts "Message: %s" % e.message
261
- puts 'Errors:'
262
- e.errors.each_with_index do |error, index|
263
- puts "\tError [%d]:" % (index + 1)
264
- error.each do |field, value|
265
- puts "\t\t%s: %s" % [field, value]
266
- end
267
- end
268
- end
269
- end
@@ -1,133 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Author:: api.mcloonan@gmail.com (Michael Cloonan)
5
- #
6
- # Copyright:: Copyright 2014, Google Inc. All Rights Reserved.
7
- #
8
- # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
- # implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
- # This example restricts the products that will be included in the campaign by
22
- # setting a ProductScope.
23
- #
24
- # Tags: CampaignCriterionService.mutate
25
-
26
- require 'adwords_api'
27
-
28
- def add_product_scope(campaign_id)
29
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
30
- # when called without parameters.
31
- adwords = AdwordsApi::Api.new
32
-
33
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
34
- # the configuration file or provide your own logger:
35
- # adwords.logger = Logger.new('adwords_xml.log')
36
-
37
- campaign_criterion_srv = adwords.service(:CampaignCriterionService,
38
- API_VERSION)
39
-
40
- product_scope = {
41
- # This set of dimensions is for demonstration purposes only. It is
42
- # extremely unlikely that you want to include so many dimensions in your
43
- # product scope.
44
- :dimensions => [
45
- {
46
- :xsi_type => 'ProductBrand',
47
- :value => 'Nexus'
48
- },
49
- {
50
- :xsi_type => 'ProductCanonicalCondition',
51
- :value => 'NEW'
52
- },
53
- {
54
- :xsi_type => 'ProductCustomAttribute',
55
- :type => 'CUSTOM_ATTRIBUTE_0',
56
- :value => 'my attribute value'
57
- },
58
- {
59
- :xsi_type => 'ProductOfferId',
60
- :value => 'book1'
61
- },
62
- {
63
- :xsi_type => 'ProductType',
64
- :type => 'PRODUCT_TYPE_L1',
65
- :value => 'Media'
66
- },
67
- {
68
- :xsi_type => 'ProductType',
69
- :type => 'PRODUCT_TYPE_L2',
70
- :value => 'Books'
71
- },
72
- # The value for the bidding category is a fixed ID for the
73
- # 'Luggage & Bags' category. You can retrieve IDs for categories from
74
- # the ConstantDataService. See the 'get_product_category_taxonomy'
75
- # example for more details.
76
- {
77
- :xsi_type => 'ProductBiddingCategory',
78
- :type => 'BIDDING_CATEGORY_L1',
79
- :value => '-5914235892932915235',
80
- }
81
- ]
82
- }
83
-
84
- campaign_criterion = {
85
- :campaign_id => campaign_id,
86
- :product_scope => product_scope
87
- }
88
-
89
- campaign_criterion_operation = {
90
- :operator => 'ADD',
91
- :operand => campaign_criterion
92
- }
93
-
94
- # Make the mutate request.
95
- result = campaign_criterion_srv.mutate([campaign_criterion_operation])
96
-
97
- campaign_criterion = result[:value].first
98
- puts "Created a ProductScope criterion with ID %d." %
99
- [campaign_criterion[:criterion][:id]]
100
- end
101
-
102
- if __FILE__ == $0
103
- API_VERSION = :v201406
104
-
105
- begin
106
- campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
107
-
108
- add_product_scope(campaign_id)
109
-
110
- # Authorization error.
111
- rescue AdsCommon::Errors::OAuth2VerificationRequired => e
112
- puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
113
- "OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
114
- "to retrieve and store OAuth2 tokens."
115
- puts "See this wiki page for more details:\n\n " +
116
- 'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
117
-
118
- # HTTP errors.
119
- rescue AdsCommon::Errors::HttpError => e
120
- puts "HTTP Error: %s" % e
121
-
122
- # API errors.
123
- rescue AdwordsApi::Errors::ApiException => e
124
- puts "Message: %s" % e.message
125
- puts 'Errors:'
126
- e.errors.each_with_index do |error, index|
127
- puts "\tError [%d]:" % (index + 1)
128
- error.each do |field, value|
129
- puts "\t\t%s: %s" % [field, value]
130
- end
131
- end
132
- end
133
- end