google-adwords-api 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. checksums.yaml +5 -13
  2. data/ChangeLog +5 -0
  3. data/README.md +3 -3
  4. data/adwords_api.yml +3 -0
  5. data/examples/v201509/{campaign_management → advanced_operations}/add_complete_campaigns_using_batch_job.rb +10 -16
  6. data/examples/v201509/advanced_operations/add_keywords_using_incremental_batch_job.rb +179 -0
  7. data/examples/v201509/reporting/stream_criteria_report_results.rb +97 -0
  8. data/lib/adwords_api/api_config.rb +0 -86
  9. data/lib/adwords_api/batch_job_utils.rb +124 -51
  10. data/lib/adwords_api/incremental_upload_helper.rb +71 -0
  11. data/lib/adwords_api/report_header_handler.rb +1 -1
  12. data/lib/adwords_api/report_stream.rb +64 -0
  13. data/lib/adwords_api/report_utils.rb +88 -8
  14. data/lib/adwords_api/version.rb +1 -1
  15. data/test/adwords_api/test_batch_job_utils.rb +15 -0
  16. metadata +18 -168
  17. data/examples/v201502/account_management/create_account.rb +0 -88
  18. data/examples/v201502/account_management/get_account_changes.rb +0 -139
  19. data/examples/v201502/account_management/get_account_hierarchy.rb +0 -94
  20. data/examples/v201502/advanced_operations/add_ad_customizers.rb +0 -184
  21. data/examples/v201502/advanced_operations/add_ad_group_bid_modifier.rb +0 -101
  22. data/examples/v201502/advanced_operations/add_click_to_download_ad.rb +0 -133
  23. data/examples/v201502/advanced_operations/add_text_ad_with_upgraded_urls.rb +0 -134
  24. data/examples/v201502/advanced_operations/create_and_attach_shared_keyword_set.rb +0 -133
  25. data/examples/v201502/advanced_operations/find_and_remove_criteria_from_shared_set.rb +0 -166
  26. data/examples/v201502/advanced_operations/get_ad_group_bid_modifiers.rb +0 -102
  27. data/examples/v201502/advanced_operations/upload_offline_conversions.rb +0 -113
  28. data/examples/v201502/advanced_operations/use_shared_bidding_strategy.rb +0 -147
  29. data/examples/v201502/basic_operations/add_ad_groups.rb +0 -140
  30. data/examples/v201502/basic_operations/add_campaigns.rb +0 -139
  31. data/examples/v201502/basic_operations/add_keywords.rb +0 -114
  32. data/examples/v201502/basic_operations/add_text_ads.rb +0 -109
  33. data/examples/v201502/basic_operations/get_ad_groups.rb +0 -102
  34. data/examples/v201502/basic_operations/get_campaigns.rb +0 -97
  35. data/examples/v201502/basic_operations/get_campaigns_with_awql.rb +0 -89
  36. data/examples/v201502/basic_operations/get_keywords.rb +0 -108
  37. data/examples/v201502/basic_operations/get_text_ads.rb +0 -110
  38. data/examples/v201502/basic_operations/pause_ad.rb +0 -88
  39. data/examples/v201502/basic_operations/remove_ad.rb +0 -89
  40. data/examples/v201502/basic_operations/remove_ad_group.rb +0 -85
  41. data/examples/v201502/basic_operations/remove_campaign.rb +0 -87
  42. data/examples/v201502/basic_operations/remove_keyword.rb +0 -94
  43. data/examples/v201502/basic_operations/update_ad_group.rb +0 -85
  44. data/examples/v201502/basic_operations/update_campaign.rb +0 -86
  45. data/examples/v201502/basic_operations/update_keyword.rb +0 -106
  46. data/examples/v201502/campaign_management/add_campaign_labels.rb +0 -82
  47. data/examples/v201502/campaign_management/add_experiment.rb +0 -162
  48. data/examples/v201502/campaign_management/add_keywords_in_bulk.rb +0 -153
  49. data/examples/v201502/campaign_management/get_all_disapproved_ads.rb +0 -97
  50. data/examples/v201502/campaign_management/get_all_disapproved_ads_with_awql.rb +0 -89
  51. data/examples/v201502/campaign_management/get_campaigns_by_label.rb +0 -108
  52. data/examples/v201502/campaign_management/promote_experiment.rb +0 -81
  53. data/examples/v201502/campaign_management/set_ad_parameters.rb +0 -118
  54. data/examples/v201502/campaign_management/set_criterion_bid_modifier.rb +0 -104
  55. data/examples/v201502/campaign_management/validate_text_ad.rb +0 -110
  56. data/examples/v201502/error_handling/handle_partial_failures.rb +0 -130
  57. data/examples/v201502/error_handling/handle_policy_violation_error.rb +0 -141
  58. data/examples/v201502/extensions/add_google_my_business_location_extensions.rb +0 -179
  59. data/examples/v201502/extensions/add_site_links.rb +0 -164
  60. data/examples/v201502/extensions/add_site_links_using_feeds.rb +0 -271
  61. data/examples/v201502/migration/migrate_to_extension_settings.rb +0 -386
  62. data/examples/v201502/migration/upgrade_ad_url.rb +0 -93
  63. data/examples/v201502/misc/create_ad_words_session_without_properties_file.rb +0 -92
  64. data/examples/v201502/misc/get_all_images_and_videos.rb +0 -104
  65. data/examples/v201502/misc/setup_oauth2.rb +0 -84
  66. data/examples/v201502/misc/upload_image.rb +0 -93
  67. data/examples/v201502/misc/use_oauth2_jwt.rb +0 -93
  68. data/examples/v201502/optimization/estimate_keyword_traffic.rb +0 -146
  69. data/examples/v201502/optimization/get_keyword_bid_simulations.rb +0 -95
  70. data/examples/v201502/optimization/get_keyword_ideas.rb +0 -126
  71. data/examples/v201502/remarketing/add_audience.rb +0 -118
  72. data/examples/v201502/remarketing/add_conversion_tracker.rb +0 -100
  73. data/examples/v201502/remarketing/add_rule_based_user_lists.rb +0 -167
  74. data/examples/v201502/reporting/download_criteria_report.rb +0 -85
  75. data/examples/v201502/reporting/download_criteria_report_with_awql.rb +0 -84
  76. data/examples/v201502/reporting/get_report_fields.rb +0 -75
  77. data/examples/v201502/reporting/parallel_report_download.rb +0 -166
  78. data/examples/v201502/shopping_campaigns/add_product_partition_tree.rb +0 -267
  79. data/examples/v201502/shopping_campaigns/add_product_scope.rb +0 -129
  80. data/examples/v201502/shopping_campaigns/add_shopping_campaign.rb +0 -129
  81. data/examples/v201502/shopping_campaigns/get_product_category_taxonomy.rb +0 -115
  82. data/examples/v201502/targeting/add_campaign_targeting_criteria.rb +0 -169
  83. data/examples/v201502/targeting/add_demographic_targeting_criteria.rb +0 -112
  84. data/examples/v201502/targeting/get_campaign_targeting_criteria.rb +0 -106
  85. data/examples/v201502/targeting/get_targetable_languages_and_carriers.rb +0 -89
  86. data/examples/v201502/targeting/lookup_location.rb +0 -108
  87. data/lib/adwords_api/v201502/account_label_service.rb +0 -46
  88. data/lib/adwords_api/v201502/account_label_service_registry.rb +0 -46
  89. data/lib/adwords_api/v201502/ad_customizer_feed_service.rb +0 -46
  90. data/lib/adwords_api/v201502/ad_customizer_feed_service_registry.rb +0 -46
  91. data/lib/adwords_api/v201502/ad_group_ad_service.rb +0 -70
  92. data/lib/adwords_api/v201502/ad_group_ad_service_registry.rb +0 -46
  93. data/lib/adwords_api/v201502/ad_group_bid_modifier_service.rb +0 -54
  94. data/lib/adwords_api/v201502/ad_group_bid_modifier_service_registry.rb +0 -46
  95. data/lib/adwords_api/v201502/ad_group_criterion_service.rb +0 -62
  96. data/lib/adwords_api/v201502/ad_group_criterion_service_registry.rb +0 -46
  97. data/lib/adwords_api/v201502/ad_group_extension_setting_service.rb +0 -54
  98. data/lib/adwords_api/v201502/ad_group_extension_setting_service_registry.rb +0 -46
  99. data/lib/adwords_api/v201502/ad_group_feed_service.rb +0 -54
  100. data/lib/adwords_api/v201502/ad_group_feed_service_registry.rb +0 -46
  101. data/lib/adwords_api/v201502/ad_group_service.rb +0 -62
  102. data/lib/adwords_api/v201502/ad_group_service_registry.rb +0 -46
  103. data/lib/adwords_api/v201502/ad_param_service.rb +0 -46
  104. data/lib/adwords_api/v201502/ad_param_service_registry.rb +0 -46
  105. data/lib/adwords_api/v201502/adwords_user_list_service.rb +0 -46
  106. data/lib/adwords_api/v201502/adwords_user_list_service_registry.rb +0 -46
  107. data/lib/adwords_api/v201502/bidding_strategy_service.rb +0 -54
  108. data/lib/adwords_api/v201502/bidding_strategy_service_registry.rb +0 -46
  109. data/lib/adwords_api/v201502/budget_order_service.rb +0 -54
  110. data/lib/adwords_api/v201502/budget_order_service_registry.rb +0 -46
  111. data/lib/adwords_api/v201502/budget_service.rb +0 -54
  112. data/lib/adwords_api/v201502/budget_service_registry.rb +0 -46
  113. data/lib/adwords_api/v201502/campaign_criterion_service.rb +0 -54
  114. data/lib/adwords_api/v201502/campaign_criterion_service_registry.rb +0 -46
  115. data/lib/adwords_api/v201502/campaign_extension_setting_service.rb +0 -54
  116. data/lib/adwords_api/v201502/campaign_extension_setting_service_registry.rb +0 -46
  117. data/lib/adwords_api/v201502/campaign_feed_service.rb +0 -54
  118. data/lib/adwords_api/v201502/campaign_feed_service_registry.rb +0 -46
  119. data/lib/adwords_api/v201502/campaign_service.rb +0 -62
  120. data/lib/adwords_api/v201502/campaign_service_registry.rb +0 -46
  121. data/lib/adwords_api/v201502/campaign_shared_set_service.rb +0 -46
  122. data/lib/adwords_api/v201502/campaign_shared_set_service_registry.rb +0 -46
  123. data/lib/adwords_api/v201502/constant_data_service.rb +0 -102
  124. data/lib/adwords_api/v201502/constant_data_service_registry.rb +0 -46
  125. data/lib/adwords_api/v201502/conversion_tracker_service.rb +0 -54
  126. data/lib/adwords_api/v201502/conversion_tracker_service_registry.rb +0 -46
  127. data/lib/adwords_api/v201502/customer_extension_setting_service.rb +0 -54
  128. data/lib/adwords_api/v201502/customer_extension_setting_service_registry.rb +0 -46
  129. data/lib/adwords_api/v201502/customer_feed_service.rb +0 -54
  130. data/lib/adwords_api/v201502/customer_feed_service_registry.rb +0 -46
  131. data/lib/adwords_api/v201502/customer_service.rb +0 -46
  132. data/lib/adwords_api/v201502/customer_service_registry.rb +0 -46
  133. data/lib/adwords_api/v201502/customer_sync_service.rb +0 -38
  134. data/lib/adwords_api/v201502/customer_sync_service_registry.rb +0 -47
  135. data/lib/adwords_api/v201502/data_service.rb +0 -78
  136. data/lib/adwords_api/v201502/data_service_registry.rb +0 -46
  137. data/lib/adwords_api/v201502/experiment_service.rb +0 -46
  138. data/lib/adwords_api/v201502/experiment_service_registry.rb +0 -46
  139. data/lib/adwords_api/v201502/feed_item_service.rb +0 -54
  140. data/lib/adwords_api/v201502/feed_item_service_registry.rb +0 -46
  141. data/lib/adwords_api/v201502/feed_mapping_service.rb +0 -54
  142. data/lib/adwords_api/v201502/feed_mapping_service_registry.rb +0 -46
  143. data/lib/adwords_api/v201502/feed_service.rb +0 -54
  144. data/lib/adwords_api/v201502/feed_service_registry.rb +0 -46
  145. data/lib/adwords_api/v201502/geo_location_service.rb +0 -38
  146. data/lib/adwords_api/v201502/geo_location_service_registry.rb +0 -46
  147. data/lib/adwords_api/v201502/label_service.rb +0 -54
  148. data/lib/adwords_api/v201502/label_service_registry.rb +0 -46
  149. data/lib/adwords_api/v201502/location_criterion_service.rb +0 -46
  150. data/lib/adwords_api/v201502/location_criterion_service_registry.rb +0 -46
  151. data/lib/adwords_api/v201502/managed_customer_service.rb +0 -78
  152. data/lib/adwords_api/v201502/managed_customer_service_registry.rb +0 -46
  153. data/lib/adwords_api/v201502/media_service.rb +0 -54
  154. data/lib/adwords_api/v201502/media_service_registry.rb +0 -46
  155. data/lib/adwords_api/v201502/mutate_job_service.rb +0 -54
  156. data/lib/adwords_api/v201502/mutate_job_service_registry.rb +0 -46
  157. data/lib/adwords_api/v201502/offline_conversion_feed_service.rb +0 -38
  158. data/lib/adwords_api/v201502/offline_conversion_feed_service_registry.rb +0 -46
  159. data/lib/adwords_api/v201502/report_definition_service.rb +0 -38
  160. data/lib/adwords_api/v201502/report_definition_service_registry.rb +0 -46
  161. data/lib/adwords_api/v201502/shared_criterion_service.rb +0 -46
  162. data/lib/adwords_api/v201502/shared_criterion_service_registry.rb +0 -46
  163. data/lib/adwords_api/v201502/shared_set_service.rb +0 -46
  164. data/lib/adwords_api/v201502/shared_set_service_registry.rb +0 -46
  165. data/lib/adwords_api/v201502/targeting_idea_service.rb +0 -38
  166. data/lib/adwords_api/v201502/targeting_idea_service_registry.rb +0 -46
  167. data/lib/adwords_api/v201502/traffic_estimator_service.rb +0 -38
  168. data/lib/adwords_api/v201502/traffic_estimator_service_registry.rb +0 -46
  169. data/test/templates/v201502/basic_operations_get_campaigns.def +0 -116
  170. data/test/templates/v201502/misc_use_oauth2_service_account.def +0 -131
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YWE0OTA1NTlhMzhjOTI1YjJmODhlZThjMWU2YjNhNTc1MjgzNmNkZA==
5
- data.tar.gz: !binary |-
6
- NThjZDRkYmNiMjQyY2E5ZTIzM2VkMmE1MWE1OGI3ZTFjZGFkOGVjYQ==
2
+ SHA1:
3
+ metadata.gz: 916926a4584ed9782e9efb72932b0c39b90473cc
4
+ data.tar.gz: 48a8aa5a00664fb2116662b84df12d07a9845e10
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- Y2IzYTNjMjE1ZDZmYjEzNWM5YzhlYTYzNjlhYzQ2MGUxOTM0ZGMxN2U4OWUz
10
- ZTc4NTZlZDlhZjI5YWIzMzcxMWQ4OTJiZjliYzE5ZDhhYzU2NWQyNTA1ZDQ5
11
- ZDcyMDFjZWUyOGViYzM1ZDlkOTEwNTE2ZjhkY2IxZDI5MmEzZTA=
12
- data.tar.gz: !binary |-
13
- ZjIxYTIwYmNiMDJmZmQxMDI0ZGUzNTM3ZTdhODIwZGI5OWQ5YmFmOTUwYzQ5
14
- MmNlMDU2ODZmZTBjN2ViOTJiYjBmZjMxYTIzM2ZlZmMwZDY0NzA0MjFiZDg0
15
- ODlmY2FmZTliN2Y4NjE5Yzc0ZjVkY2Y3ZGZmZmJhZTYzZTk3MWE=
6
+ metadata.gz: 5b87032f752d27c955deedeee692a1db207e4d8d96050be8d3c1cb2b70a1dfb12eaa0b0e77324a18fb8ee4f503003af3e48d33637cc41293b7bc7572eb811ca3
7
+ data.tar.gz: 1847b728836bbad92cac627a709f3e8a4b7e574009143507d6b48f99179b66f5593ce68c2d6e695730702faa2abb4ae7a3c9aed3b9ad0d30cbc6489f6d79fceb
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ 0.18.0:
2
+ - Removed deprecated API version v201502.
3
+ - Support for streaming report requests in report_utils.
4
+ - Require google-ads-common 0.11.1 or later from now on.
5
+
1
6
  0.17.0:
