google-dfp-api 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +201 -0
- data/ChangeLog +10 -0
- data/README +210 -0
- data/Rakefile +83 -0
- data/examples/v201101/common/error_handling.rb +76 -0
- data/examples/v201101/company_service/create_companies.rb +82 -0
- data/examples/v201101/company_service/get_all_companies.rb +92 -0
- data/examples/v201101/company_service/get_companies_by_statement.rb +88 -0
- data/examples/v201101/company_service/get_company.rb +72 -0
- data/examples/v201101/company_service/update_companies.rb +95 -0
- data/examples/v201101/creative_service/copy_image_creatives.rb +117 -0
- data/examples/v201101/creative_service/create_creatives.rb +109 -0
- data/examples/v201101/creative_service/get_all_creatives.rb +93 -0
- data/examples/v201101/creative_service/get_creative.rb +72 -0
- data/examples/v201101/creative_service/get_creatives_by_statement.rb +87 -0
- data/examples/v201101/creative_service/update_creatives.rb +98 -0
- data/examples/v201101/custom_targeting_service/create_custom_targeting_keys_and_values.rb +118 -0
- data/examples/v201101/custom_targeting_service/delete_custom_targeting_keys.rb +121 -0
- data/examples/v201101/custom_targeting_service/delete_custom_targeting_values.rb +125 -0
- data/examples/v201101/custom_targeting_service/get_all_custom_targeting_keys_and_values.rb +148 -0
- data/examples/v201101/custom_targeting_service/get_custom_targeting_keys_by_statement.rb +92 -0
- data/examples/v201101/custom_targeting_service/get_custom_targeting_values_by_statement.rb +98 -0
- data/examples/v201101/custom_targeting_service/update_custom_targeting_keys.rb +94 -0
- data/examples/v201101/custom_targeting_service/update_custom_targeting_values.rb +106 -0
- data/examples/v201101/forecast_service/get_forecast.rb +103 -0
- data/examples/v201101/forecast_service/get_forecast_by_id.rb +80 -0
- data/examples/v201101/inventory_service/create_ad_units.rb +98 -0
- data/examples/v201101/inventory_service/deactivate_ad_units.rb +119 -0
- data/examples/v201101/inventory_service/get_ad_unit.rb +72 -0
- data/examples/v201101/inventory_service/get_ad_units_by_statement.rb +96 -0
- data/examples/v201101/inventory_service/get_all_ad_units.rb +93 -0
- data/examples/v201101/inventory_service/update_ad_units.rb +94 -0
- data/examples/v201101/line_item_creative_association_service/create_licas.rb +94 -0
- data/examples/v201101/line_item_creative_association_service/deactivate_licas.rb +127 -0
- data/examples/v201101/line_item_creative_association_service/get_all_licas.rb +95 -0
- data/examples/v201101/line_item_creative_association_service/get_lica.rb +77 -0
- data/examples/v201101/line_item_creative_association_service/get_licas_by_statement.rb +91 -0
- data/examples/v201101/line_item_creative_association_service/update_licas.rb +92 -0
- data/examples/v201101/line_item_service/activate_line_items.rb +131 -0
- data/examples/v201101/line_item_service/create_line_items.rb +141 -0
- data/examples/v201101/line_item_service/get_all_line_items.rb +94 -0
- data/examples/v201101/line_item_service/get_line_item.rb +74 -0
- data/examples/v201101/line_item_service/get_line_items_by_statement.rb +89 -0
- data/examples/v201101/line_item_service/target_custom_criteria.rb +135 -0
- data/examples/v201101/line_item_service/update_line_items.rb +110 -0
- data/examples/v201101/network_service/get_all_networks.rb +74 -0
- data/examples/v201101/network_service/get_current_network.rb +66 -0
- data/examples/v201101/order_service/approve_orders.rb +116 -0
- data/examples/v201101/order_service/create_orders.rb +93 -0
- data/examples/v201101/order_service/get_all_orders.rb +93 -0
- data/examples/v201101/order_service/get_order.rb +74 -0
- data/examples/v201101/order_service/get_orders_by_statement.rb +90 -0
- data/examples/v201101/order_service/update_orders.rb +95 -0
- data/examples/v201101/placement_service/create_placements.rb +128 -0
- data/examples/v201101/placement_service/deactivate_placements.rb +118 -0
- data/examples/v201101/placement_service/get_all_placements.rb +93 -0
- data/examples/v201101/placement_service/get_placement.rb +74 -0
- data/examples/v201101/placement_service/get_placements_by_statement.rb +86 -0
- data/examples/v201101/placement_service/update_placements.rb +96 -0
- data/examples/v201101/publisher_query_language_service/get_all_cities.rb +85 -0
- data/examples/v201101/publisher_query_language_service/get_all_countries.rb +85 -0
- data/examples/v201101/publisher_query_language_service/get_all_metros.rb +85 -0
- data/examples/v201101/publisher_query_language_service/get_all_regions.rb +85 -0
- data/examples/v201101/report_service/download_report.rb +81 -0
- data/examples/v201101/report_service/run_delivery_report.rb +89 -0
- data/examples/v201101/report_service/run_inventory_report.rb +90 -0
- data/examples/v201101/report_service/run_sales_report.rb +89 -0
- data/examples/v201101/user_service/create_users.rb +89 -0
- data/examples/v201101/user_service/deactivate_users.rb +99 -0
- data/examples/v201101/user_service/get_all_roles.rb +73 -0
- data/examples/v201101/user_service/get_all_users.rb +92 -0
- data/examples/v201101/user_service/get_user.rb +73 -0
- data/examples/v201101/user_service/get_users_by_statement.rb +79 -0
- data/examples/v201101/user_service/update_users.rb +89 -0
- data/lib/dfp_api.rb +142 -0
- data/lib/dfp_api/api_config.rb +126 -0
- data/lib/dfp_api/credential_handler.rb +60 -0
- data/lib/dfp_api/errors.rb +59 -0
- data/lib/dfp_api/extensions.rb +54 -0
- data/lib/dfp_api/v201101/company_service.rb +52 -0
- data/lib/dfp_api/v201101/company_service_registry.rb +37 -0
- data/lib/dfp_api/v201101/creative_service.rb +52 -0
- data/lib/dfp_api/v201101/creative_service_registry.rb +37 -0
- data/lib/dfp_api/v201101/custom_targeting_service.rb +60 -0
- data/lib/dfp_api/v201101/custom_targeting_service_registry.rb +37 -0
- data/lib/dfp_api/v201101/forecast_service.rb +36 -0
- data/lib/dfp_api/v201101/forecast_service_registry.rb +37 -0
- data/lib/dfp_api/v201101/inventory_service.rb +56 -0
- data/lib/dfp_api/v201101/inventory_service_registry.rb +37 -0
- data/lib/dfp_api/v201101/line_item_creative_association_service.rb +56 -0
- data/lib/dfp_api/v201101/line_item_creative_association_service_registry.rb +37 -0
- data/lib/dfp_api/v201101/line_item_service.rb +56 -0
- data/lib/dfp_api/v201101/line_item_service_registry.rb +37 -0
- data/lib/dfp_api/v201101/network_service.rb +40 -0
- data/lib/dfp_api/v201101/network_service_registry.rb +37 -0
- data/lib/dfp_api/v201101/order_service.rb +56 -0
- data/lib/dfp_api/v201101/order_service_registry.rb +37 -0
- data/lib/dfp_api/v201101/placement_service.rb +56 -0
- data/lib/dfp_api/v201101/placement_service_registry.rb +37 -0
- data/lib/dfp_api/v201101/publisher_query_language_service.rb +32 -0
- data/lib/dfp_api/v201101/publisher_query_language_service_registry.rb +37 -0
- data/lib/dfp_api/v201101/report_service.rb +40 -0
- data/lib/dfp_api/v201101/report_service_registry.rb +37 -0
- data/lib/dfp_api/v201101/user_service.rb +60 -0
- data/lib/dfp_api/v201101/user_service_registry.rb +37 -0
- metadata +204 -0
@@ -0,0 +1,96 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
4
|
+
#
|
5
|
+
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
# This example gets first 500 children below the effective root ad unit. To
|
21
|
+
# create ad units, run create_ad_units.rb.
|
22
|
+
#
|
23
|
+
# Tags: InventoryService.getAdUnitsByStatement, NetworkService.getCurrentNetwork
|
24
|
+
|
25
|
+
require 'rubygems'
|
26
|
+
require 'dfp_api'
|
27
|
+
|
28
|
+
API_VERSION = :v201101
|
29
|
+
|
30
|
+
def get_ad_units_by_statement()
|
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 InventoryService.
|
39
|
+
inventory_service = dfp.service(:InventoryService, API_VERSION)
|
40
|
+
|
41
|
+
# Get the NetworkService.
|
42
|
+
network_service = dfp.service(:NetworkService, API_VERSION)
|
43
|
+
|
44
|
+
# Get the effective root ad unit ID of the network.
|
45
|
+
effective_root_ad_unit_id =
|
46
|
+
network_service.get_current_network[:effective_root_ad_unit_id]
|
47
|
+
|
48
|
+
puts "Using effective root ad unit: %d" % effective_root_ad_unit_id
|
49
|
+
|
50
|
+
# Create a statement to select the children of the effective root ad unit.
|
51
|
+
statement = {
|
52
|
+
:query => 'WHERE parentId = :id LIMIT 500',
|
53
|
+
:values => [
|
54
|
+
{:key => 'id',
|
55
|
+
:value => {:value => effective_root_ad_unit_id,
|
56
|
+
:xsi_type => 'NumberValue'}}
|
57
|
+
]
|
58
|
+
}
|
59
|
+
|
60
|
+
# Get ad units by statement.
|
61
|
+
page = inventory_service.get_ad_units_by_statement(statement)
|
62
|
+
|
63
|
+
if page[:results]
|
64
|
+
# Print details about each creative in results.
|
65
|
+
page[:results].each_with_index do |ad_unit, index|
|
66
|
+
puts "%d) Ad unit ID: %d, name: %s, status: %s." %
|
67
|
+
[index, ad_unit[:id], ad_unit[:name], ad_unit[:status]]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Print a footer.
|
72
|
+
if page.include?(:total_result_set_size)
|
73
|
+
puts "Total number of ad units: %d" % page[:total_result_set_size]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
if __FILE__ == $0
|
78
|
+
begin
|
79
|
+
get_ad_units_by_statement()
|
80
|
+
|
81
|
+
# HTTP errors.
|
82
|
+
rescue AdsCommon::Errors::HttpError => e
|
83
|
+
puts "HTTP Error: %s" % e
|
84
|
+
|
85
|
+
# API errors.
|
86
|
+
rescue DfpApi::Errors::ApiException => e
|
87
|
+
puts "Message: %s" % e.message
|
88
|
+
puts 'Errors:'
|
89
|
+
e.errors.each_with_index do |error, index|
|
90
|
+
puts "\tError [%d]:" % (index + 1)
|
91
|
+
error.each do |field, value|
|
92
|
+
puts "\t\t%s: %s" % [field, value]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
4
|
+
#
|
5
|
+
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
# This example gets all ad units. To create ad units, run create_ad_units.rb.
|
21
|
+
#
|
22
|
+
# Tags: InventoryService.getAdUnitsByStatement
|
23
|
+
|
24
|
+
require 'rubygems'
|
25
|
+
require 'dfp_api'
|
26
|
+
|
27
|
+
API_VERSION = :v201101
|
28
|
+
PAGE_SIZE = 500
|
29
|
+
|
30
|
+
def get_all_ad_units()
|
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 InventoryService.
|
39
|
+
inventory_service = dfp.service(:InventoryService, API_VERSION)
|
40
|
+
|
41
|
+
# Define initial values.
|
42
|
+
offset = 0
|
43
|
+
page = Hash.new
|
44
|
+
|
45
|
+
begin
|
46
|
+
# Create a statement to get one page with current offset.
|
47
|
+
statement = {:query => "LIMIT %d OFFSET %d" % [PAGE_SIZE, offset]}
|
48
|
+
|
49
|
+
# Get ad units by statement.
|
50
|
+
page = inventory_service.get_ad_units_by_statement(statement)
|
51
|
+
|
52
|
+
if page[:results]
|
53
|
+
# Increase query offset by page size.
|
54
|
+
offset += PAGE_SIZE
|
55
|
+
|
56
|
+
# Get the start index for printout.
|
57
|
+
start_index = page[:start_index]
|
58
|
+
|
59
|
+
# Print details about each ad unit in results.
|
60
|
+
page[:results].each_with_index do |ad_unit, index|
|
61
|
+
puts "%d) Ad unit ID: %d, name: %s, status: %s." %
|
62
|
+
[index + start_index, ad_unit[:id],
|
63
|
+
ad_unit[:name], ad_unit[:status]]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end while offset < page[:total_result_set_size]
|
67
|
+
|
68
|
+
# Print a footer.
|
69
|
+
if page.include?(:total_result_set_size)
|
70
|
+
puts "Total number of ad units: %d" % page[:total_result_set_size]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
if __FILE__ == $0
|
75
|
+
begin
|
76
|
+
get_all_ad_units()
|
77
|
+
|
78
|
+
# HTTP errors.
|
79
|
+
rescue AdsCommon::Errors::HttpError => e
|
80
|
+
puts "HTTP Error: %s" % e
|
81
|
+
|
82
|
+
# API errors.
|
83
|
+
rescue DfpApi::Errors::ApiException => e
|
84
|
+
puts "Message: %s" % e.message
|
85
|
+
puts 'Errors:'
|
86
|
+
e.errors.each_with_index do |error, index|
|
87
|
+
puts "\tError [%d]:" % (index + 1)
|
88
|
+
error.each do |field, value|
|
89
|
+
puts "\t\t%s: %s" % [field, value]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
4
|
+
#
|
5
|
+
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
# This example updates an ad unit by enabling AdSense to the first 500. To
|
21
|
+
# determine which ad units exist, run get_all_ad_units.rb or
|
22
|
+
# get_inventory_tree.rb.
|
23
|
+
#
|
24
|
+
# Tags: InventoryService.updateAdUnits
|
25
|
+
|
26
|
+
require 'rubygems'
|
27
|
+
require 'dfp_api'
|
28
|
+
|
29
|
+
API_VERSION = :v201101
|
30
|
+
|
31
|
+
def update_ad_units()
|
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 InventoryService.
|
40
|
+
inventory_service = dfp.service(:InventoryService, API_VERSION)
|
41
|
+
|
42
|
+
# Create a statement to get first 500 ad units.
|
43
|
+
statement = {:query => "LIMIT 500"}
|
44
|
+
|
45
|
+
# Get ad units by statement.
|
46
|
+
page = inventory_service.get_ad_units_by_statement(statement)
|
47
|
+
|
48
|
+
if page[:results]
|
49
|
+
ad_units = page[:results]
|
50
|
+
|
51
|
+
# Update each local ad unit object by enabling AdSense.
|
52
|
+
ad_units.each do |ad_unit|
|
53
|
+
ad_unit[:inherited_ad_sense_settings] =
|
54
|
+
{:value => {:ad_sense_enabled => true}}
|
55
|
+
end
|
56
|
+
|
57
|
+
# Update the ad units on the server.
|
58
|
+
return_ad_units = inventory_service.update_ad_units(ad_units)
|
59
|
+
|
60
|
+
if return_ad_units
|
61
|
+
return_ad_units.each do |ad_unit|
|
62
|
+
puts ("Ad unit with ID: %d, name: %s and status: %s was updated " +
|
63
|
+
"with AdSense enabled: %s") %
|
64
|
+
[ad_unit[:id], ad_unit[:name], ad_unit[:status],
|
65
|
+
ad_unit[:inherited_ad_sense_settings][:value][:ad_sense_enabled]]
|
66
|
+
end
|
67
|
+
else
|
68
|
+
raise 'No ad units were updated.'
|
69
|
+
end
|
70
|
+
else
|
71
|
+
puts 'No ad units found to update.'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
if __FILE__ == $0
|
76
|
+
begin
|
77
|
+
update_ad_units()
|
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
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
4
|
+
#
|
5
|
+
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
# This example creates new line item creative associations (LICAs) for an
|
21
|
+
# existing line item and a set of creative ids. For small business networks,
|
22
|
+
# the creative ids must represent new or copied creatives as creatives cannot
|
23
|
+
# be used for more than one line item. For premium solution networks, the
|
24
|
+
# creative ids can represent any creatvie. To copy creatives, run
|
25
|
+
# copy_image_creatives.rb. To determine which LICAs exist, run get_all_licas.rb.
|
26
|
+
#
|
27
|
+
# Tags: LineItemCreativeAssociationService.createLineItemCreativeAssociations
|
28
|
+
|
29
|
+
require 'rubygems'
|
30
|
+
require 'dfp_api'
|
31
|
+
|
32
|
+
API_VERSION = :v201101
|
33
|
+
|
34
|
+
def create_licas()
|
35
|
+
# Get DfpApi instance and load configuration from ~/dfp_api.yml.
|
36
|
+
dfp = DfpApi::Api.new
|
37
|
+
|
38
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
39
|
+
# the configuration file or provide your own logger:
|
40
|
+
# dfp.logger = Logger.new('dfp_xml.log')
|
41
|
+
|
42
|
+
# Get the LineItemCreativeAssociationService.
|
43
|
+
lica_service = dfp.service(:LineItemCreativeAssociationService, API_VERSION)
|
44
|
+
|
45
|
+
# Get the CreativeService.
|
46
|
+
creative_service = dfp.service(:CreativeService, API_VERSION)
|
47
|
+
|
48
|
+
# Set the line item ID and creative IDs to associate.
|
49
|
+
line_item_id = 'INSERT_LINE_ITEM_ID_HERE'.to_i
|
50
|
+
creative_ids = [
|
51
|
+
'INSERT_CREATIVE_ID_HERE'.to_i,
|
52
|
+
'INSERT_CREATIVE_ID_HERE'.to_i
|
53
|
+
]
|
54
|
+
|
55
|
+
# Create an array to store local LICA objects.
|
56
|
+
licas = creative_ids.map do |creative_id|
|
57
|
+
# For each line item, associate it with the given creative.
|
58
|
+
{:line_item_id => line_item_id, :creative_id => creative_id}
|
59
|
+
end
|
60
|
+
|
61
|
+
# Create the LICAs on the server.
|
62
|
+
return_licas = lica_service.create_line_item_creative_associations(licas)
|
63
|
+
|
64
|
+
if return_licas
|
65
|
+
return_licas.each do |lica|
|
66
|
+
puts ("LICA with line item ID: %d, creative ID: %d and status: %s was " +
|
67
|
+
"created.") % [lica[:line_item_id], lica[:creative_id], lica[:status]]
|
68
|
+
end
|
69
|
+
else
|
70
|
+
raise 'No LICAs were created.'
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
if __FILE__ == $0
|
76
|
+
begin
|
77
|
+
create_licas()
|
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
|
@@ -0,0 +1,127 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
4
|
+
#
|
5
|
+
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
# This example deactivates all LICAs for the line item. To determine which LICAs
|
21
|
+
# exist, run get_all_licas.rb. To determine which line items exist, run
|
22
|
+
# get_all_line_items.rb.
|
23
|
+
#
|
24
|
+
# Tags: InventoryService.getLineItemsByStatement,
|
25
|
+
# InventoryService.performAdUnitAction
|
26
|
+
|
27
|
+
require 'rubygems'
|
28
|
+
require 'dfp_api'
|
29
|
+
|
30
|
+
API_VERSION = :v201101
|
31
|
+
PAGE_SIZE = 500
|
32
|
+
|
33
|
+
def deactivate_licas()
|
34
|
+
# Get DfpApi instance and load configuration from ~/dfp_api.yml.
|
35
|
+
dfp = DfpApi::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
|
+
# dfp.logger = Logger.new('dfp_xml.log')
|
40
|
+
|
41
|
+
# Get the LineItemCreativeAssociationService.
|
42
|
+
lica_service = dfp.service(:LineItemCreativeAssociationService, API_VERSION)
|
43
|
+
|
44
|
+
# Set the line item to get LICAs by.
|
45
|
+
line_item_id = 'INSERT_LINE_ITEM_ID_HERE'.to_i
|
46
|
+
|
47
|
+
# Create statement text to select active LICAs for a given line item.
|
48
|
+
statement_text = 'WHERE lineItemId = :line_item_id AND status = :status'
|
49
|
+
|
50
|
+
statement = {
|
51
|
+
:values => [
|
52
|
+
{:key => 'line_item_id',
|
53
|
+
:value => {:value => line_item_id, :xsi_type => 'NumberValue'}},
|
54
|
+
{:key => 'status',
|
55
|
+
:value => {:value => 'ACTIVE', :xsi_type => 'TextValue'}}
|
56
|
+
]
|
57
|
+
}
|
58
|
+
|
59
|
+
# Define initial values.
|
60
|
+
offset = 0
|
61
|
+
page = Hash.new
|
62
|
+
creative_ids = Array.new
|
63
|
+
|
64
|
+
begin
|
65
|
+
# Create a statement to get one page with current offset.
|
66
|
+
statement[:query] = statement_text +
|
67
|
+
" LIMIT %d OFFSET %d" % [PAGE_SIZE, offset]
|
68
|
+
|
69
|
+
# Get LICAs by statement.
|
70
|
+
page =
|
71
|
+
lica_service.get_line_item_creative_associations_by_statement(statement)
|
72
|
+
|
73
|
+
if page[:results]
|
74
|
+
# Increase query offset by page size.
|
75
|
+
offset += PAGE_SIZE
|
76
|
+
|
77
|
+
page[:results].each do |lica|
|
78
|
+
puts ("%d) LICA with line item ID: %d, creative ID: %d and status: %s" +
|
79
|
+
" will be deactivated.") % [creative_ids.size, lica[:line_item_id],
|
80
|
+
lica[:creative_id], lica[:status]]
|
81
|
+
creative_ids << lica[:creative_id]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end while offset < page[:total_result_set_size]
|
85
|
+
|
86
|
+
puts "Number of LICAs to be deactivated: %d" % creative_ids.size
|
87
|
+
|
88
|
+
if !creative_ids.empty?
|
89
|
+
# Modify statement for action. Note, the values are still present.
|
90
|
+
statement[:query] = statement_text + " AND creativeId IN (%s)" %
|
91
|
+
creative_ids.join(', ')
|
92
|
+
|
93
|
+
# Perform action.
|
94
|
+
result = lica_service.perform_line_item_creative_association_action(
|
95
|
+
{:xsi_type => 'DeactivateLineItemCreativeAssociations'}, statement)
|
96
|
+
|
97
|
+
# Display results.
|
98
|
+
if result and result[:num_changes] > 0
|
99
|
+
puts "Number of LICAs deactivated: %d" % result[:num_changes]
|
100
|
+
else
|
101
|
+
puts 'No LICAs were deactivated.'
|
102
|
+
end
|
103
|
+
else
|
104
|
+
puts 'No LICAs found to deactivate.'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
if __FILE__ == $0
|
109
|
+
begin
|
110
|
+
deactivate_licas()
|
111
|
+
|
112
|
+
# HTTP errors.
|
113
|
+
rescue AdsCommon::Errors::HttpError => e
|
114
|
+
puts "HTTP Error: %s" % e
|
115
|
+
|
116
|
+
# API errors.
|
117
|
+
rescue DfpApi::Errors::ApiException => e
|
118
|
+
puts "Message: %s" % e.message
|
119
|
+
puts 'Errors:'
|
120
|
+
e.errors.each_with_index do |error, index|
|
121
|
+
puts "\tError [%d]:" % (index + 1)
|
122
|
+
error.each do |field, value|
|
123
|
+
puts "\t\t%s: %s" % [field, value]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|