Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removing sunset AdWords API v201206

  • Loading branch information...
commit 4727da275807850209aeceda277b7d57cd0e7aa8 1 parent 42b1a56
@dklimkin dklimkin authored
Showing with 11 additions and 9,045 deletions.
  1. +2 −1  adwords_api/ChangeLog
  2. +2 −2 adwords_api/README
  3. +0 −87 adwords_api/examples/v201206/account_management/create_account.rb
  4. +0 −114 adwords_api/examples/v201206/account_management/get_account_alerts.rb
  5. +0 −137 adwords_api/examples/v201206/account_management/get_account_changes.rb
  6. +0 −95 adwords_api/examples/v201206/account_management/get_account_hierarchy.rb
  7. +0 −88 adwords_api/examples/v201206/account_management/get_client_customer_id.rb
  8. +0 −90 adwords_api/examples/v201206/account_management/get_client_unit_usage.rb
  9. +0 −136 adwords_api/examples/v201206/basic_operations/add_ad_groups.rb
  10. +0 −151 adwords_api/examples/v201206/basic_operations/add_campaigns.rb
  11. +0 −108 adwords_api/examples/v201206/basic_operations/add_keywords.rb
  12. +0 −105 adwords_api/examples/v201206/basic_operations/add_text_ads.rb
  13. +0 −85 adwords_api/examples/v201206/basic_operations/delete_ad.rb
  14. +0 −102 adwords_api/examples/v201206/basic_operations/delete_ad_group.rb
  15. +0 −103 adwords_api/examples/v201206/basic_operations/delete_campaign.rb
  16. +0 −90 adwords_api/examples/v201206/basic_operations/delete_keyword.rb
  17. +0 −98 adwords_api/examples/v201206/basic_operations/get_ad_groups.rb
  18. +0 −93 adwords_api/examples/v201206/basic_operations/get_campaigns.rb
  19. +0 −85 adwords_api/examples/v201206/basic_operations/get_campaigns_with_awql.rb
  20. +0 −104 adwords_api/examples/v201206/basic_operations/get_keywords.rb
  21. +0 −106 adwords_api/examples/v201206/basic_operations/get_text_ads.rb
  22. +0 −84 adwords_api/examples/v201206/basic_operations/pause_ad.rb
  23. +0 −81 adwords_api/examples/v201206/basic_operations/update_ad_group.rb
  24. +0 −84 adwords_api/examples/v201206/basic_operations/update_campaign.rb
  25. +0 −99 adwords_api/examples/v201206/basic_operations/update_keyword.rb
  26. +0 −158 adwords_api/examples/v201206/campaign_management/add_experiment.rb
  27. +0 −150 adwords_api/examples/v201206/campaign_management/add_keywords_in_bulk.rb
  28. +0 −117 adwords_api/examples/v201206/campaign_management/add_location_extension.rb
  29. +0 −83 adwords_api/examples/v201206/campaign_management/add_location_extension_override.rb
  30. +0 −93 adwords_api/examples/v201206/campaign_management/get_all_disapproved_ads.rb
  31. +0 −84 adwords_api/examples/v201206/campaign_management/get_all_disapproved_ads_with_awql.rb
  32. +0 −77 adwords_api/examples/v201206/campaign_management/promote_experiment.rb
  33. +0 −114 adwords_api/examples/v201206/campaign_management/set_ad_parameters.rb
  34. +0 −106 adwords_api/examples/v201206/campaign_management/validate_text_ad.rb
  35. +0 −93 adwords_api/examples/v201206/error_handling/handle_captcha_challenge.rb
  36. +0 −126 adwords_api/examples/v201206/error_handling/handle_partial_failures.rb
  37. +0 −137 adwords_api/examples/v201206/error_handling/handle_policy_violation_error.rb
  38. +0 −88 adwords_api/examples/v201206/error_handling/handle_two_factor_authorization_error.rb
  39. +0 −100 adwords_api/examples/v201206/misc/get_all_images_and_videos.rb
  40. +0 −89 adwords_api/examples/v201206/misc/upload_image.rb
  41. +0 −97 adwords_api/examples/v201206/misc/use_oauth2.rb
  42. +0 −129 adwords_api/examples/v201206/optimization/estimate_keyword_traffic.rb
  43. +0 −92 adwords_api/examples/v201206/optimization/get_keyword_bid_simulations.rb
  44. +0 −114 adwords_api/examples/v201206/optimization/get_keyword_ideas.rb
  45. +0 −104 adwords_api/examples/v201206/optimization/get_placement_ideas.rb
  46. +0 −115 adwords_api/examples/v201206/remarketing/add_audience.rb
  47. +0 −97 adwords_api/examples/v201206/remarketing/add_conversion_tracker.rb
  48. +0 −79 adwords_api/examples/v201206/reporting/download_criteria_report.rb
  49. +0 −78 adwords_api/examples/v201206/reporting/download_criteria_report_with_awql.rb
  50. +0 −105 adwords_api/examples/v201206/reporting/get_campaign_stats.rb
  51. +0 −71 adwords_api/examples/v201206/reporting/get_report_fields.rb
  52. +0 −162 adwords_api/examples/v201206/reporting/parallel_report_download.rb
  53. +0 −118 adwords_api/examples/v201206/targeting/add_campaign_targeting_criteria.rb
  54. +0 −102 adwords_api/examples/v201206/targeting/get_campaign_targeting_criteria.rb
  55. +0 −86 adwords_api/examples/v201206/targeting/get_targetable_languages_and_carriers.rb
  56. +0 −104 adwords_api/examples/v201206/targeting/lookup_location.rb
  57. +0 −58 adwords_api/lib/adwords_api/api_config.rb
  58. +3 −19 adwords_api/lib/adwords_api/report_utils.rb
  59. +0 −38 adwords_api/lib/adwords_api/v201206/ad_extension_override_service.rb
  60. +0 −46 adwords_api/lib/adwords_api/v201206/ad_extension_override_service_registry.rb
  61. +0 −42 adwords_api/lib/adwords_api/v201206/ad_group_ad_service.rb
  62. +0 −46 adwords_api/lib/adwords_api/v201206/ad_group_ad_service_registry.rb
  63. +0 −42 adwords_api/lib/adwords_api/v201206/ad_group_criterion_service.rb
  64. +0 −46 adwords_api/lib/adwords_api/v201206/ad_group_criterion_service_registry.rb
  65. +0 −42 adwords_api/lib/adwords_api/v201206/ad_group_service.rb
  66. +0 −46 adwords_api/lib/adwords_api/v201206/ad_group_service_registry.rb
  67. +0 −38 adwords_api/lib/adwords_api/v201206/ad_param_service.rb
  68. +0 −46 adwords_api/lib/adwords_api/v201206/ad_param_service_registry.rb
  69. +0 −34 adwords_api/lib/adwords_api/v201206/alert_service.rb
  70. +0 −46 adwords_api/lib/adwords_api/v201206/alert_service_registry.rb
  71. +0 −42 adwords_api/lib/adwords_api/v201206/budget_order_service.rb
  72. +0 −46 adwords_api/lib/adwords_api/v201206/budget_order_service_registry.rb
  73. +0 −38 adwords_api/lib/adwords_api/v201206/bulk_mutate_job_service.rb
  74. +0 −46 adwords_api/lib/adwords_api/v201206/bulk_mutate_job_service_registry.rb
  75. +0 −38 adwords_api/lib/adwords_api/v201206/campaign_ad_extension_service.rb
  76. +0 −46 adwords_api/lib/adwords_api/v201206/campaign_ad_extension_service_registry.rb
  77. +0 −42 adwords_api/lib/adwords_api/v201206/campaign_criterion_service.rb
  78. +0 −46 adwords_api/lib/adwords_api/v201206/campaign_criterion_service_registry.rb
  79. +0 −42 adwords_api/lib/adwords_api/v201206/campaign_service.rb
  80. +0 −46 adwords_api/lib/adwords_api/v201206/campaign_service_registry.rb
  81. +0 −62 adwords_api/lib/adwords_api/v201206/constant_data_service.rb
  82. +0 −46 adwords_api/lib/adwords_api/v201206/constant_data_service_registry.rb
  83. +0 −38 adwords_api/lib/adwords_api/v201206/conversion_tracker_service.rb
  84. +0 −46 adwords_api/lib/adwords_api/v201206/conversion_tracker_service_registry.rb
  85. +0 −34 adwords_api/lib/adwords_api/v201206/customer_service.rb
  86. +0 −46 adwords_api/lib/adwords_api/v201206/customer_service_registry.rb
  87. +0 −34 adwords_api/lib/adwords_api/v201206/customer_sync_service.rb
  88. +0 −47 adwords_api/lib/adwords_api/v201206/customer_sync_service_registry.rb
  89. +0 −38 adwords_api/lib/adwords_api/v201206/data_service.rb
  90. +0 −46 adwords_api/lib/adwords_api/v201206/data_service_registry.rb
  91. +0 −38 adwords_api/lib/adwords_api/v201206/experiment_service.rb
  92. +0 −46 adwords_api/lib/adwords_api/v201206/experiment_service_registry.rb
  93. +0 −34 adwords_api/lib/adwords_api/v201206/geo_location_service.rb
  94. +0 −46 adwords_api/lib/adwords_api/v201206/geo_location_service_registry.rb
  95. +0 −34 adwords_api/lib/adwords_api/v201206/info_service.rb
  96. +0 −46 adwords_api/lib/adwords_api/v201206/info_service_registry.rb
  97. +0 −34 adwords_api/lib/adwords_api/v201206/location_criterion_service.rb
  98. +0 −46 adwords_api/lib/adwords_api/v201206/location_criterion_service_registry.rb
  99. +0 −38 adwords_api/lib/adwords_api/v201206/managed_customer_service.rb
  100. +0 −46 adwords_api/lib/adwords_api/v201206/managed_customer_service_registry.rb
  101. +0 −38 adwords_api/lib/adwords_api/v201206/media_service.rb
  102. +0 −46 adwords_api/lib/adwords_api/v201206/media_service_registry.rb
  103. +0 −42 adwords_api/lib/adwords_api/v201206/mutate_job_service.rb
  104. +0 −46 adwords_api/lib/adwords_api/v201206/mutate_job_service_registry.rb
  105. +0 −34 adwords_api/lib/adwords_api/v201206/report_definition_service.rb
  106. +0 −46 adwords_api/lib/adwords_api/v201206/report_definition_service_registry.rb
  107. +0 −38 adwords_api/lib/adwords_api/v201206/targeting_idea_service.rb
  108. +0 −46 adwords_api/lib/adwords_api/v201206/targeting_idea_service_registry.rb
  109. +0 −34 adwords_api/lib/adwords_api/v201206/traffic_estimator_service.rb
  110. +0 −46 adwords_api/lib/adwords_api/v201206/traffic_estimator_service_registry.rb
  111. +0 −38 adwords_api/lib/adwords_api/v201206/user_list_service.rb
  112. +0 −46 adwords_api/lib/adwords_api/v201206/user_list_service_registry.rb
  113. +1 −1  adwords_api/lib/adwords_api/version.rb
  114. +0 −89 adwords_api/test/adwords_api/test_report_utils.rb
  115. +0 −60 adwords_api/test/examples/v201206/test_account_management.rb
  116. +0 −177 adwords_api/test/examples/v201206/test_basic_operations.rb
  117. +0 −124 adwords_api/test/examples/v201206/test_campaign_management.rb
  118. +0 −63 adwords_api/test/examples/v201206/test_error_handling.rb
  119. +0 −39 adwords_api/test/examples/v201206/test_misc.rb
  120. +0 −63 adwords_api/test/examples/v201206/test_optimization.rb
  121. +0 −39 adwords_api/test/examples/v201206/test_remarketing.rb
  122. +0 −84 adwords_api/test/examples/v201206/test_reporting.rb
  123. +0 −60 adwords_api/test/examples/v201206/test_targeting.rb
  124. +0 −244 adwords_api/test/examples/v201206/utils.rb
  125. +0 −37 adwords_api/test/suite_exampletests_v201206.rb
  126. +1 −1  adwords_api/test/templates/v201209/basic_operations_get_campaigns.def
  127. +1 −1  adwords_api/test/templates/v201302/basic_operations_get_campaigns.def
  128. +1 −1  adwords_api/test/templates/v201302/misc_use_oauth2_jwt.def
