google-adwords-api 0.15.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. checksums.yaml +8 -8
  2. data/ChangeLog +3 -0
  3. data/examples/v201409/misc/create_ad_words_session_without_properties_file.rb +1 -1
  4. data/examples/v201409/optimization/estimate_keyword_traffic.rb +2 -1
  5. data/examples/v201409/remarketing/add_conversion_tracker.rb +1 -1
  6. data/examples/v201502/account_management/get_account_changes.rb +6 -6
  7. data/examples/v201502/advanced_operations/add_ad_customizers.rb +3 -3
  8. data/examples/v201502/advanced_operations/add_text_ad_with_upgraded_urls.rb +4 -3
  9. data/examples/v201502/extensions/add_site_links.rb +4 -3
  10. data/examples/v201502/migration/migrate_to_extension_settings.rb +3 -3
  11. data/examples/v201502/misc/create_ad_words_session_without_properties_file.rb +1 -1
  12. data/examples/v201502/optimization/estimate_keyword_traffic.rb +1 -6
  13. data/examples/v201502/optimization/get_keyword_bid_simulations.rb +1 -1
  14. data/examples/v201502/remarketing/add_audience.rb +2 -2
  15. data/examples/v201502/remarketing/add_conversion_tracker.rb +1 -2
  16. data/lib/adwords_api/credential_handler.rb +4 -7
  17. data/lib/adwords_api/version.rb +1 -1
  18. data/test/adwords_api/test_credential_handler.rb +0 -17
  19. data/test/adwords_api/test_report_utils.rb +13 -1
  20. data/test/templates/v201409/basic_operations_get_campaigns.def +10 -8
  21. data/test/templates/v201502/basic_operations_get_campaigns.def +10 -8
  22. metadata +2 -6
  23. data/examples/v201409/error_handling/handle_captcha_challenge.rb +0 -93
  24. data/examples/v201409/error_handling/handle_two_factor_authorization_error.rb +0 -88
  25. data/examples/v201502/error_handling/handle_captcha_challenge.rb +0 -93
  26. data/examples/v201502/error_handling/handle_two_factor_authorization_error.rb +0 -88
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2IwZjhmNzIxODY2YjM2YzgyY2NiNWVmNWM1OGNmODQwNTBlNzEyNg==
4
+ OWQzMDNlMDY2NjU2NDY0NjU0ZjMzMjRlZGMwYjJhOTdkMzcwMjEwYw==
5
5
  data.tar.gz: !binary |-
6
- NjkyNDVkMTVjZTg1MWZmZmFjYTI2ZjExMjQ0ZjAzOTgyYzU3ZmZlYw==
6
+ ZTBiMWQwYjRmMmUzMTIxZGQ4OWJhNWZlYjU4ZWEwNDUyM2MwMWIwZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NmNiODQ0MzNjMDJlZjZjMTNlYWZiZWMzYWVmN2ZmMjJkZmE3Y2IzNTM2NzE2
10
- MzZkMWNjNDJiNDAxNTFhZTNjNjNjNTkxZDZlODg5NWQ2N2E1MzM4YzJmNmY1
11
- MTNlNWMxZjhiNGE3NTYzNWRmOTExNzVlZWJmZmU4OTY4ZTkxZWM=
9
+ ZDM4ZmIxMjg1M2RkY2EwODZjMzU3OGYxNDM4YWZlZGQ1NjY1NzVmZGFlYzJl
10
+ MzA3YTI4MDFjNGIyZTkxOWZkYWVhZTQ0MTlkOTM3MDdlNmRiZTNkMDdjN2M4
11
+ YmE0MDA0YTg1ZTBlZjIyZTY4YmEyMWE2MTk5Y2E2NjM4MWJkMWE=
12
12
  data.tar.gz: !binary |-
13
- MTU0NTgxMDhjNTNjOTA0MDEyZTJjZGFlMDU2OWRhNDYwOWRlYzA4YzMyZGMx
14
- MGIwYjFkMTFiZWY3MGE3YzcxNDk2ZDZhZjcyYzE0ZGIyMDE4YTkxMzkzMjE1
15
- NDhmMDA4M2UwNDI1YWJlNWY5N2Y3NWNiOGUwYjAzYjI2Nzc0NmQ=
13
+ N2M1MWNiMjQ3NjIzYTA5MjFjNTE5ZTE4NzhhMWJiNGY5Yjc4NDkwNTRkMGNl
14
+ MzMyY2M1OWMzOWVkNmQwOTkxZmNjMGJhZDEwZTUyOTY1OWM3ZTJkZjAwZmU3
15
+ NDliMDNjYjRlMzkwMzg0ZDNiYWY4OTNmNGExMDE4MWY0MDczZjc=
data/ChangeLog CHANGED
@@ -1,3 +1,6 @@
1
+ 0.15.1:
2
+ - Allowing requests without CID specified for use with CustomerService.
3
+
1
4
  0.15.0:
2
5
  - Removed deprecated API version v201406.
3
6
  - Updated Feeds migration example to account for platform restrictions.
@@ -34,7 +34,7 @@ def create_ad_words_session(client_id, client_secret, refresh_token,
34
34
  :oauth2_client_id => client_id,
35
35
  :oauth2_client_secret => client_secret,
36
36
  :developer_token => developer_token,
37
- :client_customer_id => client_customer_id
37
+ :client_customer_id => client_customer_id,
38
38
  :user_agent => user_agent,
39
39
  :oauth2_token => {
40
40
  :refresh_token => refresh_token
@@ -90,7 +90,7 @@ def estimate_keyword_traffic()
90
90
  )
91
91
  mean_avg_position = calculate_mean(
92
92
  estimate[:min][:average_position],
93
- estimate[:max][:average_position])
93
+ estimate[:max][:average_position]
94
94
  )
95
95
  mean_clicks = calculate_mean(
96
96
  estimate[:min][:clicks_per_day],
@@ -107,6 +107,7 @@ def estimate_keyword_traffic()
107
107
  puts "\tEstimated ad position: %s" % format_mean(mean_avg_position)
108
108
  puts "\tEstimated daily clicks: %s" % format_mean(mean_clicks)
109
109
  puts "\tEstimated daily cost: %s" % format_mean(mean_total_cost)
110
+ end
110
111
  else
111
112
  puts 'No traffic estimates were returned.'
112
113
  end
@@ -57,7 +57,7 @@ def add_conversion_tracker()
57
57
  :conversion_page_language => 'en',
58
58
  :background_color => '#0000FF',
59
59
  :default_revenue_value => 23.41,
60
- :always_use_default_revenue_value = true
60
+ :always_use_default_revenue_value => true
61
61
  }
62
62
  }
63
63
 
@@ -82,10 +82,10 @@ def get_account_changes()
82
82
  campaign[:added_ad_extensions].pretty_inspect.chomp
83
83
  puts "\tAdded campaign criteria: '%s'" %
84
84
  campaign[:added_campaign_criteria].pretty_inspect.chomp
85
- puts "\tDeleted ad extensions: '%s'" %
86
- campaign[:deleted_ad_extensions].pretty_inspect.chomp
87
- puts "\tDeleted campaign criteria: '%s'" %
88
- campaign[:deleted_campaign_criteria].pretty_inspect.chomp
85
+ puts "\tRemoved ad extensions: '%s'" %
86
+ campaign[:removed_ad_extensions].pretty_inspect.chomp
87
+ puts "\tRemoved campaign criteria: '%s'" %
88
+ campaign[:removed_campaign_criteria].pretty_inspect.chomp
89
89
 
90
90
  if campaign[:changed_ad_groups]
91
91
  campaign[:changed_ad_groups].each do |ad_group|
@@ -98,8 +98,8 @@ def get_account_changes()
98
98
  ad_group[:changed_ads].pretty_inspect.chomp
99
99
  puts "\t\tCriteria changed: '%s'" %
100
100
  ad_group[:changed_criteria].pretty_inspect.chomp
101
- puts "\t\tCriteria deleted: '%s'" %
102
- ad_group[:deleted_criteria].pretty_inspect.chomp
101
+ puts "\t\tCriteria removed: '%s'" %
102
+ ad_group[:removed_criteria].pretty_inspect.chomp
103
103
  end
104
104
  end
105
105
  end
@@ -99,9 +99,9 @@ def add_ad_customizers(feed_name, ad_group_ids)
99
99
  # All set! We can now create ads with customizations.
100
100
  text_ad = {
101
101
  :xsi_type => 'TextAd',
102
- :headline => 'Luxury Cruise to {=CustomizerFeed.Name}',
103
- :description1 => 'Only {=CustomizerFeed.Price}',
104
- :description2 => 'Offer ends in {=countdown(CustomizerFeed.Date)}!',
102
+ :headline => 'Luxury Cruise to {=%s.Name}' % feed_name,
103
+ :description1 => 'Only {=%s.Price}' % feed_name,
104
+ :description2 => 'Offer ends in {=countdown(%s.Date)}!' % feed_name,
105
105
  :final_urls => ['http://www.example.com'],
106
106
  :display_url => 'www.example.com'
107
107
  }