2
7
  - Support and examples for v201509.
3
8
  - Require google-ads-common 0.11.0 or later from now on.
data/README.md CHANGED
@@ -74,7 +74,7 @@ The basics of making a request are:
74
74
 
75
75
  3. Specify which service you're looking to use, and which version:
76
76
 
77
- campaign_srv = adwords.service(:CampaignService, :v201502)
77
+ campaign_srv = adwords.service(:CampaignService, :v201509)
78
78
 
79
79
  4. You should now be able to just use the API methods in the returned object:
80
80
 
@@ -211,7 +211,7 @@ To target a specific version:
211
211
 
212
212
  For example:
213
213
 
214
- $ rake generate[v201502]
214
+ $ rake generate[v201509]
215
215
 
216
216
  To target a specific service in a specific version:
217
217
 
@@ -219,7 +219,7 @@ To target a specific service in a specific version:
219
219
 
220
220
  For example:
221
221
 
222
- $ rake generate[v201502,CampaignService]
222
+ $ rake generate[v201509,CampaignService]
223
223
 
224
224
  To build the gems:
225
225
 
@@ -17,6 +17,9 @@
17
17
  #:oauth2_state: INSERT_OAUTH2_STATE_HERE
18
18
  #:oauth2_access_type: INSERT_OAUTH2_ACCESS_TYPE_HERE
