From a3eba94a596f9d049ed4b59c9666158dae3381fa Mon Sep 17 00:00:00 2001 From: Michael Cloonan Date: Thu, 4 Jun 2015 12:57:00 -0400 Subject: [PATCH] Allowing requests with no CID specified, and updating some examples. --- adwords_api/ChangeLog | 3 + .../handle_captcha_challenge.rb | 93 ------------------- .../handle_two_factor_authorization_error.rb | 88 ------------------ ...d_words_session_without_properties_file.rb | 2 +- .../optimization/estimate_keyword_traffic.rb | 3 +- .../remarketing/add_conversion_tracker.rb | 2 +- .../account_management/get_account_changes.rb | 12 +-- .../advanced_operations/add_ad_customizers.rb | 6 +- .../add_text_ad_with_upgraded_urls.rb | 7 +- .../handle_captcha_challenge.rb | 93 ------------------- .../handle_two_factor_authorization_error.rb | 88 ------------------ .../v201502/extensions/add_site_links.rb | 7 +- .../migrate_to_extension_settings.rb | 6 +- ...d_words_session_without_properties_file.rb | 2 +- .../optimization/estimate_keyword_traffic.rb | 7 +- .../get_keyword_bid_simulations.rb | 2 +- .../v201502/remarketing/add_audience.rb | 4 +- .../remarketing/add_conversion_tracker.rb | 3 +- .../lib/adwords_api/credential_handler.rb | 11 +-- adwords_api/lib/adwords_api/version.rb | 2 +- .../adwords_api/test_credential_handler.rb | 17 ---- .../test/adwords_api/test_report_utils.rb | 14 ++- .../basic_operations_get_campaigns.def | 18 ++-- .../basic_operations_get_campaigns.def | 18 ++-- 24 files changed, 71 insertions(+), 437 deletions(-) delete mode 100755 adwords_api/examples/v201409/error_handling/handle_captcha_challenge.rb delete mode 100755 adwords_api/examples/v201409/error_handling/handle_two_factor_authorization_error.rb delete mode 100755 adwords_api/examples/v201502/error_handling/handle_captcha_challenge.rb delete mode 100755 adwords_api/examples/v201502/error_handling/handle_two_factor_authorization_error.rb diff --git a/adwords_api/ChangeLog b/adwords_api/ChangeLog index 52066d74b..48a23043a 100755 --- a/adwords_api/ChangeLog +++ b/adwords_api/ChangeLog @@ -1,3 +1,6 @@ +0.15.1: + - Allowing requests without CID specified for use with CustomerService. + 0.15.0: - Removed deprecated API version v201406. - Updated Feeds migration example to account for platform restrictions. diff --git a/adwords_api/examples/v201409/error_handling/handle_captcha_challenge.rb b/adwords_api/examples/v201409/error_handling/handle_captcha_challenge.rb deleted file mode 100755 index 528884924..000000000 --- a/adwords_api/examples/v201409/error_handling/handle_captcha_challenge.rb +++ /dev/null @@ -1,93 +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 handle 'CAPTCHA required' authorization -# errors. Refer to the best practices guide on how to avoid this error: -# -# http://code.google.com/apis/adwords/docs/guides/bestpractices.html#auth_tokens - -require 'adwords_api' - -def handle_captcha_challenge() - # Initialize token variable. - logintoken = nil - - # This code will repeatedly request authToken from the server until it gets - # a CAPTCHA challenge request. It is here for illustration purposes only - # and should never be used in a real application. - begin - MAX_RETRIES.times do |retry_number| - puts "Running request %d of %d..." % [retry_number + 1, MAX_RETRIES] - # Forcing library to request a new authorization token. - adwords = AdwordsApi::Api.new - auth_token = adwords.authorize() - end - # Still no challenge, make sure ClientLogin authorization is used. - raise StandardError, "Failed to get challenge after %d requests." % - MAX_RETRIES - rescue AdsCommon::Errors::CaptchaRequiredError => e - logintoken = e.captcha_token - end - - puts "CaptchaRequiredError occurred. To recover download the image and type" + - " the CAPTCHA below: %s\n" % e.captcha_url - puts 'Enter code or ENTER to retry: ' - logincaptcha = gets.chomp - - # Initialize variable for extra parameters. - credentials = {} - if logincaptcha and !logincaptcha.empty? - credentials[:logincaptcha] = logincaptcha - credentials[:logintoken] = logintoken - end - - begin - adwords = AdwordsApi::Api.new - auth_token = adwords.authorize(credentials) - puts "Successfully retrieved authToken: " + auth_token - rescue AdsCommon::Errors::CaptchaRequiredError => e - puts 'Invalid CAPTCHA text entered.' - raise e - end -end - -if __FILE__ == $0 - API_VERSION = :v201409 - MAX_RETRIES = 500 - - begin - handle_captcha_challenge() - - # 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 diff --git a/adwords_api/examples/v201409/error_handling/handle_two_factor_authorization_error.rb b/adwords_api/examples/v201409/error_handling/handle_two_factor_authorization_error.rb deleted file mode 100755 index fcc32c903..000000000 --- a/adwords_api/examples/v201409/error_handling/handle_two_factor_authorization_error.rb +++ /dev/null @@ -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 handle 'two factor' authorization error. - -require 'adwords_api' - -def handle_two_factor_authorization_error() - # Set up credentials with an account that has 2Factor enabled. - config = { - :authentication => { - :method => 'ClientLogin', - :email => '2steptester@gmail.com', - :password => 'testaccount', - :user_agent => 'Ruby 2 Factor Sample', - :developer_token => 'qwerty' - }, - :service => { - :environment => 'PRODUCTION' - } - } - adwords = AdwordsApi::Api.new(config) - - # 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') - - begin - # Forcing library to request authorization token. - auth_token = adwords.authorize() - puts 'Successfully retrieved the token.' - - # Second factor error is one of AuthErrors. - rescue AdsCommon::Errors::AuthError => e - puts "Authorization failed with message:" - puts "\t%s" % e.message - # Checking 'Info' field for particular auth error type. - if e.info and e.info.casecmp('InvalidSecondFactor') == 0 - puts "The user has enabled two factor authentication in this account." + - " Please use OAuth authentication method or have the user generate an" + - " application-specific password to make calls against the AdWords" + - " API. See \n" + - " http://adwordsapi.blogspot.com/2011/02/authentication-changes-with" + - "-2-step.html\n" + - "for more details." - end - end -end - -if __FILE__ == $0 - API_VERSION = :v201409 - - begin - handle_two_factor_authorization_error() - - # 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 diff --git a/adwords_api/examples/v201409/misc/create_ad_words_session_without_properties_file.rb b/adwords_api/examples/v201409/misc/create_ad_words_session_without_properties_file.rb index 38e5137d1..d320dfad2 100755 --- a/adwords_api/examples/v201409/misc/create_ad_words_session_without_properties_file.rb +++ b/adwords_api/examples/v201409/misc/create_ad_words_session_without_properties_file.rb @@ -34,7 +34,7 @@ def create_ad_words_session(client_id, client_secret, refresh_token, :oauth2_client_id => client_id, :oauth2_client_secret => client_secret, :developer_token => developer_token, - :client_customer_id => client_customer_id + :client_customer_id => client_customer_id, :user_agent => user_agent, :oauth2_token => { :refresh_token => refresh_token diff --git a/adwords_api/examples/v201409/optimization/estimate_keyword_traffic.rb b/adwords_api/examples/v201409/optimization/estimate_keyword_traffic.rb index ec8745b37..664ec74d4 100755 --- a/adwords_api/examples/v201409/optimization/estimate_keyword_traffic.rb +++ b/adwords_api/examples/v201409/optimization/estimate_keyword_traffic.rb @@ -90,7 +90,7 @@ def estimate_keyword_traffic() ) mean_avg_position = calculate_mean( estimate[:min][:average_position], - estimate[:max][:average_position]) + estimate[:max][:average_position] ) mean_clicks = calculate_mean( estimate[:min][:clicks_per_day], @@ -107,6 +107,7 @@ def estimate_keyword_traffic() puts "\tEstimated ad position: %s" % format_mean(mean_avg_position) puts "\tEstimated daily clicks: %s" % format_mean(mean_clicks) puts "\tEstimated daily cost: %s" % format_mean(mean_total_cost) + end else puts 'No traffic estimates were returned.' end diff --git a/adwords_api/examples/v201409/remarketing/add_conversion_tracker.rb b/adwords_api/examples/v201409/remarketing/add_conversion_tracker.rb index 937240ba3..5892ce000 100755 --- a/adwords_api/examples/v201409/remarketing/add_conversion_tracker.rb +++ b/adwords_api/examples/v201409/remarketing/add_conversion_tracker.rb @@ -57,7 +57,7 @@ def add_conversion_tracker() :conversion_page_language => 'en', :background_color => '#0000FF', :default_revenue_value => 23.41, - :always_use_default_revenue_value = true + :always_use_default_revenue_value => true } } diff --git a/adwords_api/examples/v201502/account_management/get_account_changes.rb b/adwords_api/examples/v201502/account_management/get_account_changes.rb index f3192bb3a..1bdec69a0 100755 --- a/adwords_api/examples/v201502/account_management/get_account_changes.rb +++ b/adwords_api/examples/v201502/account_management/get_account_changes.rb @@ -82,10 +82,10 @@ def get_account_changes() campaign[:added_ad_extensions].pretty_inspect.chomp puts "\tAdded campaign criteria: '%s'" % campaign[:added_campaign_criteria].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 + puts "\tRemoved ad extensions: '%s'" % + campaign[:removed_ad_extensions].pretty_inspect.chomp + puts "\tRemoved campaign criteria: '%s'" % + campaign[:removed_campaign_criteria].pretty_inspect.chomp if campaign[:changed_ad_groups] campaign[:changed_ad_groups].each do |ad_group| @@ -98,8 +98,8 @@ def get_account_changes() 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 + puts "\t\tCriteria removed: '%s'" % + ad_group[:removed_criteria].pretty_inspect.chomp end end end diff --git a/adwords_api/examples/v201502/advanced_operations/add_ad_customizers.rb b/adwords_api/examples/v201502/advanced_operations/add_ad_customizers.rb index 7459a7619..8b3cb056b 100755 --- a/adwords_api/examples/v201502/advanced_operations/add_ad_customizers.rb +++ b/adwords_api/examples/v201502/advanced_operations/add_ad_customizers.rb @@ -99,9 +99,9 @@ def add_ad_customizers(feed_name, ad_group_ids) # All set! We can now create ads with customizations. text_ad = { :xsi_type => 'TextAd', - :headline => 'Luxury Cruise to {=CustomizerFeed.Name}', - :description1 => 'Only {=CustomizerFeed.Price}', - :description2 => 'Offer ends in {=countdown(CustomizerFeed.Date)}!', + :headline => 'Luxury Cruise to {=%s.Name}' % feed_name, + :description1 => 'Only {=%s.Price}' % feed_name, + :description2 => 'Offer ends in {=countdown(%s.Date)}!' % feed_name, :final_urls => ['http://www.example.com'], :display_url => 'www.example.com' } diff --git a/adwords_api/examples/v201502/advanced_operations/add_text_ad_with_upgraded_urls.rb b/adwords_api/examples/v201502/advanced_operations/add_text_ad_with_upgraded_urls.rb index 1b3a9b84e..408e5f6a1 100755 --- a/adwords_api/examples/v201502/advanced_operations/add_text_ad_with_upgraded_urls.rb +++ b/adwords_api/examples/v201502/advanced_operations/add_text_ad_with_upgraded_urls.rb @@ -94,9 +94,10 @@ def add_text_ad_with_upgraded_urls(ad_group_id) puts "\tFinal URLs: %s" % [text_ad[:final_urls].join(', ')] puts "\tFinal Mobile URLs: %s" % [text_ad[:final_mobile_urls].join(', ')] puts "\tTracking URL template: %s" % [text_ad[:tracking_url_template]] - custom_parameters = text_ad[:custom_parameters].map do |custom_parameter| - "%s=%s" % [custom_parameter[:key], custom_parameter[:value]] - end + custom_parameters = + text_ad[:url_custom_parameters][:parameters].map do |custom_parameter| + "%s=%s" % [custom_parameter[:key], custom_parameter[:value]] + end puts "\tCustom parameters: %s" % [custom_parameters.join(', ')] end else diff --git a/adwords_api/examples/v201502/error_handling/handle_captcha_challenge.rb b/adwords_api/examples/v201502/error_handling/handle_captcha_challenge.rb deleted file mode 100755 index 319f8aa00..000000000 --- a/adwords_api/examples/v201502/error_handling/handle_captcha_challenge.rb +++ /dev/null @@ -1,93 +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 handle 'CAPTCHA required' authorization -# errors. Refer to the best practices guide on how to avoid this error: -# -# http://code.google.com/apis/adwords/docs/guides/bestpractices.html#auth_tokens - -require 'adwords_api' - -def handle_captcha_challenge() - # Initialize token variable. - logintoken = nil - - # This code will repeatedly request authToken from the server until it gets - # a CAPTCHA challenge request. It is here for illustration purposes only - # and should never be used in a real application. - begin - MAX_RETRIES.times do |retry_number| - puts "Running request %d of %d..." % [retry_number + 1, MAX_RETRIES] - # Forcing library to request a new authorization token. - adwords = AdwordsApi::Api.new - auth_token = adwords.authorize() - end - # Still no challenge, make sure ClientLogin authorization is used. - raise StandardError, "Failed to get challenge after %d requests." % - MAX_RETRIES - rescue AdsCommon::Errors::CaptchaRequiredError => e - logintoken = e.captcha_token - end - - puts "CaptchaRequiredError occurred. To recover download the image and type" + - " the CAPTCHA below: %s\n" % e.captcha_url - puts 'Enter code or ENTER to retry: ' - logincaptcha = gets.chomp - - # Initialize variable for extra parameters. - credentials = {} - if logincaptcha and !logincaptcha.empty? - credentials[:logincaptcha] = logincaptcha - credentials[:logintoken] = logintoken - end - - begin - adwords = AdwordsApi::Api.new - auth_token = adwords.authorize(credentials) - puts "Successfully retrieved authToken: " + auth_token - rescue AdsCommon::Errors::CaptchaRequiredError => e - puts 'Invalid CAPTCHA text entered.' - raise e - end -end - -if __FILE__ == $0 - API_VERSION = :v201502 - MAX_RETRIES = 500 - - begin - handle_captcha_challenge() - - # 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 diff --git a/adwords_api/examples/v201502/error_handling/handle_two_factor_authorization_error.rb b/adwords_api/examples/v201502/error_handling/handle_two_factor_authorization_error.rb deleted file mode 100755 index 3a3db5dfa..000000000 --- a/adwords_api/examples/v201502/error_handling/handle_two_factor_authorization_error.rb +++ /dev/null @@ -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 handle 'two factor' authorization error. - -require 'adwords_api' - -def handle_two_factor_authorization_error() - # Set up credentials with an account that has 2Factor enabled. - config = { - :authentication => { - :method => 'ClientLogin', - :email => '2steptester@gmail.com', - :password => 'testaccount', - :user_agent => 'Ruby 2 Factor Sample', - :developer_token => 'qwerty' - }, - :service => { - :environment => 'PRODUCTION' - } - } - adwords = AdwordsApi::Api.new(config) - - # 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') - - begin - # Forcing library to request authorization token. - auth_token = adwords.authorize() - puts 'Successfully retrieved the token.' - - # Second factor error is one of AuthErrors. - rescue AdsCommon::Errors::AuthError => e - puts "Authorization failed with message:" - puts "\t%s" % e.message - # Checking 'Info' field for particular auth error type. - if e.info and e.info.casecmp('InvalidSecondFactor') == 0 - puts "The user has enabled two factor authentication in this account." + - " Please use OAuth authentication method or have the user generate an" + - " application-specific password to make calls against the AdWords" + - " API. See \n" + - " http://adwordsapi.blogspot.com/2011/02/authentication-changes-with" + - "-2-step.html\n" + - "for more details." - end - end -end - -if __FILE__ == $0 - API_VERSION = :v201502 - - begin - handle_two_factor_authorization_error() - - # 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 diff --git a/adwords_api/examples/v201502/extensions/add_site_links.rb b/adwords_api/examples/v201502/extensions/add_site_links.rb index ca7dc9a10..cf7b9c05b 100755 --- a/adwords_api/examples/v201502/extensions/add_site_links.rb +++ b/adwords_api/examples/v201502/extensions/add_site_links.rb @@ -125,9 +125,10 @@ def add_site_links(campaign_id) response = campaign_extension_setting_srv.mutate([operation]) if response and response[:value] new_extension_setting = response[:value].first - puts "Extension setting wiht type = %s was added to campaign ID %d" % - [new_extension_setting[:extension_type][:value], - new_extension_setting[:campaign_id]] + puts "Extension setting wiht type = %s was added to campaign ID %d" % [ + new_extension_setting[:extension_type], + new_extension_setting[:campaign_id] + ] elsif puts "No extension settings were created." end diff --git a/adwords_api/examples/v201502/migration/migrate_to_extension_settings.rb b/adwords_api/examples/v201502/migration/migrate_to_extension_settings.rb index b87adeddf..8b69541d4 100755 --- a/adwords_api/examples/v201502/migration/migrate_to_extension_settings.rb +++ b/adwords_api/examples/v201502/migration/migrate_to_extension_settings.rb @@ -57,10 +57,10 @@ def migrate_to_extension_settings() feed_item_ids = get_feed_item_ids_for_campaign(campaign_feed) if feed_item_ids.empty? - puts("Migration skipped for campaign feed with campaign ID %d " + + puts(("Migration skipped for campaign feed with campaign ID %d " + "and feed ID %d because no mapped feed item IDs were found in " + "the campaign feed's matching function.") % - [campaign_feed[:campaign_id], campaign_feed[:feed_id]] + [campaign_feed[:campaign_id], campaign_feed[:feed_id]]) next end @@ -76,7 +76,7 @@ def migrate_to_extension_settings() # Mark the sitelinks from the feed for deletion. feed_item_ids - end.flatten.to_set + end.flatten.to_set.reject {|id| id.nil?} # Delete all the sitelinks from the feed. delete_old_feed_items(adwords, all_feed_items_to_delete, feed) diff --git a/adwords_api/examples/v201502/misc/create_ad_words_session_without_properties_file.rb b/adwords_api/examples/v201502/misc/create_ad_words_session_without_properties_file.rb index 89ddbf004..37f6cd6e3 100755 --- a/adwords_api/examples/v201502/misc/create_ad_words_session_without_properties_file.rb +++ b/adwords_api/examples/v201502/misc/create_ad_words_session_without_properties_file.rb @@ -34,7 +34,7 @@ def create_ad_words_session(client_id, client_secret, refresh_token, :oauth2_client_id => client_id, :oauth2_client_secret => client_secret, :developer_token => developer_token, - :client_customer_id => client_customer_id + :client_customer_id => client_customer_id, :user_agent => user_agent, :oauth2_token => { :refresh_token => refresh_token diff --git a/adwords_api/examples/v201502/optimization/estimate_keyword_traffic.rb b/adwords_api/examples/v201502/optimization/estimate_keyword_traffic.rb index 1106f3140..83c20f8ff 100755 --- a/adwords_api/examples/v201502/optimization/estimate_keyword_traffic.rb +++ b/adwords_api/examples/v201502/optimization/estimate_keyword_traffic.rb @@ -84,13 +84,9 @@ def estimate_keyword_traffic() keyword = keyword_requests[index][:keyword] # Find the mean of the min and max values. - mean_avg_cpc = calculate_mean( - estimate[:min][:average_cpc][:micro_amount], - estimate[:max][:average_cpc][:micro_amount] - ) mean_avg_position = calculate_mean( estimate[:min][:average_position], - estimate[:max][:average_position]) + estimate[:max][:average_position] ) mean_clicks = calculate_mean( estimate[:min][:clicks_per_day], @@ -103,7 +99,6 @@ def estimate_keyword_traffic() puts "Results for the keyword with text '%s' and match type %s:" % [keyword[:text], keyword[:match_type]] - puts "\tEstimated average CPC: %s" % format_mean(mean_avg_cpc) puts "\tEstimated ad position: %s" % format_mean(mean_avg_position) puts "\tEstimated daily clicks: %s" % format_mean(mean_clicks) puts "\tEstimated daily cost: %s" % format_mean(mean_total_cost) diff --git a/adwords_api/examples/v201502/optimization/get_keyword_bid_simulations.rb b/adwords_api/examples/v201502/optimization/get_keyword_bid_simulations.rb index 50619e9a6..9c36dff04 100755 --- a/adwords_api/examples/v201502/optimization/get_keyword_bid_simulations.rb +++ b/adwords_api/examples/v201502/optimization/get_keyword_bid_simulations.rb @@ -39,7 +39,7 @@ def get_criterion_bid_landscapes(ad_group_id, keyword_id) # Get keyword bid landscape. selector = { :fields => ['AdGroupId', 'CriterionId', 'StartDate', 'EndDate', 'Bid', - 'LocalClicks', 'LocalCost', 'MarginalCpc', 'LocalImpressions'], + 'LocalClicks', 'LocalCost', 'LocalImpressions'], :predicates => [ {:field => 'AdGroupId', :operator => 'IN', :values => [ad_group_id]}, {:field => 'CriterionId', :operator => 'IN', :values => [keyword_id]}, diff --git a/adwords_api/examples/v201502/remarketing/add_audience.rb b/adwords_api/examples/v201502/remarketing/add_audience.rb index 32de620e1..51a0efa75 100755 --- a/adwords_api/examples/v201502/remarketing/add_audience.rb +++ b/adwords_api/examples/v201502/remarketing/add_audience.rb @@ -62,13 +62,13 @@ def add_audience() # Get conversion snippets. if user_list and user_list[:conversion_types] - conversion_ids = user_list[:conversion_types].map {|type| type[:id]} + conversion_ids = user_list[:conversion_types][:id] selector = { # We're actually interested in the 'Snippet' field, which is returned # automatically. :fields => ['Id'], :predicates => [ - {:field => 'Id', :operator => 'IN', :values => conversion_ids} + {:field => 'Id', :operator => 'IN', :values => [conversion_ids]} ] } conv_tracker_response = conv_tracker_srv.get(selector) diff --git a/adwords_api/examples/v201502/remarketing/add_conversion_tracker.rb b/adwords_api/examples/v201502/remarketing/add_conversion_tracker.rb index 86de2815d..0bafc2987 100755 --- a/adwords_api/examples/v201502/remarketing/add_conversion_tracker.rb +++ b/adwords_api/examples/v201502/remarketing/add_conversion_tracker.rb @@ -51,13 +51,12 @@ def add_conversion_tracker() # Optional fields: :status => 'ENABLED', :viewthrough_lookback_window => 15, - :viewthrough_conversion_de_dup_search => true, :is_product_ads_chargeable => true, :product_ads_chargeable_conversion_window => 15, :conversion_page_language => 'en', :background_color => '#0000FF', :default_revenue_value => 23.41, - :always_use_default_revenue_value = true + :always_use_default_revenue_value => true } } diff --git a/adwords_api/lib/adwords_api/credential_handler.rb b/adwords_api/lib/adwords_api/credential_handler.rb index bdd10b7db..d48462d3c 100755 --- a/adwords_api/lib/adwords_api/credential_handler.rb +++ b/adwords_api/lib/adwords_api/credential_handler.rb @@ -45,7 +45,8 @@ def credentials(credentials_override = nil) 'userAgent' => generate_user_agent(), 'developerToken' => result[:developer_token] } - extra_headers['clientCustomerId'] = result[:client_customer_id] + extra_headers['clientCustomerId'] = result[:client_customer_id] if + result[:client_customer_id] extra_headers['validateOnly'] = 'true' if @validate_only extra_headers['partialFailure'] = 'true' if @partial_failure result[:extra_headers] = extra_headers @@ -70,13 +71,9 @@ def generate_user_agent(extra_ids = []) # def validate_headers_for_server(credentials) client_customer_id = credentials[:client_customer_id] - unless client_customer_id - raise AdwordsApi::Errors::BadCredentialsError, - 'Missing client customer ID for the request.' - end - if !(client_customer_id.is_a?(Integer) or - (client_customer_id =~ /^\d+(-\d+-\d+)?$/)) + if client_customer_id and (!(client_customer_id.is_a?(Integer) or + (client_customer_id =~ /^\d+(-\d+-\d+)?$/))) raise AdwordsApi::Errors::BadCredentialsError, 'Invalid client customer ID: %s' % client_customer_id.to_s end diff --git a/adwords_api/lib/adwords_api/version.rb b/adwords_api/lib/adwords_api/version.rb index 45e628a90..bbcdd459b 100755 --- a/adwords_api/lib/adwords_api/version.rb +++ b/adwords_api/lib/adwords_api/version.rb @@ -21,6 +21,6 @@ module AdwordsApi module ApiConfig - CLIENT_LIB_VERSION = '0.15.0' + CLIENT_LIB_VERSION = '0.15.1' end end diff --git a/adwords_api/test/adwords_api/test_credential_handler.rb b/adwords_api/test/adwords_api/test_credential_handler.rb index 2a19901fb..376995f9c 100755 --- a/adwords_api/test/adwords_api/test_credential_handler.rb +++ b/adwords_api/test/adwords_api/test_credential_handler.rb @@ -104,23 +104,6 @@ def test_validate_headers_for_server_invalid_cid() end end - def test_validate_headers_for_server_no_client_customer_id() - credentials1 = { - :developer_token => 'AbC' - } - assert_raise(AdwordsApi::Errors::BadCredentialsError) do - @handler.validate_headers_for_server(credentials1) - end - - credentials2 = { - :client_customer_id => nil, - :developer_token => 'AbC' - } - assert_raise(AdwordsApi::Errors::BadCredentialsError) do - @handler.validate_headers_for_server(credentials2) - end - end - def test_validate_headers_for_server_no_developer_token() credentials1 = {:client_customer_id => '123-456-7890'} assert_raise(AdwordsApi::Errors::BadCredentialsError) do diff --git a/adwords_api/test/adwords_api/test_report_utils.rb b/adwords_api/test/adwords_api/test_report_utils.rb index cb9e7226d..e17038ed2 100755 --- a/adwords_api/test/adwords_api/test_report_utils.rb +++ b/adwords_api/test/adwords_api/test_report_utils.rb @@ -60,7 +60,19 @@ class TestReportUtils < Test::Unit::TestCase # Initialize tests. def setup() - @api = AdwordsApi::Api.new + @api = AdwordsApi::Api.new({ + :authentication => { + :method => 'OAuth2', + :oauth2_client_id => 'client_id123', + :oauth2_client_secret => 'client_secret123', + :developer_token => 'developer_token123', + :client_customer_id => '012-345-6789', + :user_agent => 'TestReportUtils' + }, + :service => { + :environment => 'PRODUCTION' + } + }) @report_utils = @api.report_utils(API_VERSION) end diff --git a/adwords_api/test/templates/v201409/basic_operations_get_campaigns.def b/adwords_api/test/templates/v201409/basic_operations_get_campaigns.def index eca058cf7..51b075710 100755 --- a/adwords_api/test/templates/v201409/basic_operations_get_campaigns.def +++ b/adwords_api/test/templates/v201409/basic_operations_get_campaigns.def @@ -2,18 +2,21 @@ def setup_mocks() $api_config = { :service => {:environment => 'PRODUCTION'}, :authentication => { - :method => 'ClientLogin', - :email => 'noreply@google.com', - :password => 'noreply_password', + :method => 'OAuth2', + :oauth2_client_id => 'client_id123', + :oauth2_client_secret => 'client_secret123', :developer_token => 'dev_token123', :client_customer_id => '123-456-7890', - :user_agent => 'ruby-tests' + :user_agent => 'ruby-tests', + :oauth2_token => { + :refresh_token => 'refresh_token123' + } } } - stub_request(:post, "https://www.google.com/accounts/ClientLogin"). - with(:body => {"Email"=>"noreply@google.com", "Passwd"=>"noreply_password", "accountType"=>"GOOGLE", "service"=>"adwords"}). - to_return(:status => 200, :body => "SID=abcSIDbcd\nLSID=abcLSIDbcd\nAuth=abcAuthbcd\n", :headers => {}) + stub_request(:post, "https://accounts.google.com/o/oauth2/auth"). + with(:body => {"client_id"=>"client_id123", "client_secret"=>"client_secret123", "refresh_token"=>"refresh_token123", "grant_type"=>"refresh_token"}). + to_return(:status => 200, :body => '{"access_token":"access_token123","token_type":"Bearer","expires_in":"3600"}\n', :headers => {}) stub_request(:post, "https://adwords.google.com/api/adwords/cm/v201409/CampaignService"). with( @@ -25,7 +28,6 @@ def setup_mocks() {"userAgent"=>"ruby-tests (AwApi-Ruby/0.15.0, Common-Ruby/0.9.8, Savon/1.2.0, ruby/1.9.3, HTTPI/1.1.1, net_http)", "developerToken"=>"dev_token123", "clientCustomerId"=>"123-456-7890", - "authToken"=>"abcAuthbcd", "xmlns"=>"https://adwords.google.com/api/adwords/cm/v201409"}}, "env:Body"=> {"get"=> diff --git a/adwords_api/test/templates/v201502/basic_operations_get_campaigns.def b/adwords_api/test/templates/v201502/basic_operations_get_campaigns.def index 662ee415a..931b6a3dd 100755 --- a/adwords_api/test/templates/v201502/basic_operations_get_campaigns.def +++ b/adwords_api/test/templates/v201502/basic_operations_get_campaigns.def @@ -2,18 +2,21 @@ def setup_mocks() $api_config = { :service => {:environment => 'PRODUCTION'}, :authentication => { - :method => 'ClientLogin', - :email => 'noreply@google.com', - :password => 'noreply_password', + :method => 'OAuth2', + :oauth2_client_id => 'client_id123', + :oauth2_client_secret => 'client_secret123', :developer_token => 'dev_token123', :client_customer_id => '123-456-7890', - :user_agent => 'ruby-tests' + :user_agent => 'ruby-tests', + :oauth2_token => { + :refresh_token => 'refresh_token123' + } } } - stub_request(:post, "https://www.google.com/accounts/ClientLogin"). - with(:body => {"Email"=>"noreply@google.com", "Passwd"=>"noreply_password", "accountType"=>"GOOGLE", "service"=>"adwords"}). - to_return(:status => 200, :body => "SID=abcSIDbcd\nLSID=abcLSIDbcd\nAuth=abcAuthbcd\n", :headers => {}) + stub_request(:post, "https://accounts.google.com/o/oauth2/auth"). + with(:body => {"client_id"=>"client_id123", "client_secret"=>"client_secret123", "refresh_token"=>"refresh_token123", "grant_type"=>"refresh_token"}). + to_return(:status => 200, :body => '{"access_token":"access_token123","token_type":"Bearer","expires_in":"3600"}\n', :headers => {}) stub_request(:post, "https://adwords.google.com/api/adwords/cm/v201502/CampaignService"). with( @@ -25,7 +28,6 @@ def setup_mocks() {"userAgent"=>"ruby-tests (AwApi-Ruby/0.15.0, Common-Ruby/0.9.8, Savon/1.2.0, ruby/1.9.3, HTTPI/1.1.1, net_http)", "developerToken"=>"dev_token123", "clientCustomerId"=>"123-456-7890", - "authToken"=>"abcAuthbcd", "xmlns"=>"https://adwords.google.com/api/adwords/cm/v201502"}}, "env:Body"=> {"get"=>