View
3  adwords_api/ChangeLog
@@ -1,6 +1,7 @@
-0.8.3:
+0.9.0:
- Shared set support and examples (beta feature).
- Updated feed services auto-generated code.
+ - Removed deprecated API version v201206.
0.8.2:
- Support and examples for v201302.
View
4 adwords_api/README
@@ -3,8 +3,8 @@
Welcome to the next generation Google-developed Ruby client library for the
AdWords and DoubleClick Ad Exchange Buyer API!
-It contains full support for v201206, v201209 and v201302, with full stubs, and
-a simplified programming interface that lets you handle everything in native
+It contains full support for v201209 and v201302, with full stubs, and a
+simplified programming interface that lets you handle everything in native
Ruby collections.
View
87 adwords_api/examples/v201206/account_management/create_account.rb
@@ -1,87 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to create an account. Note by default this
-# account will only be accessible via parent MCC.
-#
-# Note: This code example uses MCC-level calls and won't work with Test
-# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
-#
-# Tags: ManagedCustomerService.mutate
-
-require 'adwords_api'
-require 'adwords_api/utils'
-
-def create_account()
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- managed_customer_srv = adwords.service(:ManagedCustomerService, API_VERSION)
-
- # Create a local Customer object.
- customer = {
- :name => 'Account created with ManagedCustomerService',
- :currency_code => 'EUR',
- :date_time_zone => 'Europe/London'
- }
-
- # Prepare operation to create an account.
- operation = {
- :operator => 'ADD',
- :operand => customer
- }
-
- # Create the account. It is possible to create multiple accounts with one
- # request by sending an array of operations.
- response = managed_customer_srv.mutate([operation])
-
- response[:value].each do |new_account|
- puts "Account with customer ID '%s' was successfully created." %
- AdwordsApi::Utils.format_id(new_account[:customer_id])
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- create_account()
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
114 adwords_api/examples/v201206/account_management/get_account_alerts.rb
@@ -1,114 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example gets all alerts for all clients of an MCC account. The effective
-# user (clientCustomerId, or authToken) must be an MCC user to get results.
-#
-# Note: This code example uses MCC-level calls and won't work with Test
-# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
-#
-# Tags: AlertService.get
-
-require 'adwords_api'
-require 'adwords_api/utils'
-
-def get_account_alerts()
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- alert_srv = adwords.service(:AlertService, API_VERSION)
-
- # Create the selector.
- selector = {
- :query => {
- :filter_spec => 'ALL',
- :client_spec => 'ALL',
- :trigger_time_spec => 'ALL_TIME',
- :severities => ['GREEN', 'YELLOW', 'RED'],
- :types => [
- 'ACCOUNT_BUDGET_BURN_RATE', 'ACCOUNT_BUDGET_ENDING',
- 'ACCOUNT_ON_TARGET', 'CAMPAIGN_ENDED', 'CAMPAIGN_ENDING',
- 'CREDIT_CARD_EXPIRING', 'DECLINED_PAYMENT', 'MANAGER_LINK_PENDING',
- 'MISSING_BANK_REFERENCE_NUMBER', 'PAYMENT_NOT_ENTERED',
- 'TV_ACCOUNT_BUDGET_ENDING', 'TV_ACCOUNT_ON_TARGET',
- 'TV_ZERO_DAILY_SPENDING_LIMIT', 'USER_INVITE_ACCEPTED',
- 'USER_INVITE_PENDING', 'ZERO_DAILY_SPENDING_LIMIT'
- ]
- },
- :paging => {
- :start_index => 0,
- :number_results => PAGE_SIZE
- }
- }
-
- # Set initial values.
- offset, page = 0, {}
-
- # Get alerts.
- begin
- page = alert_srv.get(selector)
- if page[:entries]
- page[:entries].each_with_index do |alert, index|
- puts "%d) Customer ID is '%s', alert type is '%s', severity is '%s'."
- [AdwordsApi::Utils.format_id(alert[:client_customer_id]),
- alert[:alert_type], alert[:alert_severity]]
- alert[:details].each do |detail|
- puts "\t- triggered at %s" % detail[:trigger_time]
- end
- end
- # Increment values to request the next page.
- offset += PAGE_SIZE
- selector[:paging][:start_index] = offset
- end
- end while page[:total_num_entries] > offset
-
- if page.include?(:total_num_entries)
- puts "\tTotal number of alerts: %d." % page[:total_num_entries]
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
- PAGE_SIZE = 500
-
- begin
- get_account_alerts()
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
137 adwords_api/examples/v201206/account_management/get_account_changes.rb
@@ -1,137 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example gets all account changes that happened within the last 24 hours,
-# for all your campaigns.
-#
-# Tags: CustomerSyncService.get
-
-require 'adwords_api'
-require 'date'
-require 'pp'
-
-def get_account_changes()
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- campaign_srv = adwords.service(:CampaignService, API_VERSION)
- customer_sync_srv = adwords.service(:CustomerSyncService, API_VERSION)
-
- today_at_midnight = DateTime.parse(Date.today.to_s)
- yesterday_at_midnight = DateTime.parse((Date.today - 1).to_s)
- min_date_time = yesterday_at_midnight.strftime("%Y%m%d %H%M%S")
- max_date_time = today_at_midnight.strftime("%Y%m%d %H%M%S")
-
- # Get all the campaigns for this account.
- selector = {
- :fields => ['Id']
- }
- response = campaign_srv.get(selector)
-
- campaign_ids = []
-
- if response and response[:entries]
- campaign_ids = response[:entries].map { |campaign| campaign[:id] }
- else
- raise StandardError, 'No campaigns were found.'
- end
-
- # Create a selector for CustomerSyncService.
- selector = {
- :campaign_ids => campaign_ids,
- :date_time_range => {
- :min => min_date_time,
- :max => max_date_time
- }
- }
-
- # Get all account changes for the campaigns.
- campaign_changes = customer_sync_srv.get(selector)
-
- # Display changes.
- if campaign_changes
- puts "Most recent change: %s" % campaign_changes[:last_change_timestamp]
- campaign_changes[:changed_campaigns].each do |campaign|
- puts "Campaign with ID %d was changed:" % campaign[:campaign_id]
- puts "\tCampaign change status: '%s'" % campaign[:campaign_change_status]
- unless ['NEW', 'FIELDS_UNCHANGED'].include?(
- campaign[:campaign_change_status])
- puts "\tAdded ad extensions: '%s'" %
- campaign[:added_ad_extensions].pretty_inspect.chomp
- puts "\tAdded campaign criteria: '%s'" %
- campaign[:added_campaign_criteria].pretty_inspect.chomp
- puts "\tAdded campaign targeting: '%s'" %
- campaign[:campaign_targeting_changed].pretty_inspect.chomp
- puts "\tDeleted ad extensions: '%s'" %
- campaign[:deleted_ad_extensions].pretty_inspect.chomp
- puts "\tDeleted campaign criteria: '%s'" %
- campaign[:deleted_campaign_criteria].pretty_inspect.chomp
-
- if campaign[:changed_ad_groups]
- campaign[:changed_ad_groups].each do |ad_group|
- puts "\tAd group with ID %d was changed:" % ad_group[:ad_group_id]
- puts "\t\tAd group changed status: '%s'" %
- ad_group[:ad_group_change_status]
- unless ['NEW', 'FIELDS_UNCHANGED'].include?(
- ad_group[:ad_group_change_status])
- puts "\t\tAds changed: '%s'" %
- ad_group[:changed_ads].pretty_inspect.chomp
- puts "\t\tCriteria changed: '%s'" %
- ad_group[:changed_criteria].pretty_inspect.chomp
- puts "\t\tCriteria deleted: '%s'" %
- ad_group[:deleted_criteria].pretty_inspect.chomp
- end
- end
- end
- end
- puts
- end
- else
- puts 'No account changes were found.'
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- get_account_changes()
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
95 adwords_api/examples/v201206/account_management/get_account_hierarchy.rb
@@ -1,95 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to retrieve the account hierarchy under an
-# account.
-#
-# Note: This code example uses MCC-level calls and won't work with Test
-# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
-#
-# Tags: ManagedCustomerService.get
-
-require 'adwords_api'
-require 'adwords_api/utils'
-
-def get_account_hierarchy()
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- managed_customer_srv = adwords.service(:ManagedCustomerService, API_VERSION)
-
- # Get the account hierarchy for this account.
- selector = {
- :fields => ['Login', 'CustomerId', 'Name']
- }
-
- # Run the request at the MCC level.
- graph = adwords.use_mcc() {managed_customer_srv.get(selector)}
-
- if graph and graph[:entries]
- puts 'Accounts under this hierarchy: %d' % graph[:total_num_entries]
- graph[:entries].each_with_index do |account, index|
- puts "%d) Customer ID: %s" %
- [index + 1, AdwordsApi::Utils.format_id(account[:customer_id])]
- puts "\tLogin email: %s" % account[:login]
- puts "\tName: %s" % account[:name]
- end
-
- # Display the links.
- if graph[:links]
- puts 'Hierarchy links:'
- graph[:links].each do |link|
- puts "\tThere is a link from %s to %s" %
- [AdwordsApi::Utils.format_id(link[:manager_customer_id]),
- AdwordsApi::Utils.format_id(link[:client_customer_id])]
- end
- end
- else
- puts 'No accounts were found.'
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- get_account_hierarchy()
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
88 adwords_api/examples/v201206/account_management/get_client_customer_id.rb
@@ -1,88 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to find a client customer ID for a client email.
-# We recommend to use this script as a one off to convert your identifiers to
-# IDs and store them for future use.
-#
-# Note: This code example uses MCC-level calls and won't work with Test
-# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
-#
-# Tags: InfoService.get
-
-require 'adwords_api'
-require 'adwords_api/utils'
-
-def get_client_customer_id(client_email)
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- info_srv = adwords.service(:InfoService, API_VERSION)
-
- today = Time.new.strftime('%Y%m%d')
- selector = {
- :client_emails => [client_email],
- :api_usage_type => 'UNIT_COUNT_FOR_CLIENTS',
- :include_sub_accounts => true,
- :date_range => {:min => today, :max => today}
- }
-
- # Get the information for client email address.
- info = adwords.use_mcc() {info_srv.get(selector)}
-
- if info and info[:api_usage_records]
- api_usage_records = info[:api_usage_records]
- api_usage_records.each do |record|
- puts "Found record with client email '%s' and ID %s." %
- [record[:client_email],
- AdwordsApi::Utils.format_id(record[:client_customer_id])]
- end
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- # Email address to find ID for.
- client_email = 'INSERT_EMAIL_ADDRESS_HERE'
- get_client_customer_id(client_email)
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
90 adwords_api/examples/v201206/account_management/get_client_unit_usage.rb
@@ -1,90 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to retrieve the number of API units usage for a
-# client account for the current month.
-#
-# Note: This code example uses MCC-level calls and won't work with Test
-# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
-#
-# Tags: InfoService.get
-
-require 'adwords_api'
-
-def get_client_unit_usage(client_customer_id)
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- info_srv = adwords.service(:InfoService, API_VERSION)
-
- start_date = Time.now.strftime('%Y%m01')
- end_date = Time.now.strftime('%Y%m%d')
-
- selector = {
- :api_usage_type => 'UNIT_COUNT_FOR_CLIENTS',
- :client_customer_ids => [client_customer_id],
- # Set to true to navigate your entire accounts tree.
- :include_sub_accounts => 1,
- :date_range => {
- :min => start_date,
- :max => end_date
- }
- }
-
- # Force to use the MCC credentials.
- adwords.use_mcc do
- # Get the unit info.
- info_srv.get(selector) do |header, response|
- puts "Total number of units consumed from %s to %s is %d." %
- [start_date, end_date, response[:cost]]
- puts "Number of units consumed by this request is %d" % header[:units]
- end
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- # Specify client customer ID for the account to get usage for.
- client_customer_id = 'INSERT_CLIENT_CUSTOMER_ID_HERE'.to_i
- get_client_unit_usage(client_customer_id)
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
136 adwords_api/examples/v201206/basic_operations/add_ad_groups.rb
@@ -1,136 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to create ad groups. To get a list of existing
-# campaigns run get_campaigns.rb.
-#
-# Tags: AdGroupService.mutate
-
-require 'adwords_api'
-
-def add_ad_groups(campaign_id)
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- ad_group_srv = adwords.service(:AdGroupService, API_VERSION)
-
- ad_groups = [
- {
- :name => "Earth to Mars Cruises #%d" % (Time.new.to_f * 1000).to_i,
- :status => 'ENABLED',
- :campaign_id => campaign_id,
- :bids => {
- # The 'xsi_type' field allows you to specify the xsi:type of the object
- # being created. It's only necessary when you must provide an explicit
- # type that the client library can't infer.
- :xsi_type => 'ManualCPCAdGroupBids',
- :keyword_max_cpc => {
- :amount => {
- :micro_amount => 10000000
- }
- },
- # Optional field.
- :keyword_content_max_cpc => {:amount => {:micro_amount => 2000000}}
- },
- :settings => [
- # Targetting restriction settings - these setting only affect serving
- # for the Display Network.
- {
- :xsi_type => 'TargetingSetting',
- :details => [
- # Restricting to serve ads that match your ad group placements.
- {
- :xsi_type => 'TargetingSettingDetail',
- :criterion_type_group => 'PLACEMENT',
- :target_all => true
- },
- # Using your ad group verticals only for bidding.
- {
- :xsi_type => 'TargetingSettingDetail',
- :criterion_type_group => 'VERTICAL',
- :target_all => false
- }
- ]
- }
- ]
- },
- {
- :name => 'Earth to Pluto Cruises #%d' % (Time.new.to_f * 1000).to_i,
- :status => 'ENABLED',
- :campaign_id => campaign_id,
- :bids => {
- # The 'xsi_type' field allows you to specify the xsi:type of the object
- # being created. It's only necessary when you must provide an explicit
- # type that the client library can't infer.
- :xsi_type => 'ManualCPCAdGroupBids',
- :keyword_max_cpc => {
- :amount => {
- :micro_amount => 10000000
- }
- }
- }
- }
- ]
-
- # Prepare operations for adding ad groups.
- operations = ad_groups.map do |ad_group|
- {:operator => 'ADD', :operand => ad_group}
- end
-
- # Add ad groups.
- response = ad_group_srv.mutate(operations)
- if response and response[:value]
- response[:value].each do |ad_group|
- puts "Ad group ID %d was successfully added." % ad_group[:id]
- end
- else
- raise StandardError, 'No ad group was added'
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- # Campaign ID to add ad group to.
- campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
- add_ad_groups(campaign_id)
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
151 adwords_api/examples/v201206/basic_operations/add_campaigns.rb
@@ -1,151 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to create campaigns.
-#
-# Tags: CampaignService.mutate
-
-require 'adwords_api'
-require 'date'
-
-def add_campaigns()
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- campaign_srv = adwords.service(:CampaignService, API_VERSION)
-
- campaigns = [
- {
- :name => "Interplanetary Cruise #%d" % (Time.new.to_f * 1000).to_i,
- :status => 'PAUSED',
- :bidding_strategy => {
- # The 'xsi_type' field allows you to specify the xsi:type of the object
- # being created. It's only necessary when you must provide an explicit
- # type that the client library can't infer.
- :xsi_type => 'ManualCPC'
- },
- :budget => {
- :period => 'DAILY',
- :amount => {:micro_amount => 50000000},
- :delivery_method => 'STANDARD'
- },
- # Set the campaign network options to Search and Search Network.
- :network_setting => {
- :target_google_search => true,
- :target_search_network => true,
- :target_content_network => true
- },
- # Optional fields:
- :start_date =>
- DateTime.parse((Date.today + 1).to_s).strftime('%Y%m%d'),
- :ad_serving_optimization_status => 'ROTATE',
- :settings => [
- # Display network targeting settings (optional).
- # It can only be enabled, shown only for demonstration purposes.
- # If not set this setting is enabled by default on ADD operations.
- {
- :xsi_type => 'TargetRestrictSetting',
- :use_ad_group => true
- },
- {
- :xsi_type => 'GeoTargetTypeSetting',
- :positive_geo_target_type => 'DONT_CARE',
- :negative_geo_target_type => 'DONT_CARE'
- },
- {
- :xsi_type => 'KeywordMatchSetting',
- :opt_in => true
- }
- ],
- :frequency_cap => {
- :impressions => '5',
- :time_unit => 'DAY',
- :level => 'ADGROUP'
- }
- },
- {
- :name => "Interplanetary Cruise banner #%d" % (Time.new.to_f * 1000).to_i,
- :status => 'PAUSED',
- :bidding_strategy => {
- :xsi_type => 'ManualCPM'
- },
- :budget => {
- :period => 'DAILY',
- :amount => {:micro_amount => 150000000},
- :delivery_method => 'STANDARD'
- },
- :settings => [
- {
- :xsi_type => 'KeywordMatchSetting',
- :opt_in => true
- }
- ],
- :network_setting => {
- :target_google_search => false,
- :target_search_network => false,
- :target_content_network => true
- }
- }
- ]
-
- # Prepare for adding campaign.
- operations = campaigns.map do |campaign|
- {:operator => 'ADD', :operand => campaign}
- end
-
- # Add campaign.
- response = campaign_srv.mutate(operations)
- if response and response[:value]
- response[:value].each do |campaign|
- puts "Campaign with name '%s' and ID %d was added." %
- [campaign[:name], campaign[:id]]
- end
- else
- raise new StandardError, 'No campaigns were added.'
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- add_campaigns()
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
108 adwords_api/examples/v201206/basic_operations/add_keywords.rb
@@ -1,108 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to add multiple keywords to a given ad group. To
-# create an ad group, run add_ad_group.rb.
-#
-# Tags: AdGroupCriterionService.mutate
-
-require 'adwords_api'
-
-def add_keywords(ad_group_id)
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- ad_group_criterion_srv =
- adwords.service(:AdGroupCriterionService, API_VERSION)
-
- # Create keywords.
- # The 'xsi_type' field allows you to specify the xsi:type of the object
- # being created. It's only necessary when you must provide an explicit
- # type that the client library can't infer.
- keywords = [
- {:xsi_type => 'BiddableAdGroupCriterion',
- :ad_group_id => ad_group_id,
- :criterion => {
- :xsi_type => 'Keyword',
- :text => 'mars cruise',
- :match_type => 'BROAD'
- },
- # Optional fields:
- :user_status => 'PAUSED',
- :destination_url => 'http://example.com/mars'
- },
- {:xsi_type => 'BiddableAdGroupCriterion',
- :ad_group_id => ad_group_id,
- :criterion => {
- :xsi_type => 'Keyword',
- :text => 'space hotel',
- :match_type => 'BROAD'}}
- ]
-
- # Create 'ADD' operations.
- operations = keywords.map do |keyword|
- {:operator => 'ADD', :operand => keyword}
- end
-
- # Add keywords.
- response = ad_group_criterion_srv.mutate(operations)
- if response and response[:value]
- ad_group_criteria = response[:value]
- puts "Added %d keywords to ad group ID %d:" %
- [ad_group_criteria.length, ad_group_id]
- ad_group_criteria.each do |ad_group_criterion|
- puts "\tKeyword ID is %d and type is '%s'" %
- [ad_group_criterion[:criterion][:id],
- ad_group_criterion[:criterion][:type]]
- end
- else
- raise StandardError, 'No keywords were added.'
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- # Ad group ID to add keywords to.
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
- add_keywords(ad_group_id)
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
105 adwords_api/examples/v201206/basic_operations/add_text_ads.rb
@@ -1,105 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to add text ads to a given ad group. To create an
-# ad group, run add_ad_group.rb.
-#
-# Tags: AdGroupAdService.mutate
-
-require 'adwords_api'
-
-def add_text_ads(ad_group_id)
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
-
- # Create text ads.
- # The 'xsi_type' field allows you to specify the xsi:type of the object
- # being created. It's only necessary when you must provide an explicit
- # type that the client library can't infer.
- text_ads = [
- {
- :xsi_type => 'TextAd',
- :headline => 'Luxury Cruise to Mars',
- :description1 => 'Visit the Red Planet in style.',
- :description2 => 'Low-gravity fun for everyone!',
- :url => 'http://www.example.com',
- :display_url => 'www.example.com'
- },
- {
- :xsi_type => 'TextAd',
- :headline => 'Luxury Cruise to Mars',
- :description1 => 'Enjoy your stay at Red Planet.',
- :description2 => 'Buy your tickets now!',
- :url => 'http://www.example.com',
- :display_url => 'www.example.com'
- }
- ]
-
- # Create ad 'ADD' operations.
- text_ad_operations = text_ads.map do |text_ad|
- {:operator => 'ADD',
- :operand => {:ad_group_id => ad_group_id, :ad => text_ad}}
- end
-
- # Add ads.
- response = ad_group_ad_srv.mutate(text_ad_operations)
- if response and response[:value]
- ads = response[:value]
- puts "Added %d ad(s) to ad group ID %d:" % [ads.length, ad_group_id]
- ads.each do |ad|
- puts "\tAd ID %d, type '%s' and status '%s'" %
- [ad[:ad][:id], ad[:ad][:ad_type], ad[:status]]
- end
- else
- raise StandardError, 'No ads were added.'
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- # Ad group ID to add text ads to.
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
- add_text_ads(ad_group_id)
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
85 adwords_api/examples/v201206/basic_operations/delete_ad.rb
@@ -1,85 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.sgomes@gmail.com (Sérgio Gomes)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example deletes an ad using the 'REMOVE' operator. To get ads, run
-# get_text_ads.rb.
-#
-# Tags: AdGroupAdService.mutate
-
-require 'adwords_api'
-
-def delete_ad(ad_group_id, ad_id)
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
-
- # Prepare for deleting ad.
- operation = {
- :operator => 'REMOVE',
- :operand => {
- :ad_group_id => ad_group_id,
- :ad => {
- :xsi_type => 'Ad',
- :id => ad_id
- }
- }
- }
-
- # Delete ad.
- response = ad_group_ad_srv.mutate([operation])
- if response and response[:value]
- ad = response[:value].first
- puts "Ad ID %d was successfully deleted." % ad[:ad][:id]
- else
- puts 'No ads were deleted.'
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- # IDs of an ad to delete and its ad group.
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
- ad_id = 'INSERT_AD_ID_HERE'.to_i
- delete_ad(ad_group_id, ad_id)
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
102 adwords_api/examples/v201206/basic_operations/delete_ad_group.rb
@@ -1,102 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example deletes an ad group by setting the status to 'DELETED'. To get ad
-# groups, run get_ad_groups.rb.
-#
-# Tags: AdGroupService.mutate
-
-require 'adwords_api'
-
-def delete_ad_group(ad_group_id)
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- ad_group_srv = adwords.service(:AdGroupService, API_VERSION)
-
- # Retrieve the ad group to obtain its name. This is optional but recommended
- # to keep deleted objects searchable. In production the name is already known
- # in most cases.
- selector = {
- :fields => ['Id', 'Name'],
- :predicates => [
- {:field => 'Id', :operator => 'EQUALS', :values => [ad_group_id]}
- ]
- }
- result = ad_group_srv.get(selector)
-
- if result.nil? or result[:entries].empty?
- raise StandardError, "Ad group with ID %d was not found." % ad_group_id
- end
-
- # We recommend renaming object on delete to avoid name conflicts later.
- ad_group_name = result[:entries].first[:name]
- ad_group_name += Time.now.strftime(" (deleted on %Y-%m-%d %H:%M:%S)")
-
- # Prepare for deleting ad group.
- operation = {
- :operator => 'SET',
- :operand => {
- :id => ad_group_id,
- :name => ad_group_name,
- :status => 'DELETED'
- }
- }
-
- # Delete ad group.
- response = ad_group_srv.mutate([operation])
- if response and response[:value]
- ad_group = response[:value].first
- puts "Ad group ID %d was successfully deleted and renamed to '%s'." %
- [ad_group[:id], ad_group[:name]]
- else
- puts 'No ad group was updated.'
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- # ID of an ad group to delete.
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
- delete_ad_group(ad_group_id)
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
103 adwords_api/examples/v201206/basic_operations/delete_campaign.rb
@@ -1,103 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example deletes a campaign by setting the status to 'DELETED'. To get
-# campaigns, run get_campaigns.rb.
-#
-# Tags: CampaignService.mutate
-
-require 'adwords_api'
-
-def delete_campaign(campaign_id)
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- campaign_srv = adwords.service(:CampaignService, API_VERSION)
-
- # Retrieve the campaign to obtain its name. This is optional but recommended
- # to keep deleted objects searchable. In production the name is already known
- # in most cases.
- selector = {
- :fields => ['Id', 'Name'],
- :predicates => [
- {:field => 'Id', :operator => 'EQUALS', :values => [campaign_id]}
- ]
- }
- result = campaign_srv.get(selector)
-
- if result.nil? or result[:entries].empty?
- raise StandardError, "Campaign with ID %d was not found." % campaign_id
- end
-
- # We recommend renaming object on delete to avoid name conflicts later.
- campaign_name = result[:entries].first[:name]
- campaign_name += Time.now.strftime(" (deleted on %Y-%m-%d %H:%M:%S)")
-
- # Prepare for deleting campaign.
- operation = {
- :operator => 'SET',
- :operand => {
- :id => campaign_id,
- :name => campaign_name,
- :status => 'DELETED',
- }
- }
-
- # Delete campaign.
- response = campaign_srv.mutate([operation])
-
- if response and response[:value]
- campaign = response[:value].first
- puts "Campaign ID %d was renamed to '%s' and deleted." %
- [campaign[:id], campaign[:name]]
- else
- puts 'No campaign was updated.'
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- # ID of a campaign to delete.
- campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
- delete_campaign(campaign_id)
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
90 adwords_api/examples/v201206/basic_operations/delete_keyword.rb
@@ -1,90 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example deletes a keyword using the 'REMOVE' operator. To get list of
-# keywords, run get_keywords.rb.
-#
-# Tags: AdGroupCriterionService.mutate
-
-require 'adwords_api'
-
-def delete_keyword(ad_group_id, criterion_id)
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- ad_group_criterion_srv =
- adwords.service(:AdGroupCriterionService, API_VERSION)
-
- # Prepare for deleting keyword.
- operation = {
- :operator => 'REMOVE',
- :operand => {
- # The 'xsi_type' field allows you to specify the xsi:type of the object
- # being created. It's only necessary when you must provide an explicit
- # type that the client library can't infer.
- :xsi_type => 'BiddableAdGroupCriterion',
- :ad_group_id => ad_group_id,
- :criterion => {
- :id => criterion_id
- }
- }
- }
-
- # Delete keyword.
- response = ad_group_criterion_srv.mutate([operation])
- ad_group_criterion = response[:value].first
- if ad_group_criterion
- puts "Keyword ID %d was successfully deleted." %
- ad_group_criterion[:criterion][:id]
- else
- puts 'No keywords were deleted.'
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- # IDs of criterion to delete and its ad group.
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
- criterion_id = 'INSERT_CRITERION_ID_HERE'.to_i
- delete_keyword(ad_group_id, criterion_id)
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
98 adwords_api/examples/v201206/basic_operations/get_ad_groups.rb
@@ -1,98 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to retrieve all the ad groups for a campaign. To
-# create an ad group, run add_ad_group.rb.
-#
-# Tags: AdGroupService.get
-
-require 'adwords_api'
-
-def get_ad_groups(campaign_id)
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- ad_group_srv = adwords.service(:AdGroupService, API_VERSION)
-
- # Get all the ad groups for this campaign.
- selector = {
- :fields => ['Id', 'Name'],
- :ordering => [{:field => 'Name', :sort_order => 'ASCENDING'}],
- :predicates => [
- {:field => 'CampaignId', :operator => 'IN', :values => [campaign_id]}
- ],
- :paging => {
- :start_index => 0,
- :number_results => PAGE_SIZE
- }
- }
-
- # Set initial values.
- offset, page = 0, {}
-
- begin
- page = ad_group_srv.get(selector)
- if page[:entries]
- page[:entries].each do |ad_group|
- puts "Ad group name is '%s' and ID is %d" %
- [ad_group[:name], ad_group[:id]]
- end
- # Increment values to request the next page.
- offset += PAGE_SIZE
- selector[:paging][:start_index] = offset
- end
- end while page[:total_num_entries] > offset
-
- if page.include?(:total_num_entries)
- puts "\tCampaign ID %d has %d ad group(s)." %
- [campaign_id, page[:total_num_entries]]
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
- PAGE_SIZE = 500
-
- begin
- # Campaign ID to get ad groups for.
- campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
- get_ad_groups(campaign_id)
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
93 adwords_api/examples/v201206/basic_operations/get_campaigns.rb
@@ -1,93 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to retrieve all the campaigns for an account.
-#
-# Tags: CampaignService.get
-
-require 'adwords_api'
-
-def get_campaigns()
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- campaign_srv = adwords.service(:CampaignService, API_VERSION)
-
- # Get all the campaigns for this account.
- selector = {
- :fields => ['Id', 'Name', 'Status'],
- :ordering => [
- {:field => 'Name', :sort_order => 'ASCENDING'}
- ],
- :paging => {
- :start_index => 0,
- :number_results => PAGE_SIZE
- }
- }
-
- # Set initial values.
- offset, page = 0, {}
-
- begin
- page = campaign_srv.get(selector)
- if page[:entries]
- page[:entries].each do |campaign|
- puts "Campaign ID %d, name '%s' and status '%s'" %
- [campaign[:id], campaign[:name], campaign[:status]]
- end
- # Increment values to request the next page.
- offset += PAGE_SIZE
- selector[:paging][:start_index] = offset
- end
- end while page[:total_num_entries] > offset
-
- if page.include?(:total_num_entries)
- puts "\tTotal number of campaigns found: %d." % [page[:total_num_entries]]
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
- PAGE_SIZE = 500
-
- begin
- get_campaigns()
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
85 adwords_api/examples/v201206/basic_operations/get_campaigns_with_awql.rb
@@ -1,85 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2012, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to retrieve all the campaigns for an account with
-# AWQL.
-#
-# Tags: CampaignService.query
-
-require 'adwords_api'
-
-def get_campaigns_with_awql()
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- campaign_srv = adwords.service(:CampaignService, API_VERSION)
-
- # Get all the campaigns for this account.
- query = 'SELECT Id, Name, Status ORDER BY Name'
-
- # Set initial values.
- offset, page = 0, {}
-
- begin
- page_query = query + ' LIMIT %d,%d' % [offset, PAGE_SIZE]
- page = campaign_srv.query(page_query)
- if page[:entries]
- page[:entries].each do |campaign|
- puts "Campaign ID %d, name '%s' and status '%s'" %
- [campaign[:id], campaign[:name], campaign[:status]]
- end
- # Increment values to request the next page.
- offset += PAGE_SIZE
- end
- end while page[:total_num_entries] > offset
-
- if page.include?(:total_num_entries)
- puts "\tTotal number of campaigns found: %d." % page[:total_num_entries]
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
- PAGE_SIZE = 500
-
- begin
- get_campaigns_with_awql()
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts 'HTTP Error: %s' % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts 'Message: %s' % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
104 adwords_api/examples/v201206/basic_operations/get_keywords.rb
@@ -1,104 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to retrieve all keywords for an ad group. To add
-# keywords to an existing ad group, run add_keywords.rb.
-#
-# Tags: AdGroupCriterionService.get
-
-require 'adwords_api'
-
-def get_keywords(ad_group_id)
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- ad_group_criterion_srv =
- adwords.service(:AdGroupCriterionService, API_VERSION)
-
- # Get all keywords for this ad group.
- selector = {
- :fields => ['Id', 'CriteriaType', 'KeywordText'],
- :ordering => [
- {:field => 'Id', :sort_order => 'ASCENDING'}
- ],
- :predicates => [
- {:field => 'AdGroupId', :operator => 'EQUALS', :values => [ad_group_id]},
- {:field => 'CriteriaType', :operator => 'EQUALS', :values => ['KEYWORD']}
- ],
- :paging => {
- :start_index => 0,
- :number_results => PAGE_SIZE
- }
- }
-
- # Set initial values.
- offset, page = 0, {}
-
- begin
- page = ad_group_criterion_srv.get(selector)
- if page[:entries]
- page[:entries].each do |keyword|
- puts "Keyword ID %d, type '%s' and text '%s'" %
- [keyword[:criterion][:id],
- keyword[:criterion][:type],
- keyword[:criterion][:text]]
- end
- # Increment values to request the next page.
- offset += PAGE_SIZE
- selector[:paging][:start_index] = offset
- end
- end while page[:total_num_entries] > offset
-
- if page.include?(:total_num_entries)
- puts "\tAd group ID %d has %d keyword(s)." %
- [ad_group_id, page[:total_num_entries]]
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
- PAGE_SIZE = 500
-
- begin
- # Ad group ID to get keywords for.
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
- get_keywords(ad_group_id)
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
106 adwords_api/examples/v201206/basic_operations/get_text_ads.rb
@@ -1,106 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to retrieve all text ads for an ad group. To add
-# ads to an existing ad group, run add_text_ads.rb.
-#
-# Tags: AdGroupAdService.get
-
-require 'adwords_api'
-
-def get_text_ads(ad_group_id)
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
-
- # Get all the ads for this ad group.
- selector = {
- :fields => ['Id', 'Status', 'AdType'],
- :ordering => [{:field => 'Id', :sort_order => 'ASCENDING'}],
- # By default, disabled ads aren't returned by the selector. To return them,
- # include the DISABLED status in a predicate.
- :predicates => [
- {:field => 'AdGroupId', :operator => 'IN', :values => [ad_group_id]},
- {:field => 'Status',
- :operator => 'IN',
- :values => ['ENABLED', 'PAUSED', 'DISABLED']},
- {:field => 'AdType',
- :operator => 'EQUALS',
- :values => ['TEXT_AD']}
- ],
- :paging => {
- :start_index => 0,
- :number_results => PAGE_SIZE
- }
- }
-
- # Set initial values.
- offset, page = 0, {}
-
- begin
- page = ad_group_ad_srv.get(selector)
- if page[:entries]
- page[:entries].each do |ad|
- puts "Ad ID is %d, type is '%s' and status is '%s'" %
- [ad[:ad][:id], ad[:ad][:ad_type], ad[:status]]
- end
- # Increment values to request the next page.
- offset += PAGE_SIZE
- selector[:paging][:start_index] = offset
- end
- end while page[:total_num_entries] > offset
-
- if page.include?(:total_num_entries)
- puts "\tAd group ID %d has %d ad(s)." %
- [ad_group_id, page[:total_num_entries]]
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
- PAGE_SIZE = 500
-
- begin
- # Ad group ID to get text ads for.
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
- get_text_ads(ad_group_id)
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
84 adwords_api/examples/v201206/basic_operations/pause_ad.rb
@@ -1,84 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.dklimkin@gmail.com (Danial Klimkin)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to update an ad, setting its status to 'PAUSED'.
-# To create ads, run add_text_ads.rb.
-#
-# Tags: AdGroupAdService.mutate
-
-require 'adwords_api'
-
-def pause_ad(ad_group_id, ad_id)
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
-
- # Prepare operation for updating ad.
- operation = {
- :operator => 'SET',
- :operand => {
- :ad_group_id => ad_group_id,
- :status => 'PAUSED',
- :ad => {:id => ad_id}
- }
- }
-
- # Update ad.
- response = ad_group_ad_srv.mutate([operation])
- if response and response[:value]
- ad = response[:value].first
- puts "Ad ID %d was successfully updated, status set to '%s'." %
- [ad[:ad][:id], ad[:status]]
- else
- puts 'No ads were updated.'
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- # IDs of ad to pause and its ad group.
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
- ad_id = 'INSERT_AD_ID_HERE'.to_i
- pause_ad(ad_group_id, ad_id)
-
- # HTTP errors.
- rescue AdsCommon::Errors::HttpError => e
- puts "HTTP Error: %s" % e
-
- # API errors.
- rescue AdwordsApi::Errors::ApiException => e
- puts "Message: %s" % e.message
- puts 'Errors:'
- e.errors.each_with_index do |error, index|
- puts "\tError [%d]:" % (index + 1)
- error.each do |field, value|
- puts "\t\t%s: %s" % [field, value]
- end
- end
- end
-end
View
81 adwords_api/examples/v201206/basic_operations/update_ad_group.rb
@@ -1,81 +0,0 @@
-#!/usr/bin/env ruby
-# Encoding: utf-8
-#
-# Author:: api.sgomes@gmail.com (Sérgio Gomes)
-#
-# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
-#
-# License:: Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This example illustrates how to update an ad group, setting its status to
-# 'PAUSED'. To create an ad group, run add_ad_group.rb.
-#
-# Tags: AdGroupService.mutate
-
-require 'adwords_api'
-
-def update_ad_group(ad_group_id)
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
- # when called without parameters.
- adwords = AdwordsApi::Api.new
-
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
- # the configuration file or provide your own logger:
- # adwords.logger = Logger.new('adwords_xml.log')
-
- ad_group_srv = adwords.service(:AdGroupService, API_VERSION)
-
- # Prepare for updating ad group.
- operation = {
- :operator => 'SET',
- :operand => {
- :status => 'PAUSED',
- :id => ad_group_id
- }
- }
-
- # Update ad group.
- response = ad_group_srv.mutate([operation])
- if response and response[:value]
- ad_group = response[:value].first
- puts 'Ad group id %d was successfully updated.' % ad_group[:id]
- else
- puts 'No ad groups were updated.'
- end
-end
-
-if __FILE__ == $0
- API_VERSION = :v201206
-
- begin
- # ID of an ad group to update.
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
- update_ad_group(ad_group_id)
-
- # HTTP errors.