google-adwords-api 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/ChangeLog +6 -0
  2. data/README +3 -3
  3. data/examples/{v201206/basic_operations/delete_ad_group.rb → v201209/adwords_for_video/add_video_campaign.rb} +41 -40
  4. data/examples/{v201206/basic_operations/pause_ad.rb → v201209/adwords_for_video/find_videos.rb} +33 -25
  5. data/examples/{v201206/basic_operations/get_keywords.rb → v201209/adwords_for_video/get_keyword_criteria.rb} +24 -27
  6. data/examples/{v201206/basic_operations/get_campaigns_with_awql.rb → v201209/adwords_for_video/get_targeting_groups.rb} +26 -18
  7. data/examples/{v201206/basic_operations/get_ad_groups.rb → v201209/adwords_for_video/get_video_campaign_criteria.rb} +22 -21
  8. data/examples/v201209/adwords_for_video/get_video_campaign_stats.rb +126 -0
  9. data/examples/{v201206/basic_operations/get_campaigns.rb → v201209/adwords_for_video/get_video_campaigns.rb} +16 -15
  10. data/examples/v201302/advanced_operations/create_and_attach_shared_keyword_set.rb +139 -0
  11. data/examples/v201302/advanced_operations/find_and_remove_criteria_from_shared_set.rb +173 -0
  12. data/lib/adwords_api/api_config.rb +17 -59
  13. data/lib/adwords_api/report_utils.rb +3 -19
  14. data/lib/adwords_api/{v201206/ad_param_service.rb → v201209/video_ad_service.rb} +8 -8
  15. data/lib/adwords_api/v201209/video_ad_service_registry.rb +46 -0
  16. data/lib/adwords_api/{v201206/campaign_ad_extension_service.rb → v201209/video_campaign_criterion_service.rb} +8 -8
  17. data/lib/adwords_api/v201209/video_campaign_criterion_service_registry.rb +47 -0
  18. data/lib/adwords_api/{v201206/bulk_mutate_job_service.rb → v201209/video_campaign_service.rb} +8 -8
  19. data/lib/adwords_api/v201209/video_campaign_service_registry.rb +46 -0
  20. data/lib/adwords_api/v201209/video_service.rb +42 -0
  21. data/lib/adwords_api/v201209/video_service_registry.rb +46 -0
  22. data/lib/adwords_api/{v201206/ad_group_ad_service.rb → v201209/video_targeting_group_criterion_service.rb} +8 -12
  23. data/lib/adwords_api/v201209/video_targeting_group_criterion_service_registry.rb +46 -0
  24. data/lib/adwords_api/{v201206/ad_extension_override_service.rb → v201209/video_targeting_group_service.rb} +8 -8
  25. data/lib/adwords_api/v201209/video_targeting_group_service_registry.rb +46 -0
  26. data/lib/adwords_api/v201302/ad_group_feed_service.rb +1 -1
  27. data/lib/adwords_api/v201302/ad_group_feed_service_registry.rb +2 -2
  28. data/lib/adwords_api/v201302/campaign_feed_service.rb +1 -1
  29. data/lib/adwords_api/v201302/campaign_feed_service_registry.rb +2 -2
  30. data/lib/adwords_api/v201302/feed_item_service.rb +1 -1
  31. data/lib/adwords_api/v201302/feed_item_service_registry.rb +3 -4
  32. data/lib/adwords_api/v201302/feed_service.rb +1 -1
  33. data/lib/adwords_api/v201302/feed_service_registry.rb +4 -5
  34. data/lib/adwords_api/{v201206/user_list_service.rb → v201302/shared_set_service.rb} +9 -9
  35. data/lib/adwords_api/v201302/shared_set_service_registry.rb +47 -0
  36. data/lib/adwords_api/version.rb +1 -1
  37. data/test/adwords_api/test_report_utils.rb +0 -89
  38. data/test/examples/v201302/test_advanced_operations.rb +10 -0
  39. data/test/templates/v201209/basic_operations_get_campaigns.def +1 -1
  40. data/test/templates/v201302/basic_operations_get_campaigns.def +1 -1
  41. data/test/templates/v201302/misc_use_oauth2_jwt.def +131 -0
  42. data/test/test_utils.rb +6 -2
  43. metadata +26 -121
  44. data/examples/v201206/account_management/create_account.rb +0 -87
  45. data/examples/v201206/account_management/get_account_alerts.rb +0 -114
  46. data/examples/v201206/account_management/get_account_changes.rb +0 -137
  47. data/examples/v201206/account_management/get_account_hierarchy.rb +0 -95
  48. data/examples/v201206/account_management/get_client_customer_id.rb +0 -88
  49. data/examples/v201206/account_management/get_client_unit_usage.rb +0 -90
  50. data/examples/v201206/basic_operations/add_ad_groups.rb +0 -136
  51. data/examples/v201206/basic_operations/add_campaigns.rb +0 -151
  52. data/examples/v201206/basic_operations/add_keywords.rb +0 -108
  53. data/examples/v201206/basic_operations/add_text_ads.rb +0 -105
  54. data/examples/v201206/basic_operations/delete_ad.rb +0 -85
  55. data/examples/v201206/basic_operations/delete_campaign.rb +0 -103
  56. data/examples/v201206/basic_operations/delete_keyword.rb +0 -90
  57. data/examples/v201206/basic_operations/get_text_ads.rb +0 -106
  58. data/examples/v201206/basic_operations/update_ad_group.rb +0 -81
  59. data/examples/v201206/basic_operations/update_campaign.rb +0 -84
  60. data/examples/v201206/basic_operations/update_keyword.rb +0 -99
  61. data/examples/v201206/campaign_management/add_experiment.rb +0 -158
  62. data/examples/v201206/campaign_management/add_keywords_in_bulk.rb +0 -150
  63. data/examples/v201206/campaign_management/add_location_extension.rb +0 -117
  64. data/examples/v201206/campaign_management/add_location_extension_override.rb +0 -83
  65. data/examples/v201206/campaign_management/get_all_disapproved_ads.rb +0 -93
  66. data/examples/v201206/campaign_management/get_all_disapproved_ads_with_awql.rb +0 -84
  67. data/examples/v201206/campaign_management/promote_experiment.rb +0 -77
  68. data/examples/v201206/campaign_management/set_ad_parameters.rb +0 -114
  69. data/examples/v201206/campaign_management/validate_text_ad.rb +0 -106
  70. data/examples/v201206/error_handling/handle_captcha_challenge.rb +0 -93
  71. data/examples/v201206/error_handling/handle_partial_failures.rb +0 -126
  72. data/examples/v201206/error_handling/handle_policy_violation_error.rb +0 -137
  73. data/examples/v201206/error_handling/handle_two_factor_authorization_error.rb +0 -88
  74. data/examples/v201206/misc/get_all_images_and_videos.rb +0 -100
  75. data/examples/v201206/misc/upload_image.rb +0 -89
  76. data/examples/v201206/misc/use_oauth2.rb +0 -97
  77. data/examples/v201206/optimization/estimate_keyword_traffic.rb +0 -129
  78. data/examples/v201206/optimization/get_keyword_bid_simulations.rb +0 -92
  79. data/examples/v201206/optimization/get_keyword_ideas.rb +0 -114
  80. data/examples/v201206/optimization/get_placement_ideas.rb +0 -104
  81. data/examples/v201206/remarketing/add_audience.rb +0 -115
  82. data/examples/v201206/remarketing/add_conversion_tracker.rb +0 -97
  83. data/examples/v201206/reporting/download_criteria_report.rb +0 -79
  84. data/examples/v201206/reporting/download_criteria_report_with_awql.rb +0 -78
  85. data/examples/v201206/reporting/get_campaign_stats.rb +0 -105
  86. data/examples/v201206/reporting/get_report_fields.rb +0 -71
  87. data/examples/v201206/reporting/parallel_report_download.rb +0 -162
  88. data/examples/v201206/targeting/add_campaign_targeting_criteria.rb +0 -118
  89. data/examples/v201206/targeting/get_campaign_targeting_criteria.rb +0 -102
  90. data/examples/v201206/targeting/get_targetable_languages_and_carriers.rb +0 -86
  91. data/examples/v201206/targeting/lookup_location.rb +0 -104
  92. data/lib/adwords_api/v201206/ad_extension_override_service_registry.rb +0 -46
  93. data/lib/adwords_api/v201206/ad_group_ad_service_registry.rb +0 -46
  94. data/lib/adwords_api/v201206/ad_group_criterion_service.rb +0 -42
  95. data/lib/adwords_api/v201206/ad_group_criterion_service_registry.rb +0 -46
  96. data/lib/adwords_api/v201206/ad_group_service.rb +0 -42
  97. data/lib/adwords_api/v201206/ad_group_service_registry.rb +0 -46
  98. data/lib/adwords_api/v201206/ad_param_service_registry.rb +0 -46
  99. data/lib/adwords_api/v201206/alert_service.rb +0 -34
  100. data/lib/adwords_api/v201206/alert_service_registry.rb +0 -46
  101. data/lib/adwords_api/v201206/budget_order_service.rb +0 -42
  102. data/lib/adwords_api/v201206/budget_order_service_registry.rb +0 -46
  103. data/lib/adwords_api/v201206/bulk_mutate_job_service_registry.rb +0 -46
  104. data/lib/adwords_api/v201206/campaign_ad_extension_service_registry.rb +0 -46
  105. data/lib/adwords_api/v201206/campaign_criterion_service.rb +0 -42
  106. data/lib/adwords_api/v201206/campaign_criterion_service_registry.rb +0 -46
  107. data/lib/adwords_api/v201206/campaign_service.rb +0 -42
  108. data/lib/adwords_api/v201206/campaign_service_registry.rb +0 -46
  109. data/lib/adwords_api/v201206/constant_data_service.rb +0 -62
  110. data/lib/adwords_api/v201206/constant_data_service_registry.rb +0 -46
  111. data/lib/adwords_api/v201206/conversion_tracker_service.rb +0 -38
  112. data/lib/adwords_api/v201206/conversion_tracker_service_registry.rb +0 -46
  113. data/lib/adwords_api/v201206/customer_service.rb +0 -34
  114. data/lib/adwords_api/v201206/customer_service_registry.rb +0 -46
  115. data/lib/adwords_api/v201206/customer_sync_service.rb +0 -34
  116. data/lib/adwords_api/v201206/customer_sync_service_registry.rb +0 -47
  117. data/lib/adwords_api/v201206/data_service.rb +0 -38
  118. data/lib/adwords_api/v201206/data_service_registry.rb +0 -46
  119. data/lib/adwords_api/v201206/experiment_service.rb +0 -38
  120. data/lib/adwords_api/v201206/experiment_service_registry.rb +0 -46
  121. data/lib/adwords_api/v201206/geo_location_service.rb +0 -34
  122. data/lib/adwords_api/v201206/geo_location_service_registry.rb +0 -46
  123. data/lib/adwords_api/v201206/info_service.rb +0 -34
  124. data/lib/adwords_api/v201206/info_service_registry.rb +0 -46
  125. data/lib/adwords_api/v201206/location_criterion_service.rb +0 -34
  126. data/lib/adwords_api/v201206/location_criterion_service_registry.rb +0 -46
  127. data/lib/adwords_api/v201206/managed_customer_service.rb +0 -38
  128. data/lib/adwords_api/v201206/managed_customer_service_registry.rb +0 -46
  129. data/lib/adwords_api/v201206/media_service.rb +0 -38
  130. data/lib/adwords_api/v201206/media_service_registry.rb +0 -46
  131. data/lib/adwords_api/v201206/mutate_job_service.rb +0 -42
  132. data/lib/adwords_api/v201206/mutate_job_service_registry.rb +0 -46
  133. data/lib/adwords_api/v201206/report_definition_service.rb +0 -34
  134. data/lib/adwords_api/v201206/report_definition_service_registry.rb +0 -46
  135. data/lib/adwords_api/v201206/targeting_idea_service.rb +0 -38
  136. data/lib/adwords_api/v201206/targeting_idea_service_registry.rb +0 -46
  137. data/lib/adwords_api/v201206/traffic_estimator_service.rb +0 -34
  138. data/lib/adwords_api/v201206/traffic_estimator_service_registry.rb +0 -46
  139. data/lib/adwords_api/v201206/user_list_service_registry.rb +0 -46
  140. data/test/examples/v201206/test_account_management.rb +0 -60
  141. data/test/examples/v201206/test_basic_operations.rb +0 -177
  142. data/test/examples/v201206/test_campaign_management.rb +0 -124
  143. data/test/examples/v201206/test_error_handling.rb +0 -63
  144. data/test/examples/v201206/test_misc.rb +0 -39
  145. data/test/examples/v201206/test_optimization.rb +0 -63
  146. data/test/examples/v201206/test_remarketing.rb +0 -39
  147. data/test/examples/v201206/test_reporting.rb +0 -84
  148. data/test/examples/v201206/test_targeting.rb +0 -60
  149. data/test/examples/v201206/utils.rb +0 -244
  150. data/test/suite_exampletests_v201206.rb +0 -37