19
19
  #:oauth2_approval_prompt: INSERT_OAUTH2_APPROVAL_PROMPT_HERE
20
+ # You can define extra scopes so that you can reuse your refresh token for
21
+ # other APIs.
22
+ #:oauth2_extra_scopes: [INSERT_EXTRA_SCOPES_HERE]
20
23
 
21
24
  # Auth parameters for OAUTH2_SERVICE_ACCOUNT method. See:
22
25
  # https://developers.google.com/accounts/docs/OAuth2ServiceAccount
@@ -52,42 +52,36 @@ def add_complete_campaigns_using_batch_job()
52
52
  temp_id_generator = TempIdGenerator.new()
53
53
 
54
54
  # Create an array of hashed operations generated from the batch_job_utils.
55
- hashed_operations = []
55
+ operations = []
56
56
 
57
57
  # Create an operation to create a new budget.
58
58
  budget_operation = build_budget_operation(temp_id_generator)
59
- hashed_operations += batch_job_utils.generate_soap_operations(
60
- [budget_operation])
59
+ operations << budget_operation
61
60
 
62
61
  # Create operations to create new campaigns.
63
62
  campaign_operations = build_campaign_operations(
64
63
  temp_id_generator, budget_operation)
65
- hashed_operations += batch_job_utils.generate_soap_operations(
66
- campaign_operations)
64
+ operations += campaign_operations
67
65
 
