google-adwords-api 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/ChangeLog +8 -0
  2. data/README +22 -20
  3. data/adwords_api.yml +40 -0
  4. data/examples/v201109/account_management/create_account.rb +0 -1
  5. data/examples/v201109/account_management/get_account_alerts.rb +0 -1
  6. data/examples/v201109/account_management/get_account_changes.rb +0 -1
  7. data/examples/v201109/account_management/get_account_hierarchy.rb +0 -1
  8. data/examples/v201109/account_management/get_client_customer_id.rb +0 -1
  9. data/examples/v201109/account_management/get_client_unit_usage.rb +0 -1
  10. data/examples/v201109/basic_operations/add_ad_group.rb +0 -1
  11. data/examples/v201109/basic_operations/add_campaign.rb +0 -1
  12. data/examples/v201109/basic_operations/add_keywords.rb +0 -1
  13. data/examples/v201109/basic_operations/add_text_ads.rb +0 -1
  14. data/examples/v201109/basic_operations/delete_ad.rb +0 -1
  15. data/examples/v201109/basic_operations/delete_ad_group.rb +0 -1
  16. data/examples/v201109/basic_operations/delete_campaign.rb +0 -1
  17. data/examples/v201109/basic_operations/delete_keyword.rb +0 -1
  18. data/examples/v201109/basic_operations/get_ad_groups.rb +0 -1
  19. data/examples/v201109/basic_operations/get_campaigns.rb +0 -1
  20. data/examples/v201109/basic_operations/get_keywords.rb +0 -1
  21. data/examples/v201109/basic_operations/get_text_ads.rb +0 -1
  22. data/examples/v201109/basic_operations/pause_ad.rb +0 -1
  23. data/examples/v201109/basic_operations/update_ad_group.rb +0 -1
  24. data/examples/v201109/basic_operations/update_campaign.rb +0 -1
  25. data/examples/v201109/basic_operations/update_keyword.rb +0 -1
  26. data/examples/v201109/campaign_management/add_experiment.rb +0 -1
  27. data/examples/v201109/campaign_management/add_keywords_in_bulk.rb +0 -1
  28. data/examples/v201109/campaign_management/add_location_extension.rb +0 -1
  29. data/examples/v201109/campaign_management/add_location_extension_override.rb +0 -1
  30. data/examples/v201109/campaign_management/get_all_disapproved_ads.rb +0 -1
  31. data/examples/v201109/campaign_management/promote_experiment.rb +0 -1
  32. data/examples/v201109/campaign_management/set_ad_parameters.rb +0 -1
  33. data/examples/v201109/campaign_management/validate_text_ad.rb +0 -1
  34. data/examples/v201109/error_handling/handle_captcha_challenge.rb +94 -0
  35. data/examples/v201109/error_handling/handle_partial_failures.rb +0 -1
  36. data/examples/v201109/error_handling/handle_policy_violation_error.rb +0 -1
  37. data/examples/v201109/error_handling/handle_two_factor_authorization_error.rb +0 -1
  38. data/examples/v201109/misc/get_all_images_and_videos.rb +0 -1
  39. data/examples/v201109/misc/upload_image.rb +0 -1
  40. data/examples/v201109/misc/use_oauth.rb +0 -1
  41. data/examples/v201109/optimization/estimate_keyword_traffic.rb +0 -1
  42. data/examples/v201109/optimization/get_keyword_bid_simulations.rb +0 -1
  43. data/examples/v201109/optimization/get_keyword_ideas.rb +0 -1
  44. data/examples/v201109/optimization/get_placement_ideas.rb +0 -1
  45. data/examples/v201109/remarketing/add_audience.rb +0 -1
  46. data/examples/v201109/remarketing/add_conversion_tracker.rb +0 -1
  47. data/examples/v201109/reporting/download_criteria_report.rb +0 -1
  48. data/examples/v201109/reporting/download_defined_report.rb +0 -1
  49. data/examples/v201109/reporting/get_defined_reports.rb +0 -1
  50. data/examples/v201109/reporting/get_report_fields.rb +0 -1
  51. data/examples/v201109/reporting/parallel_report_download.rb +0 -1
  52. data/examples/v201109/targeting/add_campaign_targeting_criteria.rb +0 -1
  53. data/examples/v201109/targeting/get_campaign_targeting_criteria.rb +0 -1
  54. data/examples/v201109/targeting/get_targetable_languages_and_carriers.rb +0 -1
  55. data/examples/v201109/targeting/lookup_location.rb +0 -1
  56. data/lib/adwords_api.rb +1 -1
  57. data/lib/adwords_api/api_config.rb +36 -20
  58. data/lib/adwords_api/credential_handler.rb +5 -2
  59. data/lib/adwords_api/report_utils.rb +7 -5
  60. data/lib/adwords_api/v201109/ad_extension_override_service.rb +8 -10
  61. data/lib/adwords_api/v201109/ad_extension_override_service_registry.rb +6 -8
  62. data/lib/adwords_api/v201109/ad_group_ad_service.rb +8 -10
  63. data/lib/adwords_api/v201109/ad_group_ad_service_registry.rb +6 -8
  64. data/lib/adwords_api/v201109/ad_group_criterion_service.rb +8 -10
  65. data/lib/adwords_api/v201109/ad_group_criterion_service_registry.rb +6 -8
  66. data/lib/adwords_api/v201109/ad_group_service.rb +8 -10
  67. data/lib/adwords_api/v201109/ad_group_service_registry.rb +6 -8
  68. data/lib/adwords_api/v201109/ad_param_service.rb +8 -10
  69. data/lib/adwords_api/v201109/ad_param_service_registry.rb +6 -8
  70. data/lib/adwords_api/v201109/alert_service.rb +4 -6
  71. data/lib/adwords_api/v201109/alert_service_registry.rb +6 -8
  72. data/lib/adwords_api/v201109/bulk_mutate_job_service.rb +8 -10
  73. data/lib/adwords_api/v201109/bulk_mutate_job_service_registry.rb +6 -8
  74. data/lib/adwords_api/v201109/campaign_ad_extension_service.rb +8 -10
  75. data/lib/adwords_api/v201109/campaign_ad_extension_service_registry.rb +6 -8
  76. data/lib/adwords_api/v201109/campaign_criterion_service.rb +8 -10
  77. data/lib/adwords_api/v201109/campaign_criterion_service_registry.rb +6 -8
  78. data/lib/adwords_api/v201109/campaign_service.rb +8 -10
  79. data/lib/adwords_api/v201109/campaign_service_registry.rb +6 -8
  80. data/lib/adwords_api/v201109/campaign_target_service.rb +8 -10
  81. data/lib/adwords_api/v201109/campaign_target_service_registry.rb +6 -8
  82. data/lib/adwords_api/v201109/constant_data_service.rb +4 -6
  83. data/lib/adwords_api/v201109/constant_data_service_registry.rb +6 -8
  84. data/lib/adwords_api/v201109/conversion_tracker_service.rb +8 -10
  85. data/lib/adwords_api/v201109/conversion_tracker_service_registry.rb +6 -8
  86. data/lib/adwords_api/v201109/create_account_service.rb +4 -6
  87. data/lib/adwords_api/v201109/create_account_service_registry.rb +6 -8
  88. data/lib/adwords_api/v201109/customer_sync_service.rb +4 -6
  89. data/lib/adwords_api/v201109/customer_sync_service_registry.rb +6 -8
  90. data/lib/adwords_api/v201109/data_service.rb +8 -10
  91. data/lib/adwords_api/v201109/data_service_registry.rb +6 -8
  92. data/lib/adwords_api/v201109/experiment_service.rb +8 -10
  93. data/lib/adwords_api/v201109/experiment_service_registry.rb +6 -8
  94. data/lib/adwords_api/v201109/geo_location_service.rb +4 -6
  95. data/lib/adwords_api/v201109/geo_location_service_registry.rb +6 -8
  96. data/lib/adwords_api/v201109/info_service.rb +4 -6
  97. data/lib/adwords_api/v201109/info_service_registry.rb +6 -8
  98. data/lib/adwords_api/v201109/location_criterion_service.rb +4 -6
  99. data/lib/adwords_api/v201109/location_criterion_service_registry.rb +6 -8
  100. data/lib/adwords_api/v201109/media_service.rb +8 -10
  101. data/lib/adwords_api/v201109/media_service_registry.rb +6 -8
  102. data/lib/adwords_api/v201109/mutate_job_service.rb +8 -10
  103. data/lib/adwords_api/v201109/mutate_job_service_registry.rb +6 -8
  104. data/lib/adwords_api/v201109/report_definition_service.rb +8 -10
  105. data/lib/adwords_api/v201109/report_definition_service_registry.rb +6 -8
  106. data/lib/adwords_api/v201109/serviced_account_service.rb +4 -6
  107. data/lib/adwords_api/v201109/serviced_account_service_registry.rb +6 -8
  108. data/lib/adwords_api/v201109/targeting_idea_service.rb +8 -10
  109. data/lib/adwords_api/v201109/targeting_idea_service_registry.rb +6 -8
  110. data/lib/adwords_api/v201109/traffic_estimator_service.rb +4 -6
  111. data/lib/adwords_api/v201109/traffic_estimator_service_registry.rb +6 -8
  112. data/lib/adwords_api/v201109/user_list_service.rb +8 -10
  113. data/lib/adwords_api/v201109/user_list_service_registry.rb +6 -8
  114. data/lib/adwords_api/version.rb +26 -0
  115. data/test/adwords_api/test_api_config.rb +2 -2
  116. data/test/adwords_api/test_report_utils.rb +1 -1
  117. data/test/adwords_api/test_utils.rb +1 -1
  118. data/test/bugs/test_issue_00000031.rb +0 -1
  119. data/test/suite_unittests.rb +32 -0
  120. metadata +130 -132
  121. data/Rakefile +0 -92
  122. data/examples/v201109/optimization/get_keyword_opportunities.rb +0 -96
  123. data/lib/adwords_api/v201109/bulk_opportunity_service.rb +0 -34
  124. data/lib/adwords_api/v201109/bulk_opportunity_service_registry.rb +0 -46