@@ -1,79 +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
-
23
- require 'adwords_api'
24
-
25
- def download_criteria_report(file_name)
26
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
27
- # when called without parameters.
28
- adwords = AdwordsApi::Api.new
29
-
30
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
31
- # the configuration file or provide your own logger:
32
- # adwords.logger = Logger.new('adwords_xml.log')
33
-
34
- # Get report utilities for the version.
35
- report_utils = adwords.report_utils(API_VERSION)
36
-
37
- # Define report definition. You can also pass your own XML text as a string.
38
- report_definition = {
39
- :selector => {
40
- :fields => ['CampaignId', 'AdGroupId', 'Id', 'Criteria', 'CriteriaType',
41
- 'Impressions', 'Clicks', 'Cost'],
42
- # Predicates are optional.
43
- :predicates => {
44
- :field => 'Status',
45
- :operator => 'IN',
46
- :values => ['ACTIVE', 'PAUSED']
47
- }
48
- },
49
- :report_name => 'Last 7 days CRITERIA_PERFORMANCE_REPORT',
50
- :report_type => 'CRITERIA_PERFORMANCE_REPORT',
51
- :download_format => 'CSV',
52
- :date_range_type => 'LAST_7_DAYS',
53
- # Enable to get rows with zero impressions.
54
- :include_zero_impressions => false
55
- }
56
-
57
- # Download report, using "download_report_as_file" utility method.
58
- # To retrieve the report as return value, use "download_report" method.
59
- report_utils.download_report_as_file(report_definition, file_name)
60
- puts "Report was downloaded to '%s'." % file_name
61
- end
62
-
63
- if __FILE__ == $0
64
- API_VERSION = :v201206
65
-
66
- begin
67
- # File name to write report to.
68
- file_name = 'INSERT_OUTPUT_FILE_NAME_HERE'
69
- download_criteria_report(file_name)
70
-
71
- # HTTP errors.
72
- rescue AdsCommon::Errors::HttpError => e
73
- puts "HTTP Error: %s" % e
74
-
75
- # API errors.
76
- rescue AdwordsApi::Errors::ReportError => e
77
- puts "Reporting Error: %s" % e.message
78
- end
79
- end
@@ -1,78 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
- #
6
- # Copyright:: Copyright 2012, 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 an Ad Hoc report using AdWords Query Language.
22
- # See AWQL guide for more details:
23
- # https://developers.google.com/adwords/api/docs/guides/awql
24
-
25
- require 'date'
26
-
27
- require 'adwords_api'
28
-
29
- def download_criteria_report_with_awql(file_name, report_format)
30
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
31
- # when called without parameters.
32
- adwords = AdwordsApi::Api.new
33
-
34
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
35
- # the configuration file or provide your own logger:
36
- # adwords.logger = Logger.new('adwords_xml.log')
37
-
38
- # Get report utilities for the version.
39
- report_utils = adwords.report_utils(API_VERSION)
40
-
41
- # Prepare a date range for the last week. Instead you can use 'LAST_7_DAYS'.
42
- date_range = '%s,%s' % [
43
- DateTime.parse((Date.today - 7).to_s).strftime('%Y%m%d'),
44
- DateTime.parse((Date.today - 1).to_s).strftime('%Y%m%d')
45
- ]
46
-
47
- # Define report definition. You can also pass your own XML text as a string.
48
- report_query = 'SELECT CampaignId, AdGroupId, Id, Criteria, CriteriaType, ' +
49
- 'Impressions, Clicks, Cost FROM CRITERIA_PERFORMANCE_REPORT ' +
50
- 'WHERE Status IN [ACTIVE, PAUSED] ' +
51
- 'DURING %s' % date_range
52
-
53
- # Download report, using "download_report_as_file_with_awql" utility method.
54
- # To retrieve the report as return value, use "download_report_with_awql"
55
- # method.
56
- report_utils.download_report_as_file_with_awql(report_query, report_format,
57
- file_name)
58
- puts "Report was downloaded to '%s'." % file_name
59
- end
60
-
61
- if __FILE__ == $0
62
- API_VERSION = :v201206
63
-
64
- begin
65
- # File name to write report to.
66
- file_name = 'INSERT_OUTPUT_FILE_NAME_HERE'
67
- report_format = 'CSV'
68
- download_criteria_report_with_awql(file_name, report_format)
69
-
70
- # HTTP errors.
71
- rescue AdsCommon::Errors::HttpError => e
72
- puts 'HTTP Error: %s' % e
73
-
74
- # API errors.
75
- rescue AdwordsApi::Errors::ReportError => e
76
- puts 'Reporting Error: %s' % e.message
77
- end
78
- end
@@ -1,105 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
- #
6
- # Copyright:: Copyright 2012, 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 various statistics for campaigns that received at least one
22
- # impression during the last week. To get campaigns, run get_campaigns.rb.
23
- #
24
- # Tags: CampaignService.get
25
-
26
- require 'adwords_api'
27
- require 'date'
28
-
29
- def get_campaign_stats()
30
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
31
- # when called without parameters.
32
- adwords = AdwordsApi::Api.new
33
-
34
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
35
- # the configuration file or provide your own logger:
36
- # adwords.logger = Logger.new('adwords_xml.log')
37
-
38
- campaign_srv = adwords.service(:CampaignService, API_VERSION)
39
-
40
- # Prepare start and end date for the last week.
41
- start_date = DateTime.parse((Date.today - 7).to_s).strftime("%Y%m%d")
42
- end_date = DateTime.parse((Date.today - 1).to_s).strftime("%Y%m%d")
43
-
44
- # Get all the campaigns for this account.
45
- selector = {
46
- :fields => ['Id', 'Name', 'Impressions', 'Clicks', 'Cost', 'Ctr'],
47
- :predicates => [
48
- {:field => 'Impressions', :operator => 'GREATER_THAN', :values => [0]}
49
- ],
50
- :date_range => {:min => start_date, :max => end_date},
51
- :paging => {
52
- :start_index => 0,
53
- :number_results => PAGE_SIZE
54
- }
55
- }
56
-
57
- # Set initial values.
58
- offset, page = 0, {}
59
-
60
- begin
61
- page = campaign_srv.get(selector)
62
- if page[:entries]
63
- page[:entries].each do |campaign|
64
- puts ("Campaign with ID %d, name '%s' had the following stats during" +
65
- " the last week: ") % [campaign[:id], campaign[:name]]
66
- stats = campaign[:campaign_stats]
67
- puts "\tImpressions: %d" % stats[:impressions]
68
- puts "\tClicks: %d" % stats[:clicks]
69
- puts "\tCost: %.2f" % (stats[:cost][:micro_amount] / 1000000)
70
- puts "\tCTR: %.2f%%" % (stats[:ctr] * 100)
71
- end
72
- # Increment values to request the next page.
73
- offset += PAGE_SIZE
74
- selector[:paging][:start_index] = offset
75
- end
76
- end while page[:total_num_entries] > offset
77
-
78
- if page.include?(:total_num_entries)
79
- puts "Total number of campaigns found: %d." % [page[:total_num_entries]]
80
- end
81
- end
82
-
83
- if __FILE__ == $0
84
- API_VERSION = :v201206
85
- PAGE_SIZE = 500
86
-
87
- begin
88
- get_campaign_stats()
89
-
90
- # HTTP errors.
91
- rescue AdsCommon::Errors::HttpError => e
92
- puts "HTTP Error: %s" % e
93
-
94
- # API errors.
95
- rescue AdwordsApi::Errors::ApiException => e
96
- puts "Message: %s" % e.message
97
- puts 'Errors:'
98
- e.errors.each_with_index do |error, index|
99
- puts "\tError [%d]:" % (index + 1)
100
- error.each do |field, value|
101
- puts "\t\t%s: %s" % [field, value]
102
- end
103
- end
104
- end
105
- end
@@ -1,71 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Author:: api.sgomes@gmail.com (Sérgio Gomes)
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 the list of possible report fields for a report type.
22
- #
23
- # Tags: ReportDefinitionService.getReportFields
24
-
25
- require 'adwords_api'
26
-
27
- def get_report_fields(report_type)
28
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
29
- # when called without parameters.
30
- adwords = AdwordsApi::Api.new
31
-
32
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
33
- # the configuration file or provide your own logger:
34
- # adwords.logger = Logger.new('adwords_xml.log')
35
-
36
- report_def_srv = adwords.service(:ReportDefinitionService, API_VERSION)
37
-
38
- # Get report fields.
39
- fields = report_def_srv.get_report_fields(report_type)
40
- if fields
41
- puts "Report type '%s' contains the following fields:" % report_type
42
- fields.each do |field|
43
- puts ' - %s (%s)' % [field[:field_name], field[:field_type]]
44
- puts ' := [%s]' % field[:enum_values].join(', ') if field[:enum_values]
45
- end
46
- end
47
- end
48
-
49
- if __FILE__ == $0
50
- API_VERSION = :v201206
51
-
52
- begin
53
- report_type = 'INSERT_REPORT_TYPE_HERE'
54
- get_report_fields(report_type)
55
-
56
- # HTTP errors.
57
- rescue AdsCommon::Errors::HttpError => e
58
- puts "HTTP Error: %s" % e
59
-
60
- # API errors.
61
- rescue AdwordsApi::Errors::ApiException => e
62
- puts "Message: %s" % e.message
63
- puts 'Errors:'
64
- e.errors.each_with_index do |error, index|
65
- puts "\tError [%d]:" % (index + 1)
66
- error.each do |field, value|
67
- puts "\t\t%s: %s" % [field, value]
68
- end
69
- end
70
- end
71
- end
@@ -1,162 +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
- #
23
- # Note: This code example uses MCC-level calls and won't work with Test
24
- # Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
25
-
26
- require 'thread'
27
-
28
- require 'adwords_api'
29
- require 'adwords_api/utils'
30
-
31
- def parallel_report_download()
32
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
33
- # when called without parameters.
34
- adwords = AdwordsApi::Api.new
35
-
36
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
37
- # the configuration file or provide your own logger:
38
- # adwords.logger = Logger.new('adwords_xml.log')
39
-
40
- # Determine list of customer IDs to retrieve report for. For this example we
41
- # will use ManagedCustomerService to get all IDs in hierarchy.
42
-
43
- managed_customer_srv = adwords.service(:ManagedCustomerService, API_VERSION)
44
-
45
- # Get the account hierarchy for this account.
46
- selector = {:fields => ['CustomerId']}
47
-
48
- # Run the request at the MCC level.
49
- graph = adwords.use_mcc() {managed_customer_srv.get(selector)}
50
-
51
- # Using queue to balance load between threads.
52
- queue = Queue.new()
53
-
54
- if graph and graph[:entries] and !graph[:entries].empty?
55
- graph[:entries].each {|account| queue << account[:customer_id]}
56
- else
57
- raise StandardError, 'Can not retrieve any customer ID'
58
- end
59
-
60
- # Get report utilities for the version.
61
- report_utils = adwords.report_utils(API_VERSION)
62
-
63
- # Define report definition. You can also pass your own XML text as a string.
64
- report_definition = {
65
- :selector => {
66
- :fields => ['CampaignId', 'Id', 'Impressions', 'Clicks', 'Cost'],
67
- # Predicates are optional.
68
- :predicates => {
69
- :field => 'Status',
70
- :operator => 'IN',
71
- :values => ['ENABLED', 'PAUSED']
72
- }
73
- },
74
- :report_name => 'Custom ADGROUP_PERFORMANCE_REPORT',
75
- :report_type => 'ADGROUP_PERFORMANCE_REPORT',
76
- :download_format => 'CSV',
77
- :date_range_type => 'LAST_7_DAYS',
78
- # Enable to get rows with zero impressions.
79
- :include_zero_impressions => false
80
- }
81
-
82
- puts 'Retrieving %d reports with %d threads:' % [queue.size, THREADS]
83
-
84
- reports_succeeded = Queue.new()
85
- reports_failed = Queue.new()
86
-
87
- # Creating a mutex to control access to the queue.
88
- queue_mutex = Mutex.new
89
-
90
- # Start all the threads.
91
- threads = (1..THREADS).map do |thread_id|
92
- Thread.new(report_definition) do |local_def|
93
- cid = nil
94
- begin
95
- cid = queue_mutex.synchronize {(queue.empty?) ? nil : queue.pop(true)}
96
- if cid
97
- retry_count = 0
98
- file_name = 'adgroup_%010d.csv' % cid
99
- puts "[%2d/%d] Loading report for customer ID %s into '%s'..." %
100
- [thread_id, retry_count,
101
- AdwordsApi::Utils.format_id(cid), file_name]
102
- begin
103
- report_utils.download_report_as_file(local_def, file_name, cid)
104
- reports_succeeded << {:cid => cid, :file_name => file_name}
105
- rescue AdwordsApi::Errors::ReportError => e
106
- if e.http_code == 500 && retry_count < MAX_RETRIES
107
- retry_count += 1
108
- sleep(retry_count * BACKOFF_FACTOR)
109
- retry
110
- else
111
- puts(('Report failed for customer ID %s with code %d after %d ' +
112
- 'retries.') % [cid, e.http_code, retry_count + 1])
113
- reports_failed <<
114
- {:cid => cid, :http_code => e.http_code, :message => e.message}
115
- end
116
- end
117
- end
118
- end while (cid != nil)
119
- end
120
- end
121
-
122
- # Wait for all threads to finish.
123
- threads.each { |aThread| aThread.join }
124
-
125
- puts 'Download completed, results:'
126
- puts 'Successful reports:'
127
- while !reports_succeeded.empty? do
128
- result = reports_succeeded.pop()
129
- puts "\tClient ID %s => '%s'" %
130
- [AdwordsApi::Utils.format_id(result[:cid]), result[:file_name]]
131
- end
132
- puts 'Failed reports:'
133
- while !reports_failed.empty? do
134
- result = reports_failed.pop()
135
- puts "\tClient ID %s => Code: %d, Message: '%s'" %
136
- [AdwordsApi::Utils.format_id(result[:cid]),
137
- result[:http_code], result[:message]]
138
- end
139
- puts 'End of results.'
140
- end
141
-
142
- if __FILE__ == $0
143
- API_VERSION = :v201206
144
- # Number of parallel threads to spawn.
145
- THREADS = 10
146
- # Maximum number of retries for 500 errors.
147
- MAX_RETRIES = 5
148
- # Timeout between retries in seconds.
149
- BACKOFF_FACTOR = 5
150
-
151
- begin
152
- parallel_report_download()
153
-
154
- # HTTP errors.
155
- rescue AdsCommon::Errors::HttpError => e
156
- puts 'HTTP Error: %s' % e
157
-
158
- # API errors.
159
- rescue AdwordsApi::Errors::ReportError => e
160
- puts 'Reporting Error: %s' % e.message
161
- end
162
- end