68
66
  # Create operations to create new negative keyword criteria for each
69
67
  # campaign.
70
- hashed_operations += batch_job_utils.generate_soap_operations(
71
- build_campaign_criterion_operations(campaign_operations))
68
+ operations += build_campaign_criterion_operations(campaign_operations)
72
69
 
73
70
  # Create operations to create new ad groups.
74
71
  ad_group_operations = build_ad_group_operations(
75
72
  temp_id_generator, campaign_operations)
76
- hashed_operations += batch_job_utils.generate_soap_operations(
77
- ad_group_operations)
73
+ operations += ad_group_operations
78
74
 
79
75
  # Create operations to create new ad group criteria (keywords).
80
- hashed_operations += batch_job_utils.generate_soap_operations(
81
- build_ad_group_criterion_operations(ad_group_operations))
76
+ operations += build_ad_group_criterion_operations(ad_group_operations)
82
77
 
83
78
  # Create operations to create new ad group ads (text ads).
84
- hashed_operations += batch_job_utils.generate_soap_operations(
85
- build_ad_group_ad_operations(ad_group_operations))
79
+ operations += build_ad_group_ad_operations(ad_group_operations)
86
80
 
87
81
  # Use the batch_job_utils to upload all operations.
88
- batch_job_utils.post_soap_operations(hashed_operations, upload_url)
82
+ batch_job_utils.upload_operations(operations, upload_url)
89
83
  puts "Uploaded %d operations for batch job with ID %d." %