data/ChangeLog CHANGED
@@ -1,3 +1,11 @@
1
+ 0.5.1:
2
+ - Require google-ads-common 0.6.3 or later from now on.
3
+ - Support for CAPTCHA challenge handling.
4
+ - Added .gemspec and updated packaging process.
5
+ - Removed explicit require for RubyGems, see README.
6
+ - Fixed reports retrieval via curb HTTPI backend.
7
+ - Removed support for deprecated BulkOpportunityService.
8
+
1
9
  0.5.0:
2
10
  - Removed deprecated API versions (pre-v201109).
3
11
  - Example updates and revamp.
data/README CHANGED
@@ -28,30 +28,21 @@ which is installed automatically as a dependency.
28
28
 
29
29
  The following gem libraries are required:
30
30
  - savon v0.9.7
31
- - google-ads-common v0.6.1 or later.
31
+ - google-ads-common v0.6.3 or later.
32
32
 
33
33
 
34
34
  == 2 - Using the client library:
35
35
 
36
- It's pretty easy to use.
37
- See http://docs.rubygems.org/read/chapter/3#page70 for how to set the rubygem
38
- environment.
39
- $ export RUBYOPT=rubygems
40
- or
41
- $ ruby -rubygems my_program_that_uses_gems
42
-
43
- If you are running Ruby 1.8 and do not use the rubygems option, you need to add
44
- require 'rubygems'
45
- at the beginning of your programs.
46
-
47
- Then:
48
- gem 'google-adwords-api'
36
+ Include the library with 'require':
49
37
  require 'adwords_api'
