Skip to content

Commit 9b4b459

Browse files
committed
DFP API v201311 support
1 parent 3c71e04 commit 9b4b459

235 files changed

Lines changed: 18304 additions & 10 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.

dfp_api/ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
0.7.1:
2+
- Added support and examples for v201311.
3+
- Require google-ads-common 0.9.4 or later from now on.
24

35
0.7.0:
46
- Added support and examples for v201308.

dfp_api/README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Once the library object is created you can request services with a 'service'
116116
method:
117117
user_service = dfp.service(:UserService, <API_VERSION>)
118118

119-
where <API_VERSION> is required version of DFP API as symbol, e.g. :v201308.
119+
where <API_VERSION> is required version of DFP API as symbol, e.g. :v201311.
120120

121121
Then you should be able to execute service methods:
122122

@@ -150,7 +150,7 @@ Examples can be run by executing by running:
150150

151151
from the "examples/<version>/<service_name>" directory i.e.
152152

153-
$ cd examples/v201308/user_service
153+
$ cd examples/v201311/user_service
154154
$ ruby get_all_users.rb
155155

156156
Some examples require modification to be functional, like create_order example
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env ruby
2+
# Encoding: utf-8
3+
#
4+
# Author:: api.davidtorres@gmail.com (David Torres)
5+
#
6+
# Copyright:: Copyright 2013, 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 creates new activity groups. To determine which activity groups
22+
# exist, run get_all_activity_groups.rb.
23+
#
24+
# Tags: ActivityGroupService.createActivityGroups
25+
26+
require 'dfp_api'
27+
28+
API_VERSION = :v201311
29+
30+
def create_activity_groups()
31+
# Get DfpApi instance and load configuration from ~/dfp_api.yml.
32+
dfp = DfpApi::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+
# dfp.logger = Logger.new('dfp_xml.log')
37+
38+
# Get the ActivityGroupService.
39+
activity_group_service = dfp.service(:ActivityGroupService, API_VERSION)
40+
41+
# Set the ID of the advertiser company this activity group is associated
42+
# with.
43+
advertiser_company_id = 'INSERT_ADVERTISER_COMPANY_ID_HERE';
44+
45+
# Create a short-term activity group.
46+
short_term_activity_group = {
47+
:name => 'Short-term activity group',
48+
:company_ids => [advertiser_company_id],
49+
:clicks_lookback => 1,
50+
:impressions_lookback => 1
51+
}
52+
53+
# Create a long-term activity group.
54+
long_term_activity_group = {
55+
:name => 'Long-term activity group',
56+
:company_ids => [advertiser_company_id],
57+
:clicks_lookback => 30,
58+
:impressions_lookback => 30
59+
}
60+
61+
# Create the activity groups on the server.
62+
return_activity_groups = activity_group_service.create_activity_groups([
63+
short_term_activity_group, long_term_activity_group])
64+
65+
if return_activity_groups
66+
return_activity_groups.each do |activity_group|
67+
puts "An activity group with ID: %d and name: %s was created." %
68+
[activity_group[:id], activity_group[:name]]
69+
end
70+
else
71+
raise 'No activity groups were created.'
72+
end
73+
end
74+
75+
if __FILE__ == $0
76+
begin
77+
create_activity_groups()
78+
79+
# HTTP errors.
80+
rescue AdsCommon::Errors::HttpError => e
81+
puts "HTTP Error: %s" % e
82+
83+
# API errors.
84+
rescue DfpApi::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
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env ruby
2+
# Encoding: utf-8
3+
#
4+
# Author:: api.davidtorres@gmail.com (David Torres)
5+
#
6+
# Copyright:: Copyright 2013, 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 active activity groups. To create activity groups,
22+
# run create_activity_groups.rb.
23+
#
24+
# Tags: ActivityGroupService.getActivityGroupsByStatement
25+
26+
require 'dfp_api'
27+
28+
API_VERSION = :v201311
29+
PAGE_SIZE = 500
30+
31+
def get_active_activity_groups()
32+
# Get DfpApi instance and load configuration from ~/dfp_api.yml.
33+
dfp = DfpApi::Api.new
34+
35+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
36+
# the configuration file or provide your own logger:
37+
# dfp.logger = Logger.new('dfp_xml.log')
38+
39+
# Get the ActivityGroupService.
40+
activity_group_service = dfp.service(:ActivityGroupService, API_VERSION)
41+
42+
# Define initial values.
43+
offset = 0
44+
page = {}
45+
46+
begin
47+
# Create statement for one page with current offset.
48+
statement = {
49+
:query => 'WHERE status = :status ORDER BY id LIMIT %d OFFSET %d' %
50+
[PAGE_SIZE, offset],
51+
:values => [
52+
{:key => 'status',
53+
:value => {:value => 'ACTIVE', :xsi_type => 'TextValue'}}
54+
]
55+
}
56+
57+
# Get activity groups by statement.
58+
page = activity_group_service.get_activity_groups_by_statement(statement)
59+
60+
if page[:results]
61+
# Increase query offset by page size.
62+
offset += PAGE_SIZE
63+
64+
# Get the start index for printout.
65+
start_index = page[:start_index]
66+
67+
# Print details about each content object in results page.
68+
page[:results].each_with_index do |activity_group, index|
69+
puts "%d) Activity group with ID: %d, name: %s." % [index + start_index,
70+
activity_group[:id], activity_group[:name]]
71+
end
72+
end
73+
end while offset < page[:total_result_set_size]
74+
75+
# Print a footer
76+
if page.include?(:total_result_set_size)
77+
puts "Total number of results: %d" % page[:total_result_set_size]
78+
end
79+
end
80+
81+
if __FILE__ == $0
82+
begin
83+
get_active_activity_groups()
84+
85+
# HTTP errors.
86+
rescue AdsCommon::Errors::HttpError => e
87+
puts "HTTP Error: %s" % e
88+
89+
# API errors.
90+
rescue DfpApi::Errors::ApiException => e
91+
puts "Message: %s" % e.message
92+
puts 'Errors:'
93+
e.errors.each_with_index do |error, index|
94+
puts "\tError [%d]:" % (index + 1)
95+
error.each do |field, value|
96+
puts "\t\t%s: %s" % [field, value]
97+
end
98+
end
99+
end
100+
end
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env ruby
2+
# Encoding: utf-8
3+
#
4+
# Author:: api.davidtorres@gmail.com (David Torres)
5+
#
6+
# Copyright:: Copyright 2013, 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 activity groups. To create activity groups,
22+
# run create_activity_groups.rb.
23+
#
24+
# Tags: ActivityGroupService.getActivityGroupsByStatement
25+
26+
require 'dfp_api'
27+
28+
API_VERSION = :v201311
29+
PAGE_SIZE = 500
30+
31+
def get_all_activity_groups()
32+
# Get DfpApi instance and load configuration from ~/dfp_api.yml.
33+
dfp = DfpApi::Api.new
34+
35+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
36+
# the configuration file or provide your own logger:
37+
# dfp.logger = Logger.new('dfp_xml.log')
38+
39+
# Get the ActivityGroupService.
40+
activity_group_service = dfp.service(:ActivityGroupService, API_VERSION)
41+
42+
# Define initial values.
43+
offset = 0
44+
page = {}
45+
46+
begin
47+
# Create statement for one page with current offset.
48+
statement = {
49+
:query => 'ORDER BY id LIMIT %d OFFSET %d' % [PAGE_SIZE, offset],
50+
}
51+
52+
# Get activity groups by statement.
53+
page = activity_group_service.get_activity_groups_by_statement(statement)
54+
55+
if page[:results]
56+
# Increase query offset by page size.
57+
offset += PAGE_SIZE
58+
59+
# Get the start index for printout.
60+
start_index = page[:start_index]
61+
62+
# Print details about each content object in results page.
63+
page[:results].each_with_index do |activity_group, index|
64+
puts "%d) Activity group with ID: %d, name: %s." % [index + start_index,
65+
activity_group[:id], activity_group[:name]]
66+
end
67+
end
68+
end while offset < page[:total_result_set_size]
69+
70+
# Print a footer
71+
if page.include?(:total_result_set_size)
72+
puts "Total number of results: %d" % page[:total_result_set_size]
73+
end
74+
end
75+
76+
if __FILE__ == $0
77+
begin
78+
get_all_activity_groups()
79+
80+
# HTTP errors.
81+
rescue AdsCommon::Errors::HttpError => e
82+
puts "HTTP Error: %s" % e
83+
84+
# API errors.
85+
rescue DfpApi::Errors::ApiException => e
86+
puts "Message: %s" % e.message
87+
puts 'Errors:'
88+
e.errors.each_with_index do |error, index|
89+
puts "\tError [%d]:" % (index + 1)
90+
error.each do |field, value|
91+
puts "\t\t%s: %s" % [field, value]
92+
end
93+
end
94+
end
95+
end

0 commit comments

Comments
 (0)