90
- [hashed_operations.size, batch_job[:id]]
84
+ [operations.size, batch_job[:id]]
91
85
 
92
86
  # Poll for completion of the batch job using an exponential back off.
93
87
  poll_attempts = 0
@@ -104,7 +98,7 @@ def add_complete_campaigns_using_batch_job()
104
98
 
105
99
  begin
106
100
  sleep_seconds = 30 * (2 ** poll_attempts)
107
- puts "Sleeping %d seconds" % sleep_seconds
101
+ puts "Sleeping for %d seconds" % sleep_seconds
108
102
  sleep(sleep_seconds)
109
103
 
110
104
  batch_job = batch_job_srv.get(selector)[:entries].first
@@ -0,0 +1,179 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+ #
4
+ # Copyright:: Copyright 2015, Google Inc. All Rights Reserved.
5
+ #
6
+ # License:: Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
+ # implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ # This example illustrates how to perform multiple requests using the
20
+ # BatchJobService using incremental uploads.
21
+
22
+ require 'adwords_api'
23
+
24
+ def add_keywords_using_incremental_batch_job(ad_group_id)
25
+ # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
26
+ # when called without parameters.
27
+ adwords = AdwordsApi::Api.new
28
+
29
+ # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
30
+ # the configuration file or provide your own logger:
31
+ # adwords.logger = Logger.new('adwords_xml.log')
32
+
33
+ batch_job_srv = adwords.service(:BatchJobService, API_VERSION)
34
+ batch_job_utils = adwords.batch_job_utils(API_VERSION)
35
+
36
+ # Create a BatchJob.
37
+ add_op = {
38
+ :operator => 'ADD',
39
+ :operand => {}
40
+ }
41
+
42
+ response = batch_job_srv.mutate([add_op])
43
+ batch_job = response[:value].first
44
+
45
+ # Get the upload URL from the new job.
46
+ upload_url = batch_job[:upload_url][:url]
47
+ puts "Created BatchJob with ID %d, status '%s', and upload URL %s." %
48
+ [batch_job[:id], batch_job[:status], upload_url]
49
+
50
+ # Upload #1
51
+ incremental_helper = batch_job_utils.start_incremental_upload(upload_url)
52
+ operations = create_keyword_operations(ad_group_id)
53
+ incremental_helper.upload(operations)
54
+
55
+ # Upload #2
56
+ operations = create_keyword_operations(ad_group_id)
57
+ incremental_helper.upload(operations)
58
+
59
+ # Upload #3
60
+ operations = create_keyword_operations(ad_group_id)
61
+ incremental_helper.upload(operations, true)
62
+
63
+ # Poll for completion of the batch job using an exponential back off.
64
+ poll_attempts = 0
65
+ is_pending = true
66
+ selector = {
67
+ :fields =>
68
+ ['Id', 'Status', 'DownloadUrl', 'ProcessingErrors', 'ProgressStats'],
69
+ :predicates => [{
70
+ :field => 'Id',
71
+ :operator => 'IN',
72
+ :values => [batch_job[:id]]
73
+ }]
74
+ }
75
+
76
+ begin
77
+ sleep_seconds = 30 * (2 ** poll_attempts)
78
+ puts "Sleeping for %d seconds" % sleep_seconds
79
+ sleep(sleep_seconds)
80
+
81
+ batch_job = batch_job_srv.get(selector)[:entries].first
82
+
83
+ puts "Batch job ID %d has status '%s'." %
84
+ [batch_job[:id], batch_job[:status]]
85
+
86
+ poll_attempts += 1
87
+ is_pending = PENDING_STATUSES.include?(batch_job[:status])
88
+ end while is_pending and poll_attempts < MAX_POLL_ATTEMPTS
89
+
90
+ if is_pending
91
+ raise StandardError,
92
+ "Job is still in pending state after polling %d times." %
93
+ MAX_POLL_ATTEMPTS
94
+ end
95
+
96
+ unless batch_job[:processing_errors].nil?
97
+ batch_job[:processing_errors].each_with_index do |processing_error, i|
98
+ puts ("Processing error [%d]: errorType=%s, trigger=%s, errorString=%s" +
99
+ "fieldPath=%s, reason=%s") % [i, processing_error[:api_error_type],
100
+ processing_error[:trigger], processing_error[:error_string],
101
+ processing_error[:field_path], processing_error[:reason]]
102
+ end
103
+ end
104
+
105
+ unless batch_job[:download_url].nil? or batch_job[:download_url][:url].nil?
106
+ mutate_response = batch_job_utils.get_job_results(
107
+ batch_job[:download_url][:url])
108
+ puts "Downloaded results from '%s':" % batch_job[:download_url][:url]
109
+ mutate_response.each do |mutate_result|
110
+ outcome = "FAILURE"
111
+ outcome = "SUCCESS" if mutate_result[:error_list].nil?
112
+ puts " Operation [%d] - %s" % [mutate_result[:index], outcome]
113
+ end
114
+ end
115
+ end
116
+
117
+ def create_keyword_operations(ad_group_id)
118
+ operations = []
119
+ KEYWORD_COUNT.times do |i|
120
+ text = "keyword %d" % i
121
+
122
+ # Make 10% of keywords invalid to demonstrate error handling.
123
+ text = text + "!!!" if i % 10 == 0
124
+ keyword = {
125
+ :xsi_type => 'Keyword',
126
+ :text => text,
127
+ :match_type => 'BROAD'
128
+ }
129
+ biddable_criterion = {
130
+ :xsi_type => 'BiddableAdGroupCriterion',
131
+ :ad_group_id => ad_group_id,
132
+ :criterion => keyword
133
+ }
134
+ operation = {
135
+ :xsi_type => 'AdGroupCriterionOperation',
136
+ :operator => 'ADD',
137
+ :operand => biddable_criterion
138
+ }
139
+ operations << operation
140
+ end
141
+
142
+ return operations
143
+ end
144
+
145
+ if __FILE__ == $0
146
+ API_VERSION = :v201509
147
+ KEYWORD_COUNT = 100
148
+ MAX_POLL_ATTEMPTS = 5
149
+ PENDING_STATUSES = ['ACTIVE', 'AWAITING_FILE']
150
+
151
+ begin
152
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
153
+
154
+ add_keywords_using_incremental_batch_job(ad_group_id)
155
+
156
+ # Authorization error.
157
+ rescue AdsCommon::Errors::OAuth2VerificationRequired => e
158
+ puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
159
+ "OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
160
+ "to retrieve and store OAuth2 tokens."
161
+ puts "See this wiki page for more details:\n\n " +
162
+ 'https://github.com/googleads/google-api-ads-ruby/wiki/OAuth2'
163
+
164
+ # HTTP errors.
165
+ rescue AdsCommon::Errors::HttpError => e
166
+ puts "HTTP Error: %s" % e
167
+
168
+ # API errors.
169
+ rescue AdwordsApi::Errors::ApiException => e
170
+ puts "Message: %s" % e.message
171
+ puts 'Errors:'
172
+ e.errors.each_with_index do |error, index|
173
+ puts "\tError [%d]:" % (index + 1)
174
+ error.each do |field, value|
175
+ puts "\t\t%s: %s" % [field, value]
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+ #
4
+ # Copyright:: Copyright 2015, Google Inc. All Rights Reserved.
5
+ #
6
+ # License:: Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
+ # implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ # This example streams the results of an Ad Hoc report to a file.
20
+
21
+ require 'adwords_api'
22
+
23
+ def stream_criteria_report_results()
24
+ # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
25
+ # when called without parameters.
26
+ adwords = AdwordsApi::Api.new
27
+
28
+ # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
29
+ # the configuration file or provide your own logger:
30
+ # adwords.logger = Logger.new('adwords_xml.log')
31
+
32
+ # Get report utilities for the version.
33
+ report_utils = adwords.report_utils(API_VERSION)
34
+
35
+ # Define report query.
36
+ report_query = 'SELECT Id, AdNetworkType1, Impressions ' +
37
+ 'FROM CRITERIA_PERFORMANCE_REPORT ' +
38
+ 'WHERE Status IN [ENABLED, PAUSED] ' +
39
+ 'DURING LAST_7_DAYS'
40
+
41
+ # Optional: Set the configuration of the API instance to suppress header,
42
+ # column name, or summary rows in the report output. You can also configure
43
+ # this in your adwords_api.yml configuration file.
44
+ adwords.skip_report_header = true
45
+ adwords.skip_column_header = true
46
+ adwords.skip_report_summary = true
47
+ # Enable to allow rows with zero impressions to show.
48
+ adwords.include_zero_impressions = false
49
+
50
+ # Set the default value of the hash to 0 to allow easy totaling.
51
+ ad_network_map = Hash.new(0)
52
+
53
+ # We use get_stream_helper_with_awql.each_line here, which uses the
54
+ # ReportStream utility to handle breaking the streamed results into lines
55
+ # for easy processing. If you'd rather handle processing yourself, you can
56
+ # use download_report_as_stream_with_awql, which just passes data to the
57
+ # block as it's downloaded, without breaking it up into meaningful chunks.
58
+ report_utils.get_stream_helper_with_awql(
59
+ report_query, 'CSV').each_line do |line|
60
+ process_line(line, ad_network_map)
61
+ end
62
+
63
+ puts 'Total impressions by ad network type 1:'
64
+ ad_network_map.each do |ad_network_type, total_impressions|
65
+ puts ' %s: %s' % [ad_network_type, total_impressions]
66
+ end
67
+ end
68
+
69
+ def process_line(line, ad_network_map)
70
+ id, ad_network_type_1, impressions = line.split(',')
71
+ ad_network_map[ad_network_type_1] += impressions
72
+ end
73
+
74
+ if __FILE__ == $0
75
+ API_VERSION = :v201509
76
+
77
+ begin
78
+ # File name to write report to.
79
+ stream_criteria_report_results()
80
+
81
+ # Authorization error.
82
+ rescue AdsCommon::Errors::OAuth2VerificationRequired => e
83
+ puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
84
+ "OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
85
+ "to retrieve and store OAuth2 tokens."
86
+ puts "See this wiki page for more details:\n\n " +
87
+ 'https://github.com/googleads/google-api-ads-ruby/wiki/OAuth2'
88
+
89
+ # HTTP errors.
90
+ rescue AdsCommon::Errors::HttpError => e
91
+ puts "HTTP Error: %s" % e
92
+
93
+ # API errors.
94
+ rescue AdwordsApi::Errors::ReportError => e
95
+ puts "Reporting Error: %s" % e.message
96
+ end
97
+ end
@@ -43,49 +43,6 @@ module AdwordsApi
43
43
 