50
38
 
39
+ Then create an API instance:
51
40
  adwords = AdwordsApi::Api.new
52
- creates an Api object that will grant you access to all the services for all of
53
- the currently supported vesions of the APIs. It uses a config file in:
54
- ENV['HOME']/adwords_api.yml to read all of your configurations.
41
+
42
+ The created API object will grant you access to all the services for all of the
43
+ currently supported vesions of the APIs. It uses a config file in:
44
+ ENV['HOME']/adwords_api.yml to read all of your configurations by default.
45
+
55
46
  There is an example configuration file shipped with these libraries.
56
47
 
57
48
  You can also pass API a manually constructed config hash like:
@@ -85,6 +76,17 @@ please set the appropriate options in the config file or config hash. E.g.:
85
76
  :proxy => 'http://user:password@proxy_hostname:8080'
86
77
  }
87
78
 
79
+ *Note*: if you are using Ruby 1.8 you may need to include RubyGems to be able
80
+ to require other gems code. There are several ways to do it, the easiest one is
81
+ to pass '-rubygems' parameter to the ruby interpreter:
82
+ $ ruby -rubygems my_program_that_uses_gems
83
+
84
+ you can also set this up in the environment:
85
+ $ export RUBYOPT="rubygems"
86
+
87
+ or add it to the bash configuration file:
88
+ $ echo 'export RUBYOPT="rubygems"' >> ~/.bashrc
89
+
88
90
 
