Skip to content

Commit 4e96209

Browse files
committed
Support for Ad Manager v201902.
1 parent ad8bf01 commit 4e96209

297 files changed

Lines changed: 23123 additions & 42 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.

ad_manager_api/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
1.6.0:
2+
- Added support for v201902.
3+
- Removed support for v201802.
4+
- Removed examples for v201805.
5+
16
1.5.0:
27
- Added support for v201811.
38
- Removed support for v201711.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env ruby
2+
# Encoding: utf-8
3+
#
4+
# Copyright:: Copyright 2013, Google Inc. All Rights Reserved.
5+
#
6+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15+
# implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# This example creates new activity groups. To determine which activity groups
20+
# exist, run get_all_activity_groups.rb.
21+
22+
require 'ad_manager_api'
23+
24+
def create_activity_groups(ad_manager, advertiser_company_id)
25+
# Get the ActivityGroupService.
26+
activity_group_service = ad_manager.service(
27+
:ActivityGroupService, API_VERSION
28+
)
29+
30+
# Create a short-term activity group.
31+
short_term_activity_group = {
32+
:name => 'Short-term activity group',
33+
:company_ids => [advertiser_company_id],
34+
:clicks_lookback => 1,
35+
:impressions_lookback => 1
36+
}
37+
38+
# Create a long-term activity group.
39+
long_term_activity_group = {
40+
:name => 'Long-term activity group',
41+
:company_ids => [advertiser_company_id],
42+
:clicks_lookback => 30,
43+
:impressions_lookback => 30
44+
}
45+
46+
# Create the activity groups on the server.
47+
return_activity_groups = activity_group_service.create_activity_groups([
48+
short_term_activity_group, long_term_activity_group
49+
])
50+
51+
if return_activity_groups.to_a.size > 0
52+
return_activity_groups.each do |activity_group|
53+
puts 'An activity group with ID %d and name "%s" was created.' %
54+
[activity_group[:id], activity_group[:name]]
55+
end
56+
else
57+
raise 'No activity groups were created.'
58+
end
59+
end
60+
61+
if __FILE__ == $0
62+
API_VERSION = :v201902
63+
64+
# Get AdManagerApi instance and load configuration from ~/ad_manager_api.yml.
65+
ad_manager = AdManagerApi::Api.new
66+
67+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
68+
# the configuration file or provide your own logger:
69+
# ad_manager.logger = Logger.new('ad_manager_xml.log')
70+
71+
begin
72+
advertiser_company_id = 'INSERT_ADVERTISER_COMPANY_ID_HERE'
73+
create_activity_groups(ad_manager, advertiser_company_id)
74+
75+
# HTTP errors.
76+
rescue AdsCommon::Errors::HttpError => e
77+
puts "HTTP Error: %s" % e
78+
79+
# API errors.
80+
rescue AdManagerApi::Errors::ApiException => e
81+
puts "Message: %s" % e.message
82+
puts 'Errors:'
83+
e.errors.each_with_index do |error, index|
84+
puts "\tError [%d]:" % (index + 1)
85+
error.each do |field, value|
86+
puts "\t\t%s: %s" % [field, value]
87+
end
88+
end
89+
end
90+
end
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env ruby
2+
# Encoding: utf-8
3+
#
4+
# Copyright:: Copyright 2016, Google Inc. All Rights Reserved.
5+
#
6+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15+
# implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# This example gets all active activity groups.
20+
21+
require 'ad_manager_api'
22+
23+
def get_active_activity_groups(ad_manager)
24+
activity_group_service = ad_manager.service(
25+
:ActivityGroupService, API_VERSION
26+
)
27+
28+
# Create a statement to select activity groups.
29+
statement = ad_manager.new_statement_builder do |sb|
30+
sb.where = 'status = :status'
31+
sb.with_bind_variable('status', 'ACTIVE')
32+
end
33+
34+
# Retrieve a small amount of activity groups at a time, paging
35+
# through until all activity groups have been retrieved.
36+
page = {:total_result_set_size => 0}
37+
begin
38+
# Get activity groups by statement.
39+
page = activity_group_service.get_activity_groups_by_statement(
40+
statement.to_statement()
41+
)
42+
43+
# Print out some information for each activity group.
44+
unless page[:results].nil?
45+
page[:results].each_with_index do |activity_group, index|
46+
puts '%d) Activity group with ID %d and name "%s" was found.' % [
47+
index + statement.offset,
48+
activity_group[:id],
49+
activity_group[:name]
50+
]
51+
end
52+
end
53+
54+
# Increase the statement offset by the page size to get the next page.
55+
statement.offset += statement.limit
56+
end while statement.offset < page[:total_result_set_size]
57+
58+
puts 'Total number of activity groups: %d' % page[:total_result_set_size]
59+
end
60+
61+
if __FILE__ == $0
62+
API_VERSION = :v201902
63+
64+
# Get AdManagerApi instance and load configuration from ~/ad_manager_api.yml.
65+
ad_manager = AdManagerApi::Api.new
66+
67+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
68+
# the configuration file or provide your own logger:
69+
# ad_manager.logger = Logger.new('ad_manager_xml.log')
70+
71+
begin
72+
get_active_activity_groups(ad_manager)
73+
74+
# HTTP errors.
75+
rescue AdsCommon::Errors::HttpError => e
76+
puts "HTTP Error: %s" % e
77+
78+
# API errors.
79+
rescue AdManagerApi::Errors::ApiException => e
80+
puts "Message: %s" % e.message
81+
puts 'Errors:'
82+
e.errors.each_with_index do |error, index|
83+
puts "\tError [%d]:" % (index + 1)
84+
error.each do |field, value|
85+
puts "\t\t%s: %s" % [field, value]
86+
end
87+
end
88+
end
89+
end
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env ruby
2+
# Encoding: utf-8
3+
#
4+
# Copyright:: Copyright 2016, Google Inc. All Rights Reserved.
5+
#
6+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15+
# implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# This example gets all activity groups.
20+
require 'ad_manager_api'
21+
22+
def get_all_activity_groups(ad_manager)
23+
activity_group_service = ad_manager.service(
24+
:ActivityGroupService, API_VERSION
25+
)
26+
27+
# Create a statement to select activity groups.
28+
statement = ad_manager.new_statement_builder()
29+
30+
# Retrieve a small amount of activity groups at a time, paging
31+
# through until all activity groups have been retrieved.
32+
page = {:total_result_set_size => 0}
33+
begin
34+
page = activity_group_service.get_activity_groups_by_statement(
35+
statement.to_statement()
36+
)
37+
38+
# Print out some information for each activity group.
39+
unless page[:results].nil?
40+
page[:results].each_with_index do |activity_group, index|
41+
puts '%d) Activity group with ID %d and name "%s" was found.' % [
42+
index + statement.offset,
43+
activity_group[:id],
44+
activity_group[:name]
45+
]
46+
end
47+
end
48+
49+
# Increase the statement offset by the page size to get the next page.
50+
statement.offset += statement.limit
51+
end while statement.offset < page[:total_result_set_size]
52+
53+
puts 'Total number of activity groups: %d' % page[:total_result_set_size]
54+
end
55+
56+
if __FILE__ == $0
57+
API_VERSION = :v201902
58+
59+
# Get AdManagerApi instance and load configuration from ~/ad_manager_api.yml.
60+
ad_manager = AdManagerApi::Api.new
61+
62+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
63+
# the configuration file or provide your own logger:
64+
# ad_manager.logger = Logger.new('ad_manager_xml.log')
65+
66+
begin
67+
get_all_activity_groups(ad_manager)
68+
69+
# HTTP errors.
70+
rescue AdsCommon::Errors::HttpError => e
71+
puts "HTTP Error: %s" % e
72+
73+
# API errors.
74+
rescue AdManagerApi::Errors::ApiException => e
75+
puts "Message: %s" % e.message
76+
puts 'Errors:'
77+
e.errors.each_with_index do |error, index|
78+
puts "\tError [%d]:" % (index + 1)
79+
error.each do |field, value|
80+
puts "\t\t%s: %s" % [field, value]
81+
end
82+
end
83+
end
84+
end
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env ruby
2+
# Encoding: utf-8
3+
#
4+
# Copyright:: Copyright 2013, Google Inc. All Rights Reserved.
5+
#
6+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15+
# implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# This example updates activity groups by adding a company. To determine which
20+
# activity groups exist, run get_all_activity_groups.rb.
21+
22+
require 'ad_manager_api'
23+
24+
def update_activity_groups(ad_manager, advertiser_company_id, activity_group_id)
25+
# Get the ActivityGroupService.
26+
activity_group_service = ad_manager.service(
27+
:ActivityGroupService, API_VERSION
28+
)
29+
30+
# Create statement to select a single activity group.
31+
statement = ad_manager.new_statement_builder do |sb|
32+
sb.where = 'id = :id'
33+
sb.with_bind_variable('id', activity_group_id)
34+
end
35+
36+
page = activity_group_service.get_activity_groups_by_statement(
37+
statement.to_statement()
38+
)
39+
40+
unless page[:results].nil?
41+
# Get the activity groups.
42+
activity_groups = page[:results]
43+
44+
activity_groups.each do |activity_group|
45+
# Update the companies.
46+
activity_group[:company_ids] << advertiser_company_id
47+
end
48+
49+
# Update the activity groups on the server.
50+
return_activity_groups = activity_group_service.update_activity_groups(
51+
activity_groups)
52+
53+
return_activity_groups.each do |updates_activity_group|
54+
puts 'Activity group with ID %d and name "%s" was updated.' %
55+
[updates_activity_group[:id], updates_activity_group[:name]]
56+
end
57+
end
58+
end
59+
60+
if __FILE__ == $0
61+
API_VERSION = :v201902
62+
63+
# Get AdManagerApi instance and load configuration from ~/ad_manager_api.yml.
64+
ad_manager = AdManagerApi::Api.new
65+
66+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
67+
# the configuration file or provide your own logger:
68+
# ad_manager.logger = Logger.new('ad_manager_xml.log')
69+
70+
begin
71+
advertiser_company_id = 'INSERT_ADVERTISER_COMPANY_ID_HERE'
72+
activity_group_id = 'INSERT_ACTIVITY_GROUP_ID_HERE'
73+
update_activity_groups(ad_manager, advertiser_company_id, activity_group_id)
74+
75+
# HTTP errors.
76+
rescue AdsCommon::Errors::HttpError => e
77+
puts "HTTP Error: %s" % e
78+
79+
# API errors.
80+
rescue AdManagerApi::Errors::ApiException => e
81+
puts "Message: %s" % e.message
82+
puts 'Errors:'
83+
e.errors.each_with_index do |error, index|
84+
puts "\tError [%d]:" % (index + 1)
85+
error.each do |field, value|
86+
puts "\t\t%s: %s" % [field, value]
87+
end
88+
end
89+
end
90+
end

0 commit comments

Comments
 (0)