44
44
  # Configure the services available to each version
45
45
  @@service_config = {
46
- :v201502 => [
47
- :AccountLabelService,
48
- :AdCustomizerFeedService,
49
- :AdGroupAdService,
50
- :AdGroupBidModifierService,
51
- :AdGroupCriterionService,
52
- :AdGroupExtensionSettingService,
53
- :AdGroupFeedService,
54
- :AdGroupService,
55
- :AdParamService,
56
- :AdwordsUserListService,
57
- :BiddingStrategyService,
58
- :BudgetOrderService,
59
- :BudgetService,
60
- :CampaignCriterionService,
61
- :CampaignExtensionSettingService,
62
- :CampaignFeedService,
63
- :CampaignService,
64
- :CampaignSharedSetService,
65
- :ConstantDataService,
66
- :ConversionTrackerService,
67
- :CustomerExtensionSettingService,
68
- :CustomerFeedService,
69
- :CustomerService,
70
- :CustomerSyncService,
71
- :DataService,
72
- :ExperimentService,
73
- :FeedItemService,
74
- :FeedMappingService,
75
- :FeedService,
76
- :GeoLocationService,
77
- :LabelService,
78
- :LocationCriterionService,
79
- :ManagedCustomerService,
80
- :MediaService,
81
- :MutateJobService,
82
- :OfflineConversionFeedService,
83
- :ReportDefinitionService,
84
- :SharedCriterionService,
85
- :SharedSetService,
86
- :TargetingIdeaService,
87
- :TrafficEstimatorService
88
- ],
89
46
  :v201506 => [
90
47
  :AccountLabelService,
91
48
  :AdCustomizerFeedService,
@@ -179,7 +136,6 @@ module AdwordsApi
179
136
  :PRODUCTION => {
180
137
  :oauth_scope => 'https://www.googleapis.com/auth/adwords',
181
138
  :header_ns => 'https://adwords.google.com/api/adwords/cm/',
182
- :v201502 => 'https://adwords.google.com/api/adwords/',
183
139
  :v201506 => 'https://adwords.google.com/api/adwords/',
184
140
  :v201509 => 'https://adwords.google.com/api/adwords/'
185
141
  }
@@ -188,48 +144,6 @@ module AdwordsApi
188
144
  # Configure the subdirectories for each version / service pair.
189
145
  # A missing pair means that only the base URL is used.
190
146
  @@subdir_config = {
191
- # v201502
192
- [:v201502, :AccountLabelService] => 'mcm/',
193
- [:v201502, :AdCustomizerFeedService] => 'cm/',
194
- [:v201502, :AdGroupAdService] => 'cm/',
195
- [:v201502, :AdGroupBidModifierService] => 'cm/',
196
- [:v201502, :AdGroupCriterionService] => 'cm/',
197
- [:v201502, :AdGroupExtensionSettingService] => 'cm/',
198
- [:v201502, :AdGroupFeedService] => 'cm/',
199
- [:v201502, :AdGroupService] => 'cm/',
200
- [:v201502, :AdParamService] => 'cm/',
201
- [:v201502, :BudgetOrderService] => 'billing/',
202
- [:v201502, :CampaignCriterionService] => 'cm/',
203
- [:v201502, :CampaignExtensionSettingService] => 'cm/',
204
- [:v201502, :CampaignFeedService] => 'cm/',
205
- [:v201502, :CampaignService] => 'cm/',
206
- [:v201502, :CampaignSharedSetService] => 'cm/',
207
- [:v201502, :ConstantDataService] => 'cm/',
208
- [:v201502, :ConversionTrackerService] => 'cm/',
209
- [:v201502, :CustomerExtensionSettingService] => 'cm/',
210
- [:v201502, :CustomerSyncService] => 'ch/',
211
- [:v201502, :DataService] => 'cm/',
212
- [:v201502, :ExperimentService] => 'cm/',
213
- [:v201502, :FeedItemService] => 'cm/',
214
- [:v201502, :FeedMappingService] => 'cm/',
215
- [:v201502, :FeedService] => 'cm/',
216
- [:v201502, :GeoLocationService] => 'cm/',
217
- [:v201502, :LocationCriterionService] => 'cm/',
218
- [:v201502, :MediaService] => 'cm/',
219
- [:v201502, :MutateJobService] => 'cm/',
220
- [:v201502, :OfflineConversionFeedService] => 'cm/',
221
- [:v201502, :ReportDefinitionService] => 'cm/',
222
- [:v201502, :SharedCriterionService] => 'cm/',
223
- [:v201502, :SharedSetService] => 'cm/',
224
- [:v201502, :TargetingIdeaService] => 'o/',
225
- [:v201502, :TrafficEstimatorService] => 'o/',
226
- [:v201502, :ManagedCustomerService] => 'mcm/',
227
- [:v201502, :CustomerService] => 'mcm/',
228
- [:v201502, :CustomerFeedService] => 'cm/',
229
- [:v201502, :BudgetService] => 'cm/',
230
- [:v201502, :BiddingStrategyService] => 'cm/',
231
- [:v201502, :AdwordsUserListService] => 'rm/',
232
- [:v201502, :LabelService] => 'cm/',
233
147
  # v201506
234
148
  [:v201506, :AccountLabelService] => 'mcm/',
235
149
  [:v201506, :AdCustomizerFeedService] => 'cm/',