89
91
  === 2.1 - Ruby names for a Ruby library:
90
92
 
@@ -175,8 +177,8 @@ respond in gzipped format. All requests are sent uncompressed regardless.
175
177
  $ rake generate
176
178
  to regenerate the stubs if needed
177
179
 
178
- $ rake package
179
- to package the gem and create a release
180
+ $ gem build google-adwords-api.gemspec
181
+ to build the gem
180
182
 
181
183
  $ rake test
182
184
  to run unit tests on the library
@@ -197,7 +199,7 @@ Questions can be asked on forum
197
199
 
198
200
  == Licence
199
201
 
200
- Copyright 2011, Google Inc. All Rights Reserved.
202
+ Copyright 2010-2012, Google Inc. All Rights Reserved.
201
203
 
202
204
  Licensed under the Apache License, Version 2.0 (the "License");
203
205
  you may not use this file except in compliance with the License.
data/adwords_api.yml ADDED
@@ -0,0 +1,40 @@
1
+ ---
2
+ # This is an example configuration file for the AdWords API client library.
3
+ # Please fill in the required fields, and copy it over to your home directory.
4
+ :authentication:
5
+ # Authentication method, methods currently supported: OAuth, ClientLogin.
6
+ :method: ClientLogin
7
+
8
+ # Auth parameters for OAuth method.
9
+ # Set the OAuth consumer key and secret. Anonymous values can be used for
10
+ # testing, and real values can be obtained by registering your application:
11
+ # http://code.google.com/apis/accounts/docs/RegistrationForWebAppsAuto.html
12
+ #:oauth_consumer_key: anonymous
13
+ #:oauth_consumer_secret: anonymous
14
+ # If you manage or store access token manually, you can specify it here.
15
+ #:oauth_token: INSERT_OAUTH_TOKEN_HERE
16
+ # If you need to change signature method, specify it here.
17
+ #:oauth_signature_method: HMAC-SHA1
18
+ # Token secret for HMAC-SHA1 method.
19
+ #:oauth_token_secret: INSERT_OAUTH_TOKEN_SECRET_HERE
20
+
21
+ # Auth parameters for ClientLogin method.
22
+ :password: INSERT_YOUR_PASSWORD_HERE
23
+ :email: INSERT_YOUR_LOGIN_EMAIL_HERE
24
+ # To manage your auth tokens manually, use the 'auth_token' property.
25
+ #:auth_token: INSERT_AUTH_TOKEN_HERE
26
+
27
+ # Other parameters.
28
+ :developer_token: INSERT_YOUR_DEVELOPER_TOKEN_HERE
29
+ :client_customer_id: INSERT_YOUR_CLIENT_CUSTOMER_ID_HERE
30
+ :user_agent: INSERT_YOUR_USER_AGENT_HERE
31
+ :service:
32
+ :environment: SANDBOX
33
+ :connection:
34
+ # Enable to request all responses to be compressed.
35
+ :enable_gzip: false
36
+ # If your proxy connection requires authentication, make sure to include it in
37
+ # the URL, e.g.: http://user:password@proxy_hostname:8080
38
+ # :proxy: INSERT_PROXY_HERE
39
+ :library:
40
+ :log_level: INFO
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: CreateAccountService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
  require 'adwords_api/utils'
29
28
 
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AlertService.get
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
  require 'adwords_api/utils'
29
28
 
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: CustomerSyncService.get
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
  require 'date'
29
28
  require 'pp'
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: ServicedAccountService.get
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
  require 'adwords_api/utils'
29
28
 
@@ -24,7 +24,6 @@
24
24
  #
25
25
  # Tags: InfoService.get
26
26
 
27
- require 'rubygems'
28
27
  require 'adwords_api'
29
28
  require 'adwords_api/utils'
30
29
 
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: InfoService.get
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AdGroupService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -22,7 +22,6 @@
22
22
  #
23
23
  # Tags: CampaignService.mutate
24
24
 
25
- require 'rubygems'
26
25
  require 'adwords_api'
27
26
 