@@ -94,9 +94,10 @@ def add_text_ad_with_upgraded_urls(ad_group_id)
94
94
  puts "\tFinal URLs: %s" % [text_ad[:final_urls].join(', ')]
95
95
  puts "\tFinal Mobile URLs: %s" % [text_ad[:final_mobile_urls].join(', ')]
96
96
  puts "\tTracking URL template: %s" % [text_ad[:tracking_url_template]]
97
- custom_parameters = text_ad[:custom_parameters].map do |custom_parameter|
98
- "%s=%s" % [custom_parameter[:key], custom_parameter[:value]]
99
- end
97
+ custom_parameters =
98
+ text_ad[:url_custom_parameters][:parameters].map do |custom_parameter|
99
+ "%s=%s" % [custom_parameter[:key], custom_parameter[:value]]
100
+ end
100
101
  puts "\tCustom parameters: %s" % [custom_parameters.join(', ')]
101
102
  end
102
103
  else
@@ -125,9 +125,10 @@ def add_site_links(campaign_id)
125
125
  response = campaign_extension_setting_srv.mutate([operation])
126
126
  if response and response[:value]
127
127
  new_extension_setting = response[:value].first
128
- puts "Extension setting wiht type = %s was added to campaign ID %d" %
129
- [new_extension_setting[:extension_type][:value],
130
- new_extension_setting[:campaign_id]]
128
+ puts "Extension setting wiht type = %s was added to campaign ID %d" % [
129
+ new_extension_setting[:extension_type],
130
+ new_extension_setting[:campaign_id]
131
+ ]
131
132
  elsif
132
133
  puts "No extension settings were created."
133
134
  end
@@ -57,10 +57,10 @@ def migrate_to_extension_settings()
57
57
  feed_item_ids = get_feed_item_ids_for_campaign(campaign_feed)
58
58
 
59
59
  if feed_item_ids.empty?
