google-dfp-api 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +6 -0
- data/README +11 -5
- data/Rakefile +1 -1
- data/examples/{v201101 → v201108}/common/error_handling.rb +1 -1
- data/examples/{v201101 → v201108}/common/oauth_handling.rb +1 -1
- data/examples/{v201101 → v201108}/company_service/create_companies.rb +1 -1
- data/examples/{v201101 → v201108}/company_service/get_all_companies.rb +1 -1
- data/examples/{v201101 → v201108}/company_service/get_companies_by_statement.rb +1 -1
- data/examples/{v201101 → v201108}/company_service/get_company.rb +1 -1
- data/examples/{v201101 → v201108}/company_service/update_companies.rb +1 -1
- data/examples/{v201101 → v201108}/creative_service/copy_image_creatives.rb +1 -1
- data/examples/{v201101 → v201108}/creative_service/create_creatives.rb +1 -1
- data/examples/{v201101 → v201108}/creative_service/get_all_creatives.rb +1 -1
- data/examples/{v201101 → v201108}/creative_service/get_creative.rb +1 -1
- data/examples/{v201101 → v201108}/creative_service/get_creatives_by_statement.rb +1 -1
- data/examples/{v201101 → v201108}/creative_service/update_creatives.rb +1 -1
- data/examples/{v201101 → v201108}/custom_targeting_service/create_custom_targeting_keys_and_values.rb +1 -1
- data/examples/{v201101 → v201108}/custom_targeting_service/delete_custom_targeting_keys.rb +1 -1
- data/examples/{v201101 → v201108}/custom_targeting_service/delete_custom_targeting_values.rb +1 -1
- data/examples/{v201101 → v201108}/custom_targeting_service/get_all_custom_targeting_keys_and_values.rb +1 -1
- data/examples/{v201101 → v201108}/custom_targeting_service/get_custom_targeting_keys_by_statement.rb +1 -1
- data/examples/{v201101 → v201108}/custom_targeting_service/get_custom_targeting_values_by_statement.rb +1 -1
- data/examples/{v201101 → v201108}/custom_targeting_service/update_custom_targeting_keys.rb +1 -1
- data/examples/{v201101 → v201108}/custom_targeting_service/update_custom_targeting_values.rb +1 -1
- data/examples/{v201101 → v201108}/forecast_service/get_forecast.rb +8 -4
- data/examples/{v201101 → v201108}/forecast_service/get_forecast_by_id.rb +1 -1
- data/examples/{v201101 → v201108}/inventory_service/create_ad_units.rb +8 -2
- data/examples/{v201101 → v201108}/inventory_service/deactivate_ad_units.rb +1 -1
- data/examples/{v201101 → v201108}/inventory_service/get_ad_unit.rb +1 -1
- data/examples/v201108/inventory_service/get_ad_unit_sizes.rb +73 -0
- data/examples/{v201101 → v201108}/inventory_service/get_ad_units_by_statement.rb +1 -1
- data/examples/{v201101 → v201108}/inventory_service/get_all_ad_units.rb +1 -1
- data/examples/{v201101 → v201108}/inventory_service/update_ad_units.rb +1 -1
- data/examples/v201108/label_service/create_labels.rb +83 -0
- data/examples/v201108/label_service/deactivate_labels.rb +118 -0
- data/examples/v201108/label_service/get_all_labels.rb +94 -0
- data/examples/v201108/label_service/get_label.rb +76 -0
- data/examples/v201108/label_service/get_labels_by_statement.rb +91 -0
- data/examples/v201108/label_service/update_labels.rb +104 -0
- data/examples/{v201101 → v201108}/line_item_creative_association_service/create_licas.rb +1 -1
- data/examples/{v201101 → v201108}/line_item_creative_association_service/deactivate_licas.rb +1 -1
- data/examples/{v201101 → v201108}/line_item_creative_association_service/get_all_licas.rb +1 -1
- data/examples/{v201101 → v201108}/line_item_creative_association_service/get_lica.rb +1 -1
- data/examples/{v201101 → v201108}/line_item_creative_association_service/get_licas_by_statement.rb +1 -1
- data/examples/{v201101 → v201108}/line_item_creative_association_service/update_licas.rb +1 -1
- data/examples/{v201101 → v201108}/line_item_service/activate_line_items.rb +1 -1
- data/examples/{v201101 → v201108}/line_item_service/create_line_items.rb +49 -19
- data/examples/{v201101 → v201108}/line_item_service/get_all_line_items.rb +1 -1
- data/examples/{v201101 → v201108}/line_item_service/get_line_item.rb +1 -1
- data/examples/{v201101 → v201108}/line_item_service/get_line_items_by_statement.rb +1 -1
- data/examples/{v201101 → v201108}/line_item_service/target_custom_criteria.rb +30 -36
- data/examples/{v201101 → v201108}/line_item_service/update_line_items.rb +1 -1
- data/examples/{v201101 → v201108}/network_service/get_all_networks.rb +1 -1
- data/examples/{v201101 → v201108}/network_service/get_current_network.rb +1 -1
- data/examples/{v201101 → v201108}/order_service/approve_orders.rb +1 -1
- data/examples/{v201101 → v201108}/order_service/create_orders.rb +1 -1
- data/examples/{v201101 → v201108}/order_service/get_all_orders.rb +1 -1
- data/examples/{v201101 → v201108}/order_service/get_order.rb +1 -1
- data/examples/{v201101 → v201108}/order_service/get_orders_by_statement.rb +1 -1
- data/examples/{v201101 → v201108}/order_service/update_orders.rb +1 -1
- data/examples/{v201101 → v201108}/placement_service/create_placements.rb +3 -2
- data/examples/{v201101 → v201108}/placement_service/deactivate_placements.rb +1 -1
- data/examples/{v201101 → v201108}/placement_service/get_all_placements.rb +1 -1
- data/examples/{v201101 → v201108}/placement_service/get_placement.rb +1 -1
- data/examples/{v201101 → v201108}/placement_service/get_placements_by_statement.rb +1 -1
- data/examples/{v201101 → v201108}/placement_service/update_placements.rb +1 -1
- data/examples/v201108/publisher_query_language_service/get_all_bandwidth_groups.rb +85 -0
- data/examples/v201108/publisher_query_language_service/get_all_browser_languages.rb +85 -0
- data/examples/v201108/publisher_query_language_service/get_all_browsers.rb +85 -0
- data/examples/{v201101 → v201108}/publisher_query_language_service/get_all_cities.rb +1 -1
- data/examples/{v201101 → v201108}/publisher_query_language_service/get_all_countries.rb +1 -1
- data/examples/{v201101 → v201108}/publisher_query_language_service/get_all_metros.rb +1 -1
- data/examples/v201108/publisher_query_language_service/get_all_operating_systems.rb +85 -0
- data/examples/{v201101 → v201108}/publisher_query_language_service/get_all_regions.rb +1 -1
- data/examples/{v201101 → v201108}/report_service/download_report.rb +1 -1
- data/examples/{v201101 → v201108}/report_service/run_delivery_report.rb +1 -1
- data/examples/{v201101 → v201108}/report_service/run_inventory_report.rb +1 -1
- data/examples/{v201101 → v201108}/report_service/run_sales_report.rb +1 -1
- data/examples/{v201101 → v201108}/user_service/create_users.rb +1 -1
- data/examples/{v201101 → v201108}/user_service/deactivate_users.rb +1 -1
- data/examples/{v201101 → v201108}/user_service/get_all_roles.rb +1 -1
- data/examples/{v201101 → v201108}/user_service/get_all_users.rb +1 -1
- data/examples/v201108/user_service/get_current_user.rb +66 -0
- data/examples/{v201101 → v201108}/user_service/get_user.rb +1 -1
- data/examples/{v201101 → v201108}/user_service/get_users_by_statement.rb +1 -1
- data/examples/{v201101 → v201108}/user_service/update_users.rb +1 -1
- data/lib/dfp_api.rb +5 -12
- data/lib/dfp_api/api_config.rb +14 -13
- data/lib/dfp_api/credential_handler.rb +5 -5
- data/lib/dfp_api/v201104/company_service.rb +5 -5
- data/lib/dfp_api/v201104/company_service_registry.rb +5 -3
- data/lib/dfp_api/v201104/creative_service.rb +5 -5
- data/lib/dfp_api/v201104/creative_service_registry.rb +5 -3
- data/lib/dfp_api/v201104/custom_targeting_service.rb +9 -9
- data/lib/dfp_api/v201104/custom_targeting_service_registry.rb +5 -3
- data/lib/dfp_api/v201104/forecast_service.rb +5 -5
- data/lib/dfp_api/v201104/forecast_service_registry.rb +5 -3
- data/lib/dfp_api/v201104/inventory_service.rb +9 -9
- data/lib/dfp_api/v201104/inventory_service_registry.rb +5 -3
- data/lib/dfp_api/v201104/line_item_creative_association_service.rb +1 -1
- data/lib/dfp_api/v201104/line_item_creative_association_service_registry.rb +5 -3
- data/lib/dfp_api/v201104/line_item_service.rb +13 -13
- data/lib/dfp_api/v201104/line_item_service_registry.rb +5 -3
- data/lib/dfp_api/v201104/network_service.rb +5 -5
- data/lib/dfp_api/v201104/network_service_registry.rb +5 -3
- data/lib/dfp_api/v201104/order_service.rb +1 -1
- data/lib/dfp_api/v201104/order_service_registry.rb +5 -3
- data/lib/dfp_api/v201104/placement_service.rb +5 -5
- data/lib/dfp_api/v201104/placement_service_registry.rb +5 -3
- data/lib/dfp_api/v201104/publisher_query_language_service.rb +1 -1
- data/lib/dfp_api/v201104/publisher_query_language_service_registry.rb +5 -3
- data/lib/dfp_api/v201104/report_service.rb +5 -5
- data/lib/dfp_api/v201104/report_service_registry.rb +5 -3
- data/lib/dfp_api/v201104/user_service.rb +9 -9
- data/lib/dfp_api/v201104/user_service_registry.rb +5 -3
- data/lib/dfp_api/v201107/company_service.rb +9 -9
- data/lib/dfp_api/v201107/company_service_registry.rb +5 -3
- data/lib/dfp_api/v201107/custom_targeting_service.rb +9 -9
- data/lib/dfp_api/v201107/custom_targeting_service_registry.rb +5 -3
- data/lib/dfp_api/v201107/label_service.rb +5 -5
- data/lib/dfp_api/v201107/label_service_registry.rb +5 -3
- data/lib/dfp_api/v201107/order_service.rb +13 -13
- data/lib/dfp_api/v201107/order_service_registry.rb +5 -3
- data/lib/dfp_api/v201107/report_service.rb +5 -5
- data/lib/dfp_api/v201107/report_service_registry.rb +5 -3
- data/lib/dfp_api/v201107/user_service.rb +19 -19
- data/lib/dfp_api/v201107/user_service_registry.rb +5 -3
- data/lib/dfp_api/{v201101 → v201108}/company_service.rb +10 -10
- data/lib/dfp_api/v201108/company_service_registry.rb +44 -0
- data/lib/dfp_api/{v201101 → v201108}/creative_service.rb +10 -10
- data/lib/dfp_api/v201108/creative_service_registry.rb +44 -0
- data/lib/dfp_api/{v201101 → v201108}/custom_targeting_service.rb +14 -14
- data/lib/dfp_api/v201108/custom_targeting_service_registry.rb +44 -0
- data/lib/dfp_api/{v201101 → v201108}/forecast_service.rb +10 -10
- data/lib/dfp_api/v201108/forecast_service_registry.rb +44 -0
- data/lib/dfp_api/{v201101 → v201108}/inventory_service.rb +18 -14
- data/lib/dfp_api/v201108/inventory_service_registry.rb +44 -0
- data/lib/dfp_api/v201108/label_service.rb +56 -0
- data/lib/dfp_api/v201108/label_service_registry.rb +44 -0
- data/lib/dfp_api/{v201101 → v201108}/line_item_creative_association_service.rb +6 -6
- data/lib/dfp_api/v201108/line_item_creative_association_service_registry.rb +44 -0
- data/lib/dfp_api/{v201101 → v201108}/line_item_service.rb +18 -18
- data/lib/dfp_api/v201108/line_item_service_registry.rb +44 -0
- data/lib/dfp_api/{v201101 → v201108}/network_service.rb +10 -10
- data/lib/dfp_api/v201108/network_service_registry.rb +44 -0
- data/lib/dfp_api/{v201101 → v201108}/order_service.rb +6 -6
- data/lib/dfp_api/v201108/order_service_registry.rb +44 -0
- data/lib/dfp_api/{v201101 → v201108}/placement_service.rb +10 -10
- data/lib/dfp_api/v201108/placement_service_registry.rb +44 -0
- data/lib/dfp_api/{v201101 → v201108}/publisher_query_language_service.rb +6 -6
- data/lib/dfp_api/v201108/publisher_query_language_service_registry.rb +44 -0
- data/lib/dfp_api/{v201101 → v201108}/report_service.rb +10 -10
- data/lib/dfp_api/v201108/report_service_registry.rb +44 -0
- data/lib/dfp_api/v201108/third_party_slot_service.rb +44 -0
- data/lib/dfp_api/v201108/third_party_slot_service_registry.rb +44 -0
- data/lib/dfp_api/{v201101 → v201108}/user_service.rb +18 -14
- data/lib/dfp_api/v201108/user_service_registry.rb +44 -0
- metadata +120 -104
- data/lib/dfp_api/v201101/company_service_registry.rb +0 -42
- data/lib/dfp_api/v201101/creative_service_registry.rb +0 -42
- data/lib/dfp_api/v201101/custom_targeting_service_registry.rb +0 -42
- data/lib/dfp_api/v201101/forecast_service_registry.rb +0 -42
- data/lib/dfp_api/v201101/inventory_service_registry.rb +0 -42
- data/lib/dfp_api/v201101/line_item_creative_association_service_registry.rb +0 -42
- data/lib/dfp_api/v201101/line_item_service_registry.rb +0 -42
- data/lib/dfp_api/v201101/network_service_registry.rb +0 -42
- data/lib/dfp_api/v201101/order_service_registry.rb +0 -42
- data/lib/dfp_api/v201101/placement_service_registry.rb +0 -42
- data/lib/dfp_api/v201101/publisher_query_language_service_registry.rb +0 -42
- data/lib/dfp_api/v201101/report_service_registry.rb +0 -42
- data/lib/dfp_api/v201101/user_service_registry.rb +0 -42
@@ -0,0 +1,83 @@
|
|
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 labels. To determine which labels exist, run
|
21
|
+
# get_all_labels.rb.
|
22
|
+
#
|
23
|
+
# This feature is only available to DFP premium solution networks.
|
24
|
+
#
|
25
|
+
# Tags: LabelService.createLabels
|
26
|
+
|
27
|
+
require 'rubygems'
|
28
|
+
require 'dfp_api'
|
29
|
+
|
30
|
+
API_VERSION = :v201108
|
31
|
+
# Number of labels to create.
|
32
|
+
ITEM_COUNT = 5
|
33
|
+
|
34
|
+
def create_labels()
|
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 LabelService.
|
43
|
+
label_service = dfp.service(:LabelService, API_VERSION)
|
44
|
+
|
45
|
+
# Create an array to store local label objects.
|
46
|
+
labels = (1..ITEM_COUNT).map do |index|
|
47
|
+
{:name => "Label #%d" % index, :type => 'COMPETITIVE_EXCLUSION'}
|
48
|
+
end
|
49
|
+
|
50
|
+
# Create the labels on the server.
|
51
|
+
return_labels = label_service.create_labels(labels)
|
52
|
+
|
53
|
+
if return_labels
|
54
|
+
return_labels.each do |label|
|
55
|
+
puts "Label with ID: %d, name: %s and type: %s was created." %
|
56
|
+
[label[:id], label[:name], label[:type]]
|
57
|
+
end
|
58
|
+
else
|
59
|
+
raise 'No labels were created.'
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
if __FILE__ == $0
|
65
|
+
begin
|
66
|
+
create_labels()
|
67
|
+
|
68
|
+
# HTTP errors.
|
69
|
+
rescue AdsCommon::Errors::HttpError => e
|
70
|
+
puts "HTTP Error: %s" % e
|
71
|
+
|
72
|
+
# API errors.
|
73
|
+
rescue DfpApi::Errors::ApiException => e
|
74
|
+
puts "Message: %s" % e.message
|
75
|
+
puts 'Errors:'
|
76
|
+
e.errors.each_with_index do |error, index|
|
77
|
+
puts "\tError [%d]:" % (index + 1)
|
78
|
+
error.each do |field, value|
|
79
|
+
puts "\t\t%s: %s" % [field, value]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,118 @@
|
|
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 active labels. To determine which labels exist,
|
21
|
+
# run get_all_labels.rb.
|
22
|
+
#
|
23
|
+
# This feature is only available to DFP premium solution networks.
|
24
|
+
#
|
25
|
+
# Tags: LabelService.getLabelsByStatement, LabelService.performLabelAction
|
26
|
+
|
27
|
+
require 'rubygems'
|
28
|
+
require 'dfp_api'
|
29
|
+
|
30
|
+
API_VERSION = :v201108
|
31
|
+
PAGE_SIZE = 500
|
32
|
+
|
33
|
+
def deactivate_labels()
|
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 LabelService.
|
42
|
+
label_service = dfp.service(:LabelService, API_VERSION)
|
43
|
+
|
44
|
+
# Create statement text and statement to select active labels.
|
45
|
+
statement_text = 'WHERE isActive = :is_active'
|
46
|
+
statement = {
|
47
|
+
:values => [
|
48
|
+
{:key => 'is_active',
|
49
|
+
:value => {:value => true, :xsi_type => 'BooleanValue'}}
|
50
|
+
]
|
51
|
+
}
|
52
|
+
|
53
|
+
# Define initial values.
|
54
|
+
offset = 0
|
55
|
+
page = {}
|
56
|
+
label_ids = []
|
57
|
+
|
58
|
+
begin
|
59
|
+
# Modify the statement to get one page with current offset.
|
60
|
+
statement[:query] = statement_text +
|
61
|
+
" LIMIT %d OFFSET %d" % [PAGE_SIZE, offset]
|
62
|
+
|
63
|
+
# Get labels by statement.
|
64
|
+
page = label_service.get_labels_by_statement(statement)
|
65
|
+
|
66
|
+
if page[:results]
|
67
|
+
# Increase query offset by page size.
|
68
|
+
offset += PAGE_SIZE
|
69
|
+
|
70
|
+
page[:results].each do |label|
|
71
|
+
puts ("%d) Label ID: %d, name: %s will be deactivated.") %
|
72
|
+
[label_ids.size, label[:id], label[:name]]
|
73
|
+
label_ids << label[:id]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end while offset < page[:total_result_set_size]
|
77
|
+
|
78
|
+
puts "Number of labels to be deactivated: %d" % label_ids.size
|
79
|
+
|
80
|
+
if !label_ids.empty?
|
81
|
+
# Create a statement for action.
|
82
|
+
statement = {:query => "WHERE id IN (%s)" % label_ids.join(', ')}
|
83
|
+
|
84
|
+
# Perform action.
|
85
|
+
result = label_service.perform_label_action(
|
86
|
+
{:xsi_type => 'DeactivateLabels'}, statement)
|
87
|
+
|
88
|
+
# Display results.
|
89
|
+
if result and result[:num_changes] > 0
|
90
|
+
puts "Number of labels deactivated: %d" % result[:num_changes]
|
91
|
+
else
|
92
|
+
puts 'No labels were deactivated.'
|
93
|
+
end
|
94
|
+
else
|
95
|
+
puts 'No labels found to deactivate.'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
if __FILE__ == $0
|
100
|
+
begin
|
101
|
+
deactivate_labels()
|
102
|
+
|
103
|
+
# HTTP errors.
|
104
|
+
rescue AdsCommon::Errors::HttpError => e
|
105
|
+
puts "HTTP Error: %s" % e
|
106
|
+
|
107
|
+
# API errors.
|
108
|
+
rescue DfpApi::Errors::ApiException => e
|
109
|
+
puts "Message: %s" % e.message
|
110
|
+
puts 'Errors:'
|
111
|
+
e.errors.each_with_index do |error, index|
|
112
|
+
puts "\tError [%d]:" % (index + 1)
|
113
|
+
error.each do |field, value|
|
114
|
+
puts "\t\t%s: %s" % [field, value]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
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 gets all labels. To create labels, run create_labels.rb
|
21
|
+
#
|
22
|
+
# This feature is only available to DFP premium solution networks.
|
23
|
+
#
|
24
|
+
# Tags: LabelService.getLabelsByStatement
|
25
|
+
|
26
|
+
require 'rubygems'
|
27
|
+
require 'dfp_api'
|
28
|
+
|
29
|
+
API_VERSION = :v201108
|
30
|
+
PAGE_SIZE = 500
|
31
|
+
|
32
|
+
def get_all_labels()
|
33
|
+
# Get DfpApi instance and load configuration from ~/dfp_api.yml.
|
34
|
+
dfp = DfpApi::Api.new
|
35
|
+
|
36
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
37
|
+
# the configuration file or provide your own logger:
|
38
|
+
# dfp.logger = Logger.new('dfp_xml.log')
|
39
|
+
|
40
|
+
# Get the LabelService.
|
41
|
+
label_service = dfp.service(:LabelService, API_VERSION)
|
42
|
+
|
43
|
+
# Define initial values.
|
44
|
+
offset = 0
|
45
|
+
page = {}
|
46
|
+
|
47
|
+
begin
|
48
|
+
# Create statement for one page with current offset.
|
49
|
+
statement = {:query => "LIMIT %d OFFSET %d" % [PAGE_SIZE, offset]}
|
50
|
+
|
51
|
+
# Get labels by statement.
|
52
|
+
page = label_service.get_labels_by_statement(statement)
|
53
|
+
|
54
|
+
if page[:results]
|
55
|
+
# Increase query offset by page size.
|
56
|
+
offset += PAGE_SIZE
|
57
|
+
|
58
|
+
# Get the start index for printout.
|
59
|
+
start_index = page[:start_index]
|
60
|
+
|
61
|
+
# Print details about each label in results page.
|
62
|
+
page[:results].each_with_index do |label, index|
|
63
|
+
puts "%d) Label ID: %d, name: %s, type: %s." %
|
64
|
+
[index + start_index, label[:id], label[:name], label[:type]]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end while offset < page[:total_result_set_size]
|
68
|
+
|
69
|
+
# Print a footer
|
70
|
+
if page.include?(:total_result_set_size)
|
71
|
+
puts "Total number of labels: %d" % page[:total_result_set_size]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
if __FILE__ == $0
|
76
|
+
begin
|
77
|
+
get_all_labels()
|
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,76 @@
|
|
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 a label by its ID. To determine which labels exist,
|
21
|
+
# run get_all_labels.rb.
|
22
|
+
#
|
23
|
+
# This feature is only available to DFP premium solution networks.
|
24
|
+
#
|
25
|
+
# Tags: LabelService.getLabel
|
26
|
+
|
27
|
+
require 'rubygems'
|
28
|
+
require 'dfp_api'
|
29
|
+
|
30
|
+
API_VERSION = :v201108
|
31
|
+
|
32
|
+
def get_label()
|
33
|
+
# Get DfpApi instance and load configuration from ~/dfp_api.yml.
|
34
|
+
dfp = DfpApi::Api.new
|
35
|
+
|
36
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
37
|
+
# the configuration file or provide your own logger:
|
38
|
+
# dfp.logger = Logger.new('dfp_xml.log')
|
39
|
+
|
40
|
+
# Get the LabelService.
|
41
|
+
label_service = dfp.service(:LabelService, API_VERSION)
|
42
|
+
|
43
|
+
# Set the ID of the label to get.
|
44
|
+
label_id = 'INSERT_LABEL_ID_HERE'.to_i
|
45
|
+
|
46
|
+
# Get the label.
|
47
|
+
label = label_service.get_label(label_id)
|
48
|
+
|
49
|
+
if label
|
50
|
+
puts "Label with ID: %d, name: %s and type %s was found." %
|
51
|
+
[label[:id], label[:name], label[:type]]
|
52
|
+
else
|
53
|
+
puts 'No label found for this ID.'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
if __FILE__ == $0
|
58
|
+
begin
|
59
|
+
get_label()
|
60
|
+
|
61
|
+
# HTTP errors.
|
62
|
+
rescue AdsCommon::Errors::HttpError => e
|
63
|
+
puts "HTTP Error: %s" % e
|
64
|
+
|
65
|
+
# API errors.
|
66
|
+
rescue DfpApi::Errors::ApiException => e
|
67
|
+
puts "Message: %s" % e.message
|
68
|
+
puts 'Errors:'
|
69
|
+
e.errors.each_with_index do |error, index|
|
70
|
+
puts "\tError [%d]:" % (index + 1)
|
71
|
+
error.each do |field, value|
|
72
|
+
puts "\t\t%s: %s" % [field, value]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,91 @@
|
|
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 labels that are competitively excluded. The statement
|
21
|
+
# retrieves up to the maximum page size limit of 500. To create labels, run
|
22
|
+
# create_labels.rb.
|
23
|
+
#
|
24
|
+
# This feature is only available to DFP premium solution networks.
|
25
|
+
#
|
26
|
+
# Tags: LabelService.getLabelsByStatement
|
27
|
+
|
28
|
+
require 'rubygems'
|
29
|
+
require 'dfp_api'
|
30
|
+
|
31
|
+
API_VERSION = :v201108
|
32
|
+
|
33
|
+
def get_labels_by_statement()
|
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 LabelService.
|
42
|
+
label_service = dfp.service(:LabelService, API_VERSION)
|
43
|
+
|
44
|
+
# Create a statement to only select active labels.
|
45
|
+
statement = {
|
46
|
+
:query => 'WHERE type = :type ORDER BY name LIMIT 500',
|
47
|
+
:values => [
|
48
|
+
{:key => 'type',
|
49
|
+
:value => {
|
50
|
+
:value => 'COMPETITIVE_EXCLUSION',
|
51
|
+
:xsi_type => 'TextValue'}
|
52
|
+
}
|
53
|
+
]
|
54
|
+
}
|
55
|
+
|
56
|
+
# Get labels by statement.
|
57
|
+
page = label_service.get_labels_by_statement(statement)
|
58
|
+
|
59
|
+
if page and page[:results]
|
60
|
+
page[:results].each_with_index do |label, index|
|
61
|
+
puts "%d) Label ID: %d, name: %s, type: %s." % [index,
|
62
|
+
label[:id], label[:name], label[:type]]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Print a footer.
|
67
|
+
if page.include?(:total_result_set_size)
|
68
|
+
puts "Number of results found: %d" % page[:total_result_set_size]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
if __FILE__ == $0
|
73
|
+
begin
|
74
|
+
get_labels_by_statement()
|
75
|
+
|
76
|
+
# HTTP errors.
|
77
|
+
rescue AdsCommon::Errors::HttpError => e
|
78
|
+
puts "HTTP Error: %s" % e
|
79
|
+
|
80
|
+
# API errors.
|
81
|
+
rescue DfpApi::Errors::ApiException => e
|
82
|
+
puts "Message: %s" % e.message
|
83
|
+
puts 'Errors:'
|
84
|
+
e.errors.each_with_index do |error, index|
|
85
|
+
puts "\tError [%d]:" % (index + 1)
|
86
|
+
error.each do |field, value|
|
87
|
+
puts "\t\t%s: %s" % [field, value]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|