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.
- data/ChangeLog +8 -0
- data/README +22 -20
- data/adwords_api.yml +40 -0
- data/examples/v201109/account_management/create_account.rb +0 -1
- data/examples/v201109/account_management/get_account_alerts.rb +0 -1
- data/examples/v201109/account_management/get_account_changes.rb +0 -1
- data/examples/v201109/account_management/get_account_hierarchy.rb +0 -1
- data/examples/v201109/account_management/get_client_customer_id.rb +0 -1
- data/examples/v201109/account_management/get_client_unit_usage.rb +0 -1
- data/examples/v201109/basic_operations/add_ad_group.rb +0 -1
- data/examples/v201109/basic_operations/add_campaign.rb +0 -1
- data/examples/v201109/basic_operations/add_keywords.rb +0 -1
- data/examples/v201109/basic_operations/add_text_ads.rb +0 -1
- data/examples/v201109/basic_operations/delete_ad.rb +0 -1
- data/examples/v201109/basic_operations/delete_ad_group.rb +0 -1
- data/examples/v201109/basic_operations/delete_campaign.rb +0 -1
- data/examples/v201109/basic_operations/delete_keyword.rb +0 -1
- data/examples/v201109/basic_operations/get_ad_groups.rb +0 -1
- data/examples/v201109/basic_operations/get_campaigns.rb +0 -1
- data/examples/v201109/basic_operations/get_keywords.rb +0 -1
- data/examples/v201109/basic_operations/get_text_ads.rb +0 -1
- data/examples/v201109/basic_operations/pause_ad.rb +0 -1
- data/examples/v201109/basic_operations/update_ad_group.rb +0 -1
- data/examples/v201109/basic_operations/update_campaign.rb +0 -1
- data/examples/v201109/basic_operations/update_keyword.rb +0 -1
- data/examples/v201109/campaign_management/add_experiment.rb +0 -1
- data/examples/v201109/campaign_management/add_keywords_in_bulk.rb +0 -1
- data/examples/v201109/campaign_management/add_location_extension.rb +0 -1
- data/examples/v201109/campaign_management/add_location_extension_override.rb +0 -1
- data/examples/v201109/campaign_management/get_all_disapproved_ads.rb +0 -1
- data/examples/v201109/campaign_management/promote_experiment.rb +0 -1
- data/examples/v201109/campaign_management/set_ad_parameters.rb +0 -1
- data/examples/v201109/campaign_management/validate_text_ad.rb +0 -1
- data/examples/v201109/error_handling/handle_captcha_challenge.rb +94 -0
- data/examples/v201109/error_handling/handle_partial_failures.rb +0 -1
- data/examples/v201109/error_handling/handle_policy_violation_error.rb +0 -1
- data/examples/v201109/error_handling/handle_two_factor_authorization_error.rb +0 -1
- data/examples/v201109/misc/get_all_images_and_videos.rb +0 -1
- data/examples/v201109/misc/upload_image.rb +0 -1
- data/examples/v201109/misc/use_oauth.rb +0 -1
- data/examples/v201109/optimization/estimate_keyword_traffic.rb +0 -1
- data/examples/v201109/optimization/get_keyword_bid_simulations.rb +0 -1
- data/examples/v201109/optimization/get_keyword_ideas.rb +0 -1
- data/examples/v201109/optimization/get_placement_ideas.rb +0 -1
- data/examples/v201109/remarketing/add_audience.rb +0 -1
- data/examples/v201109/remarketing/add_conversion_tracker.rb +0 -1
- data/examples/v201109/reporting/download_criteria_report.rb +0 -1
- data/examples/v201109/reporting/download_defined_report.rb +0 -1
- data/examples/v201109/reporting/get_defined_reports.rb +0 -1
- data/examples/v201109/reporting/get_report_fields.rb +0 -1
- data/examples/v201109/reporting/parallel_report_download.rb +0 -1
- data/examples/v201109/targeting/add_campaign_targeting_criteria.rb +0 -1
- data/examples/v201109/targeting/get_campaign_targeting_criteria.rb +0 -1
- data/examples/v201109/targeting/get_targetable_languages_and_carriers.rb +0 -1
- data/examples/v201109/targeting/lookup_location.rb +0 -1
- data/lib/adwords_api.rb +1 -1
- data/lib/adwords_api/api_config.rb +36 -20
- data/lib/adwords_api/credential_handler.rb +5 -2
- data/lib/adwords_api/report_utils.rb +7 -5
- data/lib/adwords_api/v201109/ad_extension_override_service.rb +8 -10
- data/lib/adwords_api/v201109/ad_extension_override_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/ad_group_ad_service.rb +8 -10
- data/lib/adwords_api/v201109/ad_group_ad_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/ad_group_criterion_service.rb +8 -10
- data/lib/adwords_api/v201109/ad_group_criterion_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/ad_group_service.rb +8 -10
- data/lib/adwords_api/v201109/ad_group_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/ad_param_service.rb +8 -10
- data/lib/adwords_api/v201109/ad_param_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/alert_service.rb +4 -6
- data/lib/adwords_api/v201109/alert_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/bulk_mutate_job_service.rb +8 -10
- data/lib/adwords_api/v201109/bulk_mutate_job_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/campaign_ad_extension_service.rb +8 -10
- data/lib/adwords_api/v201109/campaign_ad_extension_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/campaign_criterion_service.rb +8 -10
- data/lib/adwords_api/v201109/campaign_criterion_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/campaign_service.rb +8 -10
- data/lib/adwords_api/v201109/campaign_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/campaign_target_service.rb +8 -10
- data/lib/adwords_api/v201109/campaign_target_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/constant_data_service.rb +4 -6
- data/lib/adwords_api/v201109/constant_data_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/conversion_tracker_service.rb +8 -10
- data/lib/adwords_api/v201109/conversion_tracker_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/create_account_service.rb +4 -6
- data/lib/adwords_api/v201109/create_account_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/customer_sync_service.rb +4 -6
- data/lib/adwords_api/v201109/customer_sync_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/data_service.rb +8 -10
- data/lib/adwords_api/v201109/data_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/experiment_service.rb +8 -10
- data/lib/adwords_api/v201109/experiment_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/geo_location_service.rb +4 -6
- data/lib/adwords_api/v201109/geo_location_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/info_service.rb +4 -6
- data/lib/adwords_api/v201109/info_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/location_criterion_service.rb +4 -6
- data/lib/adwords_api/v201109/location_criterion_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/media_service.rb +8 -10
- data/lib/adwords_api/v201109/media_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/mutate_job_service.rb +8 -10
- data/lib/adwords_api/v201109/mutate_job_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/report_definition_service.rb +8 -10
- data/lib/adwords_api/v201109/report_definition_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/serviced_account_service.rb +4 -6
- data/lib/adwords_api/v201109/serviced_account_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/targeting_idea_service.rb +8 -10
- data/lib/adwords_api/v201109/targeting_idea_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/traffic_estimator_service.rb +4 -6
- data/lib/adwords_api/v201109/traffic_estimator_service_registry.rb +6 -8
- data/lib/adwords_api/v201109/user_list_service.rb +8 -10
- data/lib/adwords_api/v201109/user_list_service_registry.rb +6 -8
- data/lib/adwords_api/version.rb +26 -0
- data/test/adwords_api/test_api_config.rb +2 -2
- data/test/adwords_api/test_report_utils.rb +1 -1
- data/test/adwords_api/test_utils.rb +1 -1
- data/test/bugs/test_issue_00000031.rb +0 -1
- data/test/suite_unittests.rb +32 -0
- metadata +130 -132
- data/Rakefile +0 -92
- data/examples/v201109/optimization/get_keyword_opportunities.rb +0 -96
- data/lib/adwords_api/v201109/bulk_opportunity_service.rb +0 -34
- 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.
|
31
|
+
- google-ads-common v0.6.3 or later.
|
32
32
|
|
33
33
|
|
34
34
|
== 2 - Using the client library:
|
35
35
|
|
36
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
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
|
-
$
|
179
|
-
to
|
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
|
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
|
@@ -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
|