60
- puts("Migration skipped for campaign feed with campaign ID %d " +
60
+ puts(("Migration skipped for campaign feed with campaign ID %d " +
61
61
  "and feed ID %d because no mapped feed item IDs were found in " +
62
62
  "the campaign feed's matching function.") %
63
- [campaign_feed[:campaign_id], campaign_feed[:feed_id]]
63
+ [campaign_feed[:campaign_id], campaign_feed[:feed_id]])
64
64
  next
65
65
  end
66
66
 
@@ -76,7 +76,7 @@ def migrate_to_extension_settings()
76
76
 
77
77
  # Mark the sitelinks from the feed for deletion.
78
78
  feed_item_ids
79
- end.flatten.to_set
79
+ end.flatten.to_set.reject {|id| id.nil?}
80
80
 
81
81
  # Delete all the sitelinks from the feed.
82
82
  delete_old_feed_items(adwords, all_feed_items_to_delete, feed)
@@ -34,7 +34,7 @@ def create_ad_words_session(client_id, client_secret, refresh_token,
34
34
  :oauth2_client_id => client_id,
35
35
  :oauth2_client_secret => client_secret,
36
36
  :developer_token => developer_token,
37
- :client_customer_id => client_customer_id
37
+ :client_customer_id => client_customer_id,
38
38
  :user_agent => user_agent,
39
39
  :oauth2_token => {
40
40
  :refresh_token => refresh_token
@@ -84,13 +84,9 @@ def estimate_keyword_traffic()
84
84
  keyword = keyword_requests[index][:keyword]
85
85
 
86
86
  # Find the mean of the min and max values.
87
- mean_avg_cpc = calculate_mean(
88
- estimate[:min][:average_cpc][:micro_amount],
89
- estimate[:max][:average_cpc][:micro_amount]
90
- )
91
87
  mean_avg_position = calculate_mean(
92
88
  estimate[:min][:average_position],
93
- estimate[:max][:average_position])
89
+ estimate[:max][:average_position]
94
90
  )
95
91
  mean_clicks = calculate_mean(
96
92
  estimate[:min][:clicks_per_day],
@@ -103,7 +99,6 @@ def estimate_keyword_traffic()
103
99
 
104
100
  puts "Results for the keyword with text '%s' and match type %s:" %
105
101
  [keyword[:text], keyword[:match_type]]
106
- puts "\tEstimated average CPC: %s" % format_mean(mean_avg_cpc)
107
102
  puts "\tEstimated ad position: %s" % format_mean(mean_avg_position)
108
103
  puts "\tEstimated daily clicks: %s" % format_mean(mean_clicks)
109
104
  puts "\tEstimated daily cost: %s" % format_mean(mean_total_cost)
@@ -39,7 +39,7 @@ def get_criterion_bid_landscapes(ad_group_id, keyword_id)
39
39
  # Get keyword bid landscape.
40
40
  selector = {
41
41
  :fields => ['AdGroupId', 'CriterionId', 'StartDate', 'EndDate', 'Bid',
42
- 'LocalClicks', 'LocalCost', 'MarginalCpc', 'LocalImpressions'],
42
+ 'LocalClicks', 'LocalCost', 'LocalImpressions'],
43
43
  :predicates => [
44
44
  {:field => 'AdGroupId', :operator => 'IN', :values => [ad_group_id]},
45
45
  {:field => 'CriterionId', :operator => 'IN', :values => [keyword_id]},
@@ -62,13 +62,13 @@ def add_audience()
62
62
 
63
63
  # Get conversion snippets.
64
64
  if user_list and user_list[:conversion_types]
65
- conversion_ids = user_list[:conversion_types].map {|type| type[:id]}
65
+ conversion_ids = user_list[:conversion_types][:id]
66
66
  selector = {
67
67
  # We're actually interested in the 'Snippet' field, which is returned
68
68
  # automatically.
69
69
  :fields => ['Id'],
70
70
  :predicates => [
71
- {:field => 'Id', :operator => 'IN', :values => conversion_ids}
71
+ {:field => 'Id', :operator => 'IN', :values => [conversion_ids]}
72
72
  ]
73
73
  }
74
74
  conv_tracker_response = conv_tracker_srv.get(selector)
@@ -51,13 +51,12 @@ def add_conversion_tracker()
51
51
  # Optional fields:
52
52
  :status => 'ENABLED',
53
53
  :viewthrough_lookback_window => 15,
54
- :viewthrough_conversion_de_dup_search => true,
55
54
  :is_product_ads_chargeable => true,
56
55
  :product_ads_chargeable_conversion_window => 15,
57
56
  :conversion_page_language => 'en',
58
57
  :background_color => '#0000FF',
59
58
  :default_revenue_value => 23.41,
60
- :always_use_default_revenue_value = true
59
+ :always_use_default_revenue_value => true
61
60
  }
62
61
  }
63
62
 
@@ -45,7 +45,8 @@ module AdwordsApi
45
45
  'userAgent' => generate_user_agent(),
46
46
  'developerToken' => result[:developer_token]
47
47
  }
48
- extra_headers['clientCustomerId'] = result[:client_customer_id]
48
+ extra_headers['clientCustomerId'] = result[:client_customer_id] if
49
+ result[:client_customer_id]
49
50
  extra_headers['validateOnly'] = 'true' if @validate_only
50
51
  extra_headers['partialFailure'] = 'true' if @partial_failure
51
52
  result[:extra_headers] = extra_headers
@@ -70,13 +71,9 @@ module AdwordsApi
70
71
  #
71
72
  def validate_headers_for_server(credentials)
72
73
  client_customer_id = credentials[:client_customer_id]
73
- unless client_customer_id
74
- raise AdwordsApi::Errors::BadCredentialsError,
75
- 'Missing client customer ID for the request.'
76
- end
77
74
 
78
- if !(client_customer_id.is_a?(Integer) or
79
- (client_customer_id =~ /^\d+(-\d+-\d+)?$/))
75
+ if client_customer_id and (!(client_customer_id.is_a?(Integer) or
76
+ (client_customer_id =~ /^\d+(-\d+-\d+)?$/)))
80
77
  raise AdwordsApi::Errors::BadCredentialsError,
81
78
  'Invalid client customer ID: %s' % client_customer_id.to_s
82
79
  end
@@ -21,6 +21,6 @@
21
21
 
22
22
  module AdwordsApi
23
23
  module ApiConfig
24
- CLIENT_LIB_VERSION = '0.15.0'
24
+ CLIENT_LIB_VERSION = '0.15.1'
25
25
  end
26
26
  end
@@ -104,23 +104,6 @@ class TestCredentialHandler < Test::Unit::TestCase
104
104
  end
105
105
  end
106
106
 
107
- def test_validate_headers_for_server_no_client_customer_id()
108
- credentials1 = {
109
- :developer_token => 'AbC'
110
- }
111
- assert_raise(AdwordsApi::Errors::BadCredentialsError) do
112
- @handler.validate_headers_for_server(credentials1)
113
- end
114
-
115
- credentials2 = {
116
- :client_customer_id => nil,
117
- :developer_token => 'AbC'
118
- }
119
- assert_raise(AdwordsApi::Errors::BadCredentialsError) do
120
- @handler.validate_headers_for_server(credentials2)
121
- end
122
- end
123
-
124
107
  def test_validate_headers_for_server_no_developer_token()
125
108
  credentials1 = {:client_customer_id => '123-456-7890'}
126
109
  assert_raise(AdwordsApi::Errors::BadCredentialsError) do
@@ -60,7 +60,19 @@ class TestReportUtils < Test::Unit::TestCase
60
60
 
61
61
  # Initialize tests.
62
62
  def setup()
63
- @api = AdwordsApi::Api.new
63
+ @api = AdwordsApi::Api.new({
64
+ :authentication => {
65
+ :method => 'OAuth2',
66
+ :oauth2_client_id => 'client_id123',
67
+ :oauth2_client_secret => 'client_secret123',
68
+ :developer_token => 'developer_token123',
69
+ :client_customer_id => '012-345-6789',
70
+ :user_agent => 'TestReportUtils'
71
+ },
72
+ :service => {
73
+ :environment => 'PRODUCTION'
74
+ }
75
+ })
64
76
  @report_utils = @api.report_utils(API_VERSION)
65
77
  end
66
78
 
@@ -2,18 +2,21 @@ def setup_mocks()
2
2
  $api_config = {
3
3
  :service => {:environment => 'PRODUCTION'},
4
4
  :authentication => {
5
- :method => 'ClientLogin',
6
- :email => 'noreply@google.com',
7
- :password => 'noreply_password',
5
+ :method => 'OAuth2',
6
+ :oauth2_client_id => 'client_id123',
7
+ :oauth2_client_secret => 'client_secret123',
8
8
  :developer_token => 'dev_token123',
9
9
  :client_customer_id => '123-456-7890',
10
- :user_agent => 'ruby-tests'
10
+ :user_agent => 'ruby-tests',
11
+ :oauth2_token => {
12
+ :refresh_token => 'refresh_token123'
13
+ }
11
14
  }
12
15
  }
13
16
 
14
- stub_request(:post, "https://www.google.com/accounts/ClientLogin").
15
- with(:body => {"Email"=>"noreply@google.com", "Passwd"=>"noreply_password", "accountType"=>"GOOGLE", "service"=>"adwords"}).
16
- to_return(:status => 200, :body => "SID=abcSIDbcd\nLSID=abcLSIDbcd\nAuth=abcAuthbcd\n", :headers => {})
17
+ stub_request(:post, "https://accounts.google.com/o/oauth2/auth").
18
+ with(:body => {"client_id"=>"client_id123", "client_secret"=>"client_secret123", "refresh_token"=>"refresh_token123", "grant_type"=>"refresh_token"}).
19
+ to_return(:status => 200, :body => '{"access_token":"access_token123","token_type":"Bearer","expires_in":"3600"}\n', :headers => {})
17
20
 
18
21
  stub_request(:post, "https://adwords.google.com/api/adwords/cm/v201409/CampaignService").
19
22
  with(
@@ -25,7 +28,6 @@ def setup_mocks()
25
28
  {"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)",
26
29
  "developerToken"=>"dev_token123",
27
30
  "clientCustomerId"=>"123-456-7890",
28
- "authToken"=>"abcAuthbcd",
29
31
  "xmlns"=>"https://adwords.google.com/api/adwords/cm/v201409"}},
30
32
  "env:Body"=>
31
33
  {"get"=>
@@ -2,18 +2,21 @@ def setup_mocks()
2
2
  $api_config = {
3
3
  :service => {:environment => 'PRODUCTION'},
4
4
  :authentication => {
5
- :method => 'ClientLogin',
6
- :email => 'noreply@google.com',
7
- :password => 'noreply_password',
5
+ :method => 'OAuth2',
6
+ :oauth2_client_id => 'client_id123',
7
+ :oauth2_client_secret => 'client_secret123',
8
8
  :developer_token => 'dev_token123',
9
9
  :client_customer_id => '123-456-7890',
10
- :user_agent => 'ruby-tests'
10
+ :user_agent => 'ruby-tests',
11
+ :oauth2_token => {
12
+ :refresh_token => 'refresh_token123'
13
+ }
11
14
  }
12
15
  }
13
16
 
14
- stub_request(:post, "https://www.google.com/accounts/ClientLogin").
15
- with(:body => {"Email"=>"noreply@google.com", "Passwd"=>"noreply_password", "accountType"=>"GOOGLE", "service"=>"adwords"}).
16
- to_return(:status => 200, :body => "SID=abcSIDbcd\nLSID=abcLSIDbcd\nAuth=abcAuthbcd\n", :headers => {})
17
+ stub_request(:post, "https://accounts.google.com/o/oauth2/auth").
18
+ with(:body => {"client_id"=>"client_id123", "client_secret"=>"client_secret123", "refresh_token"=>"refresh_token123", "grant_type"=>"refresh_token"}).
19
+ to_return(:status => 200, :body => '{"access_token":"access_token123","token_type":"Bearer","expires_in":"3600"}\n', :headers => {})
17
20
 
18
21
  stub_request(:post, "https://adwords.google.com/api/adwords/cm/v201502/CampaignService").
19
22
  with(
@@ -25,7 +28,6 @@ def setup_mocks()
25
28
  {"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)",
26
29
  "developerToken"=>"dev_token123",
27
30
  "clientCustomerId"=>"123-456-7890",
28
- "authToken"=>"abcAuthbcd",
29
31
  "xmlns"=>"https://adwords.google.com/api/adwords/cm/v201502"}},
30
32
  "env:Body"=>
31
33
  {"get"=>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-adwords-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danial Klimkin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-27 00:00:00.000000000 Z
12
+ date: 2015-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-ads-common
@@ -75,10 +75,8 @@ files:
75
75
  - examples/v201409/campaign_management/set_ad_parameters.rb
76
76
  - examples/v201409/campaign_management/set_criterion_bid_modifier.rb
77
77
  - examples/v201409/campaign_management/validate_text_ad.rb
78
- - examples/v201409/error_handling/handle_captcha_challenge.rb
79
78
  - examples/v201409/error_handling/handle_partial_failures.rb
80
79
  - examples/v201409/error_handling/handle_policy_violation_error.rb
81
- - examples/v201409/error_handling/handle_two_factor_authorization_error.rb
82
80
  - examples/v201409/extensions/add_google_my_business_location_extensions.rb
83
81
  - examples/v201409/extensions/add_site_links.rb
84
82
  - examples/v201409/extensions/add_site_links_using_feeds.rb
@@ -147,10 +145,8 @@ files:
147
145
  - examples/v201502/campaign_management/set_ad_parameters.rb
148
146
  - examples/v201502/campaign_management/set_criterion_bid_modifier.rb
149
147
  - examples/v201502/campaign_management/validate_text_ad.rb
150
- - examples/v201502/error_handling/handle_captcha_challenge.rb
151
148
  - examples/v201502/error_handling/handle_partial_failures.rb
152
149
  - examples/v201502/error_handling/handle_policy_violation_error.rb
153
- - examples/v201502/error_handling/handle_two_factor_authorization_error.rb
154
150
  - examples/v201502/extensions/add_google_my_business_location_extensions.rb
155
151
  - examples/v201502/extensions/add_site_links.rb
156
152
  - examples/v201502/extensions/add_site_links_using_feeds.rb
@@ -1,93 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
- #
6
- # Copyright:: Copyright 2012, Google Inc. All Rights Reserved.
7
- #
8
- # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
- # implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
- # This example illustrates how to handle 'CAPTCHA required' authorization
22
- # errors. Refer to the best practices guide on how to avoid this error:
23
- #
24
- # http://code.google.com/apis/adwords/docs/guides/bestpractices.html#auth_tokens
25
-
26
- require 'adwords_api'
27
-
28
- def handle_captcha_challenge()
29
- # Initialize token variable.
30
- logintoken = nil
31
-
32
- # This code will repeatedly request authToken from the server until it gets
33
- # a CAPTCHA challenge request. It is here for illustration purposes only
34
- # and should never be used in a real application.
35
- begin
36
- MAX_RETRIES.times do |retry_number|
37
- puts "Running request %d of %d..." % [retry_number + 1, MAX_RETRIES]
38
- # Forcing library to request a new authorization token.
39
- adwords = AdwordsApi::Api.new
40
- auth_token = adwords.authorize()
41
- end
42
- # Still no challenge, make sure ClientLogin authorization is used.
43
- raise StandardError, "Failed to get challenge after %d requests." %
44
- MAX_RETRIES
45
- rescue AdsCommon::Errors::CaptchaRequiredError => e
46
- logintoken = e.captcha_token
47
- end
48
-
49
- puts "CaptchaRequiredError occurred. To recover download the image and type" +
50
- " the CAPTCHA below: %s\n" % e.captcha_url
51
- puts 'Enter code or ENTER to retry: '
52
- logincaptcha = gets.chomp
53
-
54
- # Initialize variable for extra parameters.
55
- credentials = {}
56
- if logincaptcha and !logincaptcha.empty?
57
- credentials[:logincaptcha] = logincaptcha
58
- credentials[:logintoken] = logintoken
59
- end
60
-
61
- begin
62
- adwords = AdwordsApi::Api.new
63
- auth_token = adwords.authorize(credentials)
64
- puts "Successfully retrieved authToken: " + auth_token
65
- rescue AdsCommon::Errors::CaptchaRequiredError => e
66
- puts 'Invalid CAPTCHA text entered.'
67
- raise e
68
- end
69
- end
70
-
71
- if __FILE__ == $0
72
- API_VERSION = :v201409
73
- MAX_RETRIES = 500
74
-
75
- begin
76
- handle_captcha_challenge()
77
-
78
- # HTTP errors.
79
- rescue AdsCommon::Errors::HttpError => e
80
- puts "HTTP Error: %s" % e
81
-
82
- # API errors.
83
- rescue AdwordsApi::Errors::ApiException => e
84
- puts "Message: %s" % e.message
85
- puts 'Errors:'
86
- e.errors.each_with_index do |error, index|
87
- puts "\tError [%d]:" % (index + 1)
88
- error.each do |field, value|
89
- puts "\t\t%s: %s" % [field, value]
90
- end
91
- end
92
- end
93
- end
@@ -1,88 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
- #
6
- # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
7
- #
8
- # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
- # implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
- # This example illustrates how to handle 'two factor' authorization error.
22
-
23
- require 'adwords_api'
24
-
25
- def handle_two_factor_authorization_error()
26
- # Set up credentials with an account that has 2Factor enabled.
27
- config = {
28
- :authentication => {
29
- :method => 'ClientLogin',
30
- :email => '2steptester@gmail.com',
31
- :password => 'testaccount',
32
- :user_agent => 'Ruby 2 Factor Sample',
33
- :developer_token => 'qwerty'
34
- },
35
- :service => {
36
- :environment => 'PRODUCTION'
37
- }
38
- }
39
- adwords = AdwordsApi::Api.new(config)
40
-
41
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
42
- # the configuration file or provide your own logger:
43
- # adwords.logger = Logger.new('adwords_xml.log')
44
-
45
- begin
46
- # Forcing library to request authorization token.
47
- auth_token = adwords.authorize()
48
- puts 'Successfully retrieved the token.'
49
-
50
- # Second factor error is one of AuthErrors.
51
- rescue AdsCommon::Errors::AuthError => e
52
- puts "Authorization failed with message:"
53
- puts "\t%s" % e.message
54
- # Checking 'Info' field for particular auth error type.
55
- if e.info and e.info.casecmp('InvalidSecondFactor') == 0
56
- puts "The user has enabled two factor authentication in this account." +
57
- " Please use OAuth authentication method or have the user generate an" +
58
- " application-specific password to make calls against the AdWords" +
59
- " API. See \n" +
60
- " http://adwordsapi.blogspot.com/2011/02/authentication-changes-with" +
61
- "-2-step.html\n" +
62
- "for more details."
63
- end
64
- end
65
- end
66
-
67
- if __FILE__ == $0
68
- API_VERSION = :v201409
69
-
70
- begin
71
- handle_two_factor_authorization_error()
72
-
73
- # HTTP errors.
74
- rescue AdsCommon::Errors::HttpError => e
75
- puts "HTTP Error: %s" % e
76
-
77
- # API errors.
78
- rescue AdwordsApi::Errors::ApiException => e
79
- puts "Message: %s" % e.message
80
- puts 'Errors:'
81
- e.errors.each_with_index do |error, index|
82
- puts "\tError [%d]:" % (index + 1)
83
- error.each do |field, value|
84
- puts "\t\t%s: %s" % [field, value]
85
- end
86
- end
87
- end
88
- end
@@ -1,93 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
- #
6
- # Copyright:: Copyright 2012, Google Inc. All Rights Reserved.
7
- #
8
- # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
- # implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
- # This example illustrates how to handle 'CAPTCHA required' authorization
22
- # errors. Refer to the best practices guide on how to avoid this error:
23
- #
24
- # http://code.google.com/apis/adwords/docs/guides/bestpractices.html#auth_tokens
25
-
26
- require 'adwords_api'
27
-
28
- def handle_captcha_challenge()
29
- # Initialize token variable.
30
- logintoken = nil
31
-
32
- # This code will repeatedly request authToken from the server until it gets
33
- # a CAPTCHA challenge request. It is here for illustration purposes only
34
- # and should never be used in a real application.
35
- begin
36
- MAX_RETRIES.times do |retry_number|
37
- puts "Running request %d of %d..." % [retry_number + 1, MAX_RETRIES]
38
- # Forcing library to request a new authorization token.
39
- adwords = AdwordsApi::Api.new
40
- auth_token = adwords.authorize()
41
- end
42
- # Still no challenge, make sure ClientLogin authorization is used.
43
- raise StandardError, "Failed to get challenge after %d requests." %
44
- MAX_RETRIES
45
- rescue AdsCommon::Errors::CaptchaRequiredError => e
46
- logintoken = e.captcha_token
47
- end
48
-
49
- puts "CaptchaRequiredError occurred. To recover download the image and type" +
50
- " the CAPTCHA below: %s\n" % e.captcha_url
51
- puts 'Enter code or ENTER to retry: '
52
- logincaptcha = gets.chomp
53
-
54
- # Initialize variable for extra parameters.
55
- credentials = {}
56
- if logincaptcha and !logincaptcha.empty?
57
- credentials[:logincaptcha] = logincaptcha
58
- credentials[:logintoken] = logintoken
59
- end
60
-
61
- begin
62
- adwords = AdwordsApi::Api.new
63
- auth_token = adwords.authorize(credentials)
64
- puts "Successfully retrieved authToken: " + auth_token
65
- rescue AdsCommon::Errors::CaptchaRequiredError => e
66
- puts 'Invalid CAPTCHA text entered.'
67
- raise e
68
- end
69
- end
70
-
71
- if __FILE__ == $0
72
- API_VERSION = :v201502
73
- MAX_RETRIES = 500
74
-
75
- begin
76
- handle_captcha_challenge()
77
-
78
- # HTTP errors.
79
- rescue AdsCommon::Errors::HttpError => e
80
- puts "HTTP Error: %s" % e
81
-
82
- # API errors.
83
- rescue AdwordsApi::Errors::ApiException => e
84
- puts "Message: %s" % e.message
85
- puts 'Errors:'
86
- e.errors.each_with_index do |error, index|
87
- puts "\tError [%d]:" % (index + 1)
88
- error.each do |field, value|
89
- puts "\t\t%s: %s" % [field, value]
90
- end
91
- end
92
- end
93
- end
@@ -1,88 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
- #
6
- # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
7
- #
8
- # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
- # implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
- # This example illustrates how to handle 'two factor' authorization error.
22
-
23
- require 'adwords_api'
24
-
25
- def handle_two_factor_authorization_error()
26
- # Set up credentials with an account that has 2Factor enabled.
27
- config = {
28
- :authentication => {
29
- :method => 'ClientLogin',
30
- :email => '2steptester@gmail.com',
31
- :password => 'testaccount',
32
- :user_agent => 'Ruby 2 Factor Sample',
33
- :developer_token => 'qwerty'
34
- },
35
- :service => {
36
- :environment => 'PRODUCTION'
37
- }
38
- }
39
- adwords = AdwordsApi::Api.new(config)
40
-
41
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
42
- # the configuration file or provide your own logger:
43
- # adwords.logger = Logger.new('adwords_xml.log')
44
-
45
- begin
46
- # Forcing library to request authorization token.
47
- auth_token = adwords.authorize()
48
- puts 'Successfully retrieved the token.'
49
-
50
- # Second factor error is one of AuthErrors.
51
- rescue AdsCommon::Errors::AuthError => e
52
- puts "Authorization failed with message:"
53
- puts "\t%s" % e.message
54
- # Checking 'Info' field for particular auth error type.
55
- if e.info and e.info.casecmp('InvalidSecondFactor') == 0
56
- puts "The user has enabled two factor authentication in this account." +
57
- " Please use OAuth authentication method or have the user generate an" +
58
- " application-specific password to make calls against the AdWords" +
59
- " API. See \n" +
60
- " http://adwordsapi.blogspot.com/2011/02/authentication-changes-with" +
61
- "-2-step.html\n" +
62
- "for more details."
63
- end
64
- end
65
- end
66
-
67
- if __FILE__ == $0
68
- API_VERSION = :v201502
69
-
70
- begin
71
- handle_two_factor_authorization_error()
72
-
73
- # HTTP errors.
74
- rescue AdsCommon::Errors::HttpError => e
75
- puts "HTTP Error: %s" % e
76
-
77
- # API errors.
78
- rescue AdwordsApi::Errors::ApiException => e
79
- puts "Message: %s" % e.message
80
- puts 'Errors:'
81
- e.errors.each_with_index do |error, index|
82
- puts "\tError [%d]:" % (index + 1)
83
- error.each do |field, value|
84
- puts "\t\t%s: %s" % [field, value]
85
- end
86
- end
87
- end
88
- end