Skip to content

Commit 2da6d98

Browse files
committed
Adding v201406 support to AdWords library.
1 parent 97b7206 commit 2da6d98

157 files changed

Lines changed: 12135 additions & 35 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

adwords_api/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.12.1:
2+
- Support and examples for v201406.
3+
- Changed default OAuth scope. See:
4+
https://developers.google.com/adwords/api/docs/guides/authentication#scope
5+
16
0.12.0:
27
- Removed deprecated API version v201306.
38

adwords_api/README.md

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Install them using the gem install command:
2020
$ gem install --remote google-adwords-api
2121
$ gem install --remote google-adx-buyer-api
2222

23-
Please note the google-adx-buyer-api gem contains only DoubleClick Ad Exchange
24-
Buyer client library examples. You need the AdWords library in order to use it
25-
which is installed automatically as a dependency.
23+
Please note the `google-adx-buyer-api` gem contains only DoubleClick Ad
24+
Exchange Buyer client library examples. The gem also depends on the
25+
AdWords library, which will be installed automatically.
2626

2727
The following gem libraries are required:
2828

@@ -32,21 +32,15 @@ The following gem libraries are required:
3232

3333
## 2 - Using the client library
3434

35-
Include the library with 'require':
36-
37-
require 'adwords_api'
38-
39-
Then create an API instance:
40-
41-
adwords = AdwordsApi::Api.new
42-
43-
The created API object will grant you access to all the services for all of the
44-
currently supported vesions of the APIs. It uses a config file in
45-
`ENV['HOME']/adwords_api.yml` to read all of your configurations by default.
35+
Before starting to use the client library, you need to set up OAuth2. You can
36+
find our guide on how to obtain OAuth2 credentials
37+
[on the wiki](https://github.com/googleads/google-api-ads-ruby/wiki/OAuth2).
4638

47-
There is an example configuration file shipped with these libraries.
39+
By default, the API uses a config file in `ENV['HOME']/adwords_api.yml`. When
40+
generating your OAuth2 refresh token, you will be given the option for the
41+
sample to automatically store the refresh token in this file.
4842

49-
You can also pass API a manually constructed config hash like:
43+
You can also pass the API a manually constructed config hash like:
5044

5145
adwords = AdwordsApi::Api.new({
5246
:authentication => {
@@ -62,21 +56,33 @@ You can also pass API a manually constructed config hash like:
6256
}
6357
})
6458

65-
To obtain OAuth2 client credentials, follow the instructions
66-
[on the wiki](https://github.com/googleads/google-api-ads-ruby/wiki/OAuth2).
59+
Once you have all the requisite setup complete, you're ready to make an API
60+
call. The easiest way to do this is to look at one of our
61+
[examples](https://github.com/googleads/google-api-ads-ruby/tree/master/adwords_api/examples).
62+
The `adwords_on_rails` example will show how to use the web flow, and the other
63+
examples will use the installed application OAuth2 flow.
6764

68-
Once the library instance is created, specify which service you're looking to
69-
use, and which version:
65+
The basics of making a request are:
7066

71-
campaign_srv = adwords.service(:CampaignService, :v201309)
67+
1. Include the library with `require`:
7268

73-
You should now be able to just use the API methods in the object you were
74-
returned:
69+
require 'adwords_api'
7570

76-
# Get 'Id', 'Name' and 'Status' fields of all campaigns.
77-
campaigns = campaign_srv.get({:fields => ['Id', 'Name', 'Status']})
71+
2. Create an API instance:
7872

79-
See the code in the examples directory for working examples you can build from.
73+
adwords = AdwordsApi::Api.new
74+
75+
3. Specify which service you're looking to use, and which version:
76+
77+
campaign_srv = adwords.service(:CampaignService, :v201402)
78+
79+
4. You should now be able to just use the API methods in the returned object:
80+
81+
# Get 'Id', 'Name' and 'Status' fields of all campaigns.
82+
campaigns = campaign_srv.get({:fields => ['Id', 'Name', 'Status']})
83+
84+
See the code in the examples directory for more thorough working examples you
85+
can build from.
8086

8187
*Note*: If your setup requires you to send connections through a proxy server,
8288
please set the appropriate options in the config file or config hash.
@@ -266,3 +272,4 @@ Authors:
266272
Maintainer:
267273

268274
- api.mcloonan@gmail.com (Michael Cloonan)
275+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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 create an account. Note by default this
22+
# account will only be accessible via parent MCC.
23+
#
24+
# Tags: ManagedCustomerService.mutate
25+
26+
require 'adwords_api'
27+
require 'adwords_api/utils'
28+
29+
def create_account()
30+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
31+
# when called without parameters.
32+
adwords = AdwordsApi::Api.new
33+
34+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
35+
# the configuration file or provide your own logger:
36+
# adwords.logger = Logger.new('adwords_xml.log')
37+
38+
managed_customer_srv = adwords.service(:ManagedCustomerService, API_VERSION)
39+
40+
# Create a local Customer object.
41+
customer = {
42+
:name => 'Account created with ManagedCustomerService',
43+
:currency_code => 'EUR',
44+
:date_time_zone => 'Europe/London'
45+
}
46+
47+
# Prepare operation to create an account.
48+
operation = {
49+
:operator => 'ADD',
50+
:operand => customer
51+
}
52+
53+
# Create the account. It is possible to create multiple accounts with one
54+
# request by sending an array of operations.
55+
response = managed_customer_srv.mutate([operation])
56+
57+
response[:value].each do |new_account|
58+
puts "Account with customer ID '%s' was successfully created." %
59+
AdwordsApi::Utils.format_id(new_account[:customer_id])
60+
end
61+
end
62+
63+
if __FILE__ == $0
64+
API_VERSION = :v201406
65+
66+
begin
67+
create_account()
68+
69+
# Authorization error.
70+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
71+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
72+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
73+
"to retrieve and store OAuth2 tokens."
74+
puts "See this wiki page for more details:\n\n " +
75+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
76+
77+
# HTTP errors.
78+
rescue AdsCommon::Errors::HttpError => e
79+
puts "HTTP Error: %s" % e
80+
81+
# API errors.
82+
rescue AdwordsApi::Errors::ApiException => e
83+
puts "Message: %s" % e.message
84+
puts 'Errors:'
85+
e.errors.each_with_index do |error, index|
86+
puts "\tError [%d]:" % (index + 1)
87+
error.each do |field, value|
88+
puts "\t\t%s: %s" % [field, value]
89+
end
90+
end
91+
end
92+
end
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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 gets all alerts for all clients of an MCC account. The effective
22+
# user (clientCustomerId, or authToken) must be an MCC user to get results.
23+
#
24+
# Note: This code example uses MCC-level calls and won't work with Test
25+
# Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
26+
#
27+
# Tags: AlertService.get
28+
29+
require 'adwords_api'
30+
require 'adwords_api/utils'
31+
32+
def get_account_alerts()
33+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
34+
# when called without parameters.
35+
adwords = AdwordsApi::Api.new
36+
37+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
38+
# the configuration file or provide your own logger:
39+
# adwords.logger = Logger.new('adwords_xml.log')
40+
41+
alert_srv = adwords.service(:AlertService, API_VERSION)
42+
43+
# Create the selector.
44+
selector = {
45+
:query => {
46+
:filter_spec => 'ALL',
47+
:client_spec => 'ALL',
48+
:trigger_time_spec => 'ALL_TIME',
49+
:severities => ['GREEN', 'YELLOW', 'RED'],
50+
:types => [
51+
'ACCOUNT_BUDGET_BURN_RATE', 'ACCOUNT_BUDGET_ENDING',
52+
'ACCOUNT_ON_TARGET', 'CAMPAIGN_ENDED', 'CAMPAIGN_ENDING',
53+
'CREDIT_CARD_EXPIRING', 'DECLINED_PAYMENT', 'MANAGER_LINK_PENDING',
54+
'MISSING_BANK_REFERENCE_NUMBER', 'PAYMENT_NOT_ENTERED',
55+
'TV_ACCOUNT_BUDGET_ENDING', 'TV_ACCOUNT_ON_TARGET',
56+
'TV_ZERO_DAILY_SPENDING_LIMIT', 'USER_INVITE_ACCEPTED',
57+
'USER_INVITE_PENDING', 'ZERO_DAILY_SPENDING_LIMIT'
58+
]
59+
},
60+
:paging => {
61+
:start_index => 0,
62+
:number_results => PAGE_SIZE
63+
}
64+
}
65+
66+
# Set initial values.
67+
offset, page = 0, {}
68+
69+
# Get alerts.
70+
begin
71+
page = alert_srv.get(selector)
72+
if page[:entries]
73+
page[:entries].each_with_index do |alert, index|
74+
puts "%d) Customer ID is '%s', alert type is '%s', severity is '%s'."
75+
[AdwordsApi::Utils.format_id(alert[:client_customer_id]),
76+
alert[:alert_type], alert[:alert_severity]]
77+
alert[:details].each do |detail|
78+
puts "\t- triggered at %s" % detail[:trigger_time]
79+
end
80+
end
81+
# Increment values to request the next page.
82+
offset += PAGE_SIZE
83+
selector[:paging][:start_index] = offset
84+
end
85+
end while page[:total_num_entries] > offset
86+
87+
if page.include?(:total_num_entries)
88+
puts "\tTotal number of alerts: %d." % page[:total_num_entries]
89+
end
90+
end
91+
92+
if __FILE__ == $0
93+
API_VERSION = :v201406
94+
PAGE_SIZE = 500
95+
96+
begin
97+
get_account_alerts()
98+
99+
# Authorization error.
100+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
101+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
102+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
103+
"to retrieve and store OAuth2 tokens."
104+
puts "See this wiki page for more details:\n\n " +
105+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
106+
107+
# HTTP errors.
108+
rescue AdsCommon::Errors::HttpError => e
109+
puts "HTTP Error: %s" % e
110+
111+
# API errors.
112+
rescue AdwordsApi::Errors::ApiException => e
113+
puts "Message: %s" % e.message
114+
puts 'Errors:'
115+
e.errors.each_with_index do |error, index|
116+
puts "\tError [%d]:" % (index + 1)
117+
error.each do |field, value|
118+
puts "\t\t%s: %s" % [field, value]
119+
end
120+
end
121+
end
122+
end

0 commit comments

Comments
 (0)