28
27
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AdGroupCriterionService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AdGroupAdService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AdGroupAdService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AdGroupService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: CampaignService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AdGroupCriterionService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AdGroupService.get
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -22,7 +22,6 @@
22
22
  #
23
23
  # Tags: CampaignService.get
24
24
 
25
- require 'rubygems'
26
25
  require 'adwords_api'
27
26
 
28
27
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AdGroupCriterionService.get
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AdGroupAdService.get
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AdGroupAdService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AdGroupService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: CampaignService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AdGroupCriterionService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -26,7 +26,6 @@
26
26
  #
27
27
  # Tags: ExperimentService.mutate
28
28
 
29
- require 'rubygems'
30
29
  require 'adwords_api'
31
30
 
32
31
  API_VERSION = :v201109
@@ -24,7 +24,6 @@
24
24
  # Tags: MutateJobService.mutate, MutateJobService.get,
25
25
  # MutateJobService.getResult
26
26
 
27
- require 'rubygems'
28
27
  require 'adwords_api'
29
28
 
30
29
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: GeoLocationService.get, CampaignAdExtensionService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -24,7 +24,6 @@
24
24
  #
25
25
  # Tags: AdExtensionOverrideService.mutate
26
26
 
27
- require 'rubygems'
28
27
  require 'adwords_api'
29
28
 
30
29
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AdGroupAdService.get
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: ExperimentService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: AdGroupAdService.mutate, AdParamService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -23,7 +23,6 @@
23
23
  #
24
24
  # Tags: CampaignService.mutate
25
25
 
26
- require 'rubygems'
27
26
  require 'adwords_api'
28
27
 
29
28
  API_VERSION = :v201109
@@ -0,0 +1,94 @@
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
+ API_VERSION = :v201109
29
+
30
+ MAX_RETRIES = 500
31
+
32
+ def handle_captcha_challenge()
33
+ # Initialize token variable.
34
+ logintoken = nil
35
+
36
+ # This code will repeatedly request authToken from the server until it gets
37
+ # a CAPTCHA challenge request. It is here for illustration purposes only
38
+ # and should never be used in a real application.
39
+ begin
40
+ MAX_RETRIES.times do |retry_number|
41
+ puts "Running request %d of %d..." % [retry_number + 1, MAX_RETRIES]
42
+ # Forcing library to request a new authorization token.
43
+ adwords = AdwordsApi::Api.new
44
+ auth_token = adwords.authorize()
45
+ end
46
+ # Still no challenge, make sure ClientLogin authorization is used.
47
+ raise StandardError, "Failed to get challenge after %d requests." %
48
+ MAX_RETRIES
49
+ rescue AdsCommon::Errors::CaptchaRequiredError => e
50
+ logintoken = e.captcha_token
51
+ end
52
+
53
+ puts "CaptchaRequiredError occurred. To recover download the image and type" +
54
+ " the CAPTCHA below: %s\n" % e.captcha_url
55
+ puts 'Enter code or ENTER to retry: '
56
+ logincaptcha = gets.chomp
57
+
58
+ # Initialize variable for extra parameters.
59
+ credentials = {}
60
+ if logincaptcha and !logincaptcha.empty?
61
+ credentials[:logincaptcha] = logincaptcha
62
+ credentials[:logintoken] = logintoken
63
+ end
64
+
65
+ begin
66
+ adwords = AdwordsApi::Api.new
67
+ auth_token = adwords.authorize(credentials)
68
+ puts "Successfully retrieved authToken: " + auth_token
69
+ rescue AdsCommon::Errors::CaptchaRequiredError => e
70
+ puts 'Invalid CAPTCHA text entered.'
71
+ raise e
72
+ end
73
+ end
74
+
75
+ if __FILE__ == $0
76
+ begin
77
+ handle_captcha_challenge()
78
+
79
+ # HTTP errors.
80
+ rescue AdsCommon::Errors::HttpError => e
81
+ puts "HTTP Error: %s" % e
82
+
83
+ # API errors.
84
+ rescue AdwordsApi::Errors::ApiException => e
85
+ puts "Message: %s" % e.message
86
+ puts 'Errors:'
87
+ e.errors.each_with_index do |error, index|
88
+ puts "\tError [%d]:" % (index + 1)
89
+ error.each do |field, value|
90
+ puts "\t\t%s: %s" % [field, value]
91
+ end
92
+ end
93
+ end
94
+ end