google-adx-buyer-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 +2 -0
- data/README +208 -0
- data/Rakefile +50 -0
- data/examples/v201003/add_ad_group.rb +98 -0
- data/examples/v201003/add_ad_group_criteria.rb +100 -0
- data/examples/v201003/add_ads.rb +110 -0
- data/examples/v201003/add_campaign.rb +101 -0
- data/examples/v201003/add_negative_campaign_criterion.rb +95 -0
- data/examples/v201003/add_placement_performance_report_definition.rb +108 -0
- data/examples/v201003/check_campaigns.rb +132 -0
- data/examples/v201003/delete_ad.rb +94 -0
- data/examples/v201003/delete_ad_group.rb +86 -0
- data/examples/v201003/delete_ad_group_criterion.rb +95 -0
- data/examples/v201003/delete_campaign.rb +87 -0
- data/examples/v201003/download_report.rb +71 -0
- data/examples/v201003/get_all_active_ad_group_criteria.rb +93 -0
- data/examples/v201003/get_all_ad_group_criteria.rb +91 -0
- data/examples/v201003/get_all_ad_groups.rb +88 -0
- data/examples/v201003/get_all_ads.rb +91 -0
- data/examples/v201003/get_all_campaign_targets.rb +83 -0
- data/examples/v201003/get_all_campaigns.rb +83 -0
- data/examples/v201003/get_all_disapproved_ads.rb +94 -0
- data/examples/v201003/get_all_images.rb +88 -0
- data/examples/v201003/get_all_paused_campaigns.rb +86 -0
- data/examples/v201003/get_all_report_definitions.rb +84 -0
- data/examples/v201003/get_criterion_bid_landscape.rb +105 -0
- data/examples/v201003/get_geo_location_info.rb +108 -0
- data/examples/v201003/get_related_placements.rb +111 -0
- data/examples/v201003/get_report_fields.rb +81 -0
- data/examples/v201003/perform_bulk_mutate_job.rb +222 -0
- data/examples/v201003/set_campaign_targets.rb +124 -0
- data/examples/v201003/update_ad.rb +95 -0
- data/examples/v201003/update_ad_group.rb +90 -0
- data/examples/v201003/update_ad_group_criterion.rb +108 -0
- data/examples/v201003/update_campaign.rb +92 -0
- data/examples/v201003/upload_image.rb +97 -0
- data/examples/v201008/add_ad_group.rb +98 -0
- data/examples/v201008/add_ad_group_criteria.rb +100 -0
- data/examples/v201008/add_ads.rb +110 -0
- data/examples/v201008/add_campaign.rb +101 -0
- data/examples/v201008/add_experiment.rb +162 -0
- data/examples/v201008/add_negative_campaign_criterion.rb +95 -0
- data/examples/v201008/add_placement_performance_report_definition.rb +108 -0
- data/examples/v201008/add_user_list.rb +96 -0
- data/examples/v201008/check_campaigns.rb +132 -0
- data/examples/v201008/delete_ad.rb +94 -0
- data/examples/v201008/delete_ad_group.rb +86 -0
- data/examples/v201008/delete_ad_group_criterion.rb +95 -0
- data/examples/v201008/delete_bulk_mutate_job.rb +96 -0
- data/examples/v201008/delete_campaign.rb +87 -0
- data/examples/v201008/delete_experiment.rb +87 -0
- data/examples/v201008/delete_user_list.rb +87 -0
- data/examples/v201008/download_report.rb +71 -0
- data/examples/v201008/get_all_account_changes.rb +144 -0
- data/examples/v201008/get_all_active_ad_group_criteria.rb +93 -0
- data/examples/v201008/get_all_ad_group_criteria.rb +91 -0
- data/examples/v201008/get_all_ad_groups.rb +88 -0
- data/examples/v201008/get_all_ads.rb +91 -0
- data/examples/v201008/get_all_campaign_targets.rb +83 -0
- data/examples/v201008/get_all_campaigns.rb +83 -0
- data/examples/v201008/get_all_disapproved_ads.rb +94 -0
- data/examples/v201008/get_all_experiments.rb +93 -0
- data/examples/v201008/get_all_images.rb +88 -0
- data/examples/v201008/get_all_paused_campaigns.rb +86 -0
- data/examples/v201008/get_all_report_definitions.rb +84 -0
- data/examples/v201008/get_all_user_lists.rb +84 -0
- data/examples/v201008/get_bulk_mutate_job.rb +106 -0
- data/examples/v201008/get_campaign_alerts.rb +103 -0
- data/examples/v201008/get_criterion_bid_landscape.rb +105 -0
- data/examples/v201008/get_geo_location_info.rb +108 -0
- data/examples/v201008/get_related_placements.rb +114 -0
- data/examples/v201008/get_report_fields.rb +81 -0
- data/examples/v201008/perform_bulk_mutate_job.rb +222 -0
- data/examples/v201008/promote_experiment.rb +88 -0
- data/examples/v201008/set_campaign_targets.rb +124 -0
- data/examples/v201008/update_ad.rb +95 -0
- data/examples/v201008/update_ad_group.rb +90 -0
- data/examples/v201008/update_ad_group_criterion.rb +108 -0
- data/examples/v201008/update_campaign.rb +93 -0
- data/examples/v201008/update_user_list.rb +91 -0
- data/examples/v201008/upload_image.rb +97 -0
- data/examples/v201101/add_ad_group.rb +98 -0
- data/examples/v201101/add_ad_group_criteria.rb +100 -0
- data/examples/v201101/add_ads.rb +110 -0
- data/examples/v201101/add_campaign.rb +108 -0
- data/examples/v201101/add_conversion.rb +97 -0
- data/examples/v201101/add_experiment.rb +162 -0
- data/examples/v201101/add_negative_campaign_criterion.rb +95 -0
- data/examples/v201101/add_placement_performance_report_definition.rb +108 -0
- data/examples/v201101/add_rtb_campaign.rb +113 -0
- data/examples/v201101/add_user_list.rb +122 -0
- data/examples/v201101/check_campaigns.rb +132 -0
- data/examples/v201101/delete_ad.rb +94 -0
- data/examples/v201101/delete_ad_group.rb +86 -0
- data/examples/v201101/delete_ad_group_criterion.rb +95 -0
- data/examples/v201101/delete_bulk_mutate_job.rb +96 -0
- data/examples/v201101/delete_campaign.rb +87 -0
- data/examples/v201101/delete_experiment.rb +87 -0
- data/examples/v201101/delete_user_list.rb +87 -0
- data/examples/v201101/download_report.rb +71 -0
- data/examples/v201101/get_ad_group_bid_landscape.rb +103 -0
- data/examples/v201101/get_all_account_changes.rb +146 -0
- data/examples/v201101/get_all_active_ad_group_criteria.rb +106 -0
- data/examples/v201101/get_all_ad_group_criteria.rb +97 -0
- data/examples/v201101/get_all_ad_groups.rb +94 -0
- data/examples/v201101/get_all_ads.rb +99 -0
- data/examples/v201101/get_all_campaign_targets.rb +83 -0
- data/examples/v201101/get_all_campaigns.rb +86 -0
- data/examples/v201101/get_all_conversions.rb +88 -0
- data/examples/v201101/get_all_disapproved_ads.rb +102 -0
- data/examples/v201101/get_all_experiments.rb +98 -0
- data/examples/v201101/get_all_images.rb +90 -0
- data/examples/v201101/get_all_paused_campaigns.rb +92 -0
- data/examples/v201101/get_all_report_definitions.rb +84 -0
- data/examples/v201101/get_all_user_lists.rb +87 -0
- data/examples/v201101/get_bulk_mutate_job.rb +106 -0
- data/examples/v201101/get_campaign_alerts.rb +103 -0
- data/examples/v201101/get_criterion_bid_landscape.rb +102 -0
- data/examples/v201101/get_geo_location_info.rb +108 -0
- data/examples/v201101/get_related_placements.rb +114 -0
- data/examples/v201101/get_report_fields.rb +81 -0
- data/examples/v201101/perform_bulk_mutate_job.rb +222 -0
- data/examples/v201101/promote_experiment.rb +88 -0
- data/examples/v201101/set_campaign_targets.rb +111 -0
- data/examples/v201101/update_ad.rb +95 -0
- data/examples/v201101/update_ad_group.rb +90 -0
- data/examples/v201101/update_ad_group_criterion.rb +108 -0
- data/examples/v201101/update_campaign.rb +93 -0
- data/examples/v201101/update_conversion.rb +96 -0
- data/examples/v201101/update_user_list.rb +91 -0
- data/examples/v201101/upload_image.rb +97 -0
- metadata +208 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: api.sgomes@gmail.com (Sérgio Gomes)
|
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 illustrates how to retrieve all the paused campaigns for an
|
21
|
+
# account.
|
22
|
+
#
|
23
|
+
# Tags: CampaignService.get
|
24
|
+
|
25
|
+
require 'rubygems'
|
26
|
+
gem 'google-adwords-api'
|
27
|
+
require 'adwords_api'
|
28
|
+
|
29
|
+
API_VERSION = :v201101
|
30
|
+
|
31
|
+
def get_all_paused_campaigns()
|
32
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
33
|
+
# when called without parameters.
|
34
|
+
adwords = AdwordsApi::Api.new
|
35
|
+
campaign_srv = adwords.service(:CampaignService, API_VERSION)
|
36
|
+
|
37
|
+
# Get all the paused campaigns for this account.
|
38
|
+
selector = {
|
39
|
+
:fields => ['Id', 'Name', 'Status'],
|
40
|
+
:ordering => [{:field => 'Name', :sort_order => 'ASCENDING'}],
|
41
|
+
:predicates => [{
|
42
|
+
:field => 'Status',
|
43
|
+
:operator => 'IN',
|
44
|
+
:values => ['PAUSED']
|
45
|
+
}]
|
46
|
+
}
|
47
|
+
response = campaign_srv.get(selector)
|
48
|
+
|
49
|
+
if response and response[:entries]
|
50
|
+
campaigns = response[:entries]
|
51
|
+
campaigns.each do |campaign|
|
52
|
+
puts "Campaign name is \"#{campaign[:name]}\", id is #{campaign[:id]} " +
|
53
|
+
"and status is \"#{campaign[:status]}\"."
|
54
|
+
end
|
55
|
+
else
|
56
|
+
puts "No campaigns were found."
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if __FILE__ == $0
|
61
|
+
# To enable logging of SOAP requests, set the ADWORDSAPI_DEBUG environment
|
62
|
+
# variable to 'true'. This can be done either from your operating system
|
63
|
+
# environment or via code, as done below.
|
64
|
+
ENV['ADWORDSAPI_DEBUG'] = 'false'
|
65
|
+
|
66
|
+
begin
|
67
|
+
get_all_paused_campaigns()
|
68
|
+
|
69
|
+
# Connection error. Likely transitory.
|
70
|
+
rescue Errno::ECONNRESET, SOAP::HTTPStreamError, SocketError => e
|
71
|
+
puts 'Connection Error: %s' % e
|
72
|
+
puts 'Source: %s' % e.backtrace.first
|
73
|
+
|
74
|
+
# API Error.
|
75
|
+
rescue AdwordsApi::Errors::ApiException => e
|
76
|
+
puts 'API Exception caught.'
|
77
|
+
puts 'Message: %s' % e.message
|
78
|
+
puts 'Code: %d' % e.code if e.code
|
79
|
+
puts 'Trigger: %s' % e.trigger if e.trigger
|
80
|
+
puts 'Errors:'
|
81
|
+
if e.errors
|
82
|
+
e.errors.each_with_index do |error, index|
|
83
|
+
puts ' %d. Error type is %s. Fields:' % [index + 1, error[:xsi_type]]
|
84
|
+
error.each_pair do |field, value|
|
85
|
+
if field != :xsi_type
|
86
|
+
puts ' %s: %s' % [field, value]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: api.sgomes@gmail.com (Sérgio Gomes)
|
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 report definitions. To add a report definition, run
|
21
|
+
# add_keywords_performance_report.rb.
|
22
|
+
#
|
23
|
+
# Tags: ReportDefinitionService.get
|
24
|
+
|
25
|
+
require 'rubygems'
|
26
|
+
gem 'google-adwords-api'
|
27
|
+
require 'adwords_api'
|
28
|
+
|
29
|
+
API_VERSION = :v201101
|
30
|
+
|
31
|
+
def get_all_report_definitions()
|
32
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
33
|
+
# when called without parameters.
|
34
|
+
adwords = AdwordsApi::Api.new
|
35
|
+
report_def_srv = adwords.service(:ReportDefinitionService, API_VERSION)
|
36
|
+
|
37
|
+
# Get all the report definitions.
|
38
|
+
selector = {}
|
39
|
+
response = report_def_srv.get(selector)
|
40
|
+
if response and response[:entries]
|
41
|
+
entries = response[:entries]
|
42
|
+
puts "#{entries.length} report definition(s) found."
|
43
|
+
entries.each do |entry|
|
44
|
+
puts " Report definition id is #{entry[:id]} and name is " +
|
45
|
+
"\"#{entry[:report_name]}\"."
|
46
|
+
end
|
47
|
+
else
|
48
|
+
puts "No report definitions found."
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if __FILE__ == $0
|
53
|
+
# To enable logging of SOAP requests, set the ADWORDSAPI_DEBUG environment
|
54
|
+
# variable to 'true'. This can be done either from your operating system
|
55
|
+
# environment or via code, as done below.
|
56
|
+
ENV['ADWORDSAPI_DEBUG'] = 'false'
|
57
|
+
|
58
|
+
begin
|
59
|
+
get_all_report_definitions()
|
60
|
+
|
61
|
+
# Connection error. Likely transitory.
|
62
|
+
rescue Errno::ECONNRESET, SOAP::HTTPStreamError, SocketError => e
|
63
|
+
puts 'Connection Error: %s' % e
|
64
|
+
puts 'Source: %s' % e.backtrace.first
|
65
|
+
|
66
|
+
# API Error.
|
67
|
+
rescue AdwordsApi::Errors::ApiException => e
|
68
|
+
puts 'API Exception caught.'
|
69
|
+
puts 'Message: %s' % e.message
|
70
|
+
puts 'Code: %d' % e.code if e.code
|
71
|
+
puts 'Trigger: %s' % e.trigger if e.trigger
|
72
|
+
puts 'Errors:'
|
73
|
+
if e.errors
|
74
|
+
e.errors.each_with_index do |error, index|
|
75
|
+
puts ' %d. Error type is %s. Fields:' % [index + 1, error[:xsi_type]]
|
76
|
+
error.each_pair do |field, value|
|
77
|
+
if field != :xsi_type
|
78
|
+
puts ' %s: %s' % [field, value]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: api.sgomes@gmail.com (Sérgio Gomes)
|
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 illustrates how to retrieve all the user lists for an account.
|
21
|
+
#
|
22
|
+
# Tags: UserListService.get
|
23
|
+
|
24
|
+
require 'rubygems'
|
25
|
+
gem 'google-adwords-api'
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
API_VERSION = :v201101
|
29
|
+
|
30
|
+
def get_all_user_lists()
|
31
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
32
|
+
# when called without parameters.
|
33
|
+
adwords = AdwordsApi::Api.new
|
34
|
+
user_list_srv = adwords.service(:UserListService, API_VERSION)
|
35
|
+
|
36
|
+
# Get all the user lists for this account.
|
37
|
+
selector = {
|
38
|
+
:fields => ['Id', 'Name', 'Status', 'Size'],
|
39
|
+
:ordering => [{:field => 'Name', :sort_order => 'ASCENDING'}]
|
40
|
+
}
|
41
|
+
response = user_list_srv.get(selector)
|
42
|
+
|
43
|
+
if response and response[:entries]
|
44
|
+
user_lists = response[:entries]
|
45
|
+
user_lists.each do |user_list|
|
46
|
+
puts "User list name is \"#{user_list[:name]}\", id is " +
|
47
|
+
"#{user_list[:id]}, status is \"#{user_list[:status]}\" and number " +
|
48
|
+
"of users is #{user_list[:size]}."
|
49
|
+
end
|
50
|
+
else
|
51
|
+
puts "No user lists were found."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
if __FILE__ == $0
|
56
|
+
# To enable logging of SOAP requests, set the ADWORDSAPI_DEBUG environment
|
57
|
+
# variable to 'true'. This can be done either from your operating system
|
58
|
+
# environment or via code, as done below.
|
59
|
+
ENV['ADWORDSAPI_DEBUG'] = 'false'
|
60
|
+
|
61
|
+
begin
|
62
|
+
get_all_user_lists()
|
63
|
+
|
64
|
+
# Connection error. Likely transitory.
|
65
|
+
rescue Errno::ECONNRESET, SOAP::HTTPStreamError, SocketError => e
|
66
|
+
puts 'Connection Error: %s' % e
|
67
|
+
puts 'Source: %s' % e.backtrace.first
|
68
|
+
|
69
|
+
# API Error.
|
70
|
+
rescue AdwordsApi::Errors::ApiException => e
|
71
|
+
puts 'API Exception caught.'
|
72
|
+
puts 'Message: %s' % e.message
|
73
|
+
puts 'Code: %d' % e.code if e.code
|
74
|
+
puts 'Trigger: %s' % e.trigger if e.trigger
|
75
|
+
puts 'Errors:'
|
76
|
+
if e.errors
|
77
|
+
e.errors.each_with_index do |error, index|
|
78
|
+
puts ' %d. Error type is %s. Fields:' % [index + 1, error[:xsi_type]]
|
79
|
+
error.each_pair do |field, value|
|
80
|
+
if field != :xsi_type
|
81
|
+
puts ' %s: %s' % [field, value]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: api.sgomes@gmail.com (Sérgio Gomes)
|
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 bulk mutate job and prints out its stats information.
|
21
|
+
# To add a bulk mutate job, run perform_bulk_mutate_job.rb.
|
22
|
+
#
|
23
|
+
# Tags: BulkMutateJobService.get
|
24
|
+
|
25
|
+
require 'rubygems'
|
26
|
+
gem 'google-adwords-api'
|
27
|
+
require 'adwords_api'
|
28
|
+
|
29
|
+
API_VERSION = :v201101
|
30
|
+
|
31
|
+
def get_all_bulk_mutate_jobs()
|
32
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
33
|
+
# when called without parameters.
|
34
|
+
adwords = AdwordsApi::Api.new
|
35
|
+
bulk_mutate_job_srv = adwords.service(:BulkMutateJobService, API_VERSION)
|
36
|
+
|
37
|
+
# Replace with valid values of your account.
|
38
|
+
bulk_mutate_job_id = "INSERT_BULK_MUTATE_JOB_ID_HERE"
|
39
|
+
|
40
|
+
# Get all the bulk mutate jobs.
|
41
|
+
selector = {
|
42
|
+
:include_stats => true,
|
43
|
+
:job_ids => [bulk_mutate_job_id]
|
44
|
+
}
|
45
|
+
jobs = bulk_mutate_job_srv.get(selector)
|
46
|
+
|
47
|
+
if jobs
|
48
|
+
jobs.each do |job|
|
49
|
+
puts "Bulk mutate job with id %d and status '%s' was found." %
|
50
|
+
[job[:id], job[:status]]
|
51
|
+
|
52
|
+
case job[:status]
|
53
|
+
when 'PENDING'
|
54
|
+
puts " Total parts: %d, parts received: %d." %
|
55
|
+
[job[:num_request_parts], job[:num_request_parts_received]]
|
56
|
+
when 'PROCESSING'
|
57
|
+
if job[:stats]
|
58
|
+
puts " Percent complete: %d." % job[:stats][:progress_percent]
|
59
|
+
end
|
60
|
+
when 'COMPLETED'
|
61
|
+
if job[:stats]
|
62
|
+
puts " Total operations: %d, failed: %d, unprocessed %d." %
|
63
|
+
[job[:stats][:num_operations],
|
64
|
+
job[:stats][:num_failed_operations],
|
65
|
+
job[:stats][:num_unprocessed_operations]]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
else
|
70
|
+
puts "No bulk mutate jobs were found."
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
if __FILE__ == $0
|
75
|
+
# To enable logging of SOAP requests, set the ADWORDSAPI_DEBUG environment
|
76
|
+
# variable to 'true'. This can be done either from your operating system
|
77
|
+
# environment or via code, as done below.
|
78
|
+
ENV['ADWORDSAPI_DEBUG'] = 'false'
|
79
|
+
|
80
|
+
begin
|
81
|
+
get_all_bulk_mutate_jobs()
|
82
|
+
|
83
|
+
# Connection error. Likely transitory.
|
84
|
+
rescue Errno::ECONNRESET, SOAP::HTTPStreamError, SocketError => e
|
85
|
+
puts 'Connection Error: %s' % e
|
86
|
+
puts 'Source: %s' % e.backtrace.first
|
87
|
+
|
88
|
+
# API Error.
|
89
|
+
rescue AdwordsApi::Errors::ApiException => e
|
90
|
+
puts 'API Exception caught.'
|
91
|
+
puts 'Message: %s' % e.message
|
92
|
+
puts 'Code: %d' % e.code if e.code
|
93
|
+
puts 'Trigger: %s' % e.trigger if e.trigger
|
94
|
+
puts 'Errors:'
|
95
|
+
if e.errors
|
96
|
+
e.errors.each_with_index do |error, index|
|
97
|
+
puts ' %d. Error type is %s. Fields:' % [index + 1, error[:xsi_type]]
|
98
|
+
error.each_pair do |field, value|
|
99
|
+
if field != :xsi_type
|
100
|
+
puts ' %s: %s' % [field, value]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: api.sgomes@gmail.com (Sérgio Gomes)
|
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 code example illustrates how to retrieve campaign alerts for a user.
|
21
|
+
# The alerts are restricted to a maximum of 10 entries.
|
22
|
+
#
|
23
|
+
# Tags: AlertService.get
|
24
|
+
|
25
|
+
require 'rubygems'
|
26
|
+
gem 'google-adwords-api'
|
27
|
+
require 'adwords_api'
|
28
|
+
|
29
|
+
API_VERSION = :v201101
|
30
|
+
|
31
|
+
def get_campaign_alerts()
|
32
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
33
|
+
# when called without parameters.
|
34
|
+
adwords = AdwordsApi::Api.new
|
35
|
+
alert_srv = adwords.service(:AlertService, API_VERSION)
|
36
|
+
|
37
|
+
# Create the selector.
|
38
|
+
selector = {
|
39
|
+
:query => {
|
40
|
+
:filter_spec => 'ALL',
|
41
|
+
:client_spec => 'ALL',
|
42
|
+
:trigger_time_spec => 'ALL_TIME',
|
43
|
+
:severities => ['GREEN', 'YELLOW', 'RED'],
|
44
|
+
:types => ['CAMPAIGN_ENDING', 'CAMPAIGN_ENDED']
|
45
|
+
},
|
46
|
+
:paging => {
|
47
|
+
:start_index => 0,
|
48
|
+
:number_results => 10
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
# Get alerts.
|
53
|
+
response = alert_srv.get(selector)
|
54
|
+
|
55
|
+
if response and response[:entries]
|
56
|
+
alerts = response[:entries]
|
57
|
+
alerts.each_with_index do |alert, index|
|
58
|
+
puts "{index}) Customer Id is " +
|
59
|
+
"#{AdwordsApi::Utils.format_id(alert[:client_customer_id])}, " +
|
60
|
+
"alert type is '#{alert[:alert_type]}', severity is " +
|
61
|
+
"#{alert[:alert_severity]}."
|
62
|
+
alert[:details].each do |detail|
|
63
|
+
puts " - triggered at #{detail[:trigger_time]}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
else
|
67
|
+
puts "No alerts were found."
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
if __FILE__ == $0
|
72
|
+
# To enable logging of SOAP requests, set the ADWORDSAPI_DEBUG environment
|
73
|
+
# variable to 'true'. This can be done either from your operating system
|
74
|
+
# environment or via code, as done below.
|
75
|
+
ENV['ADWORDSAPI_DEBUG'] = 'false'
|
76
|
+
|
77
|
+
begin
|
78
|
+
get_campaign_alerts()
|
79
|
+
|
80
|
+
# Connection error. Likely transitory.
|
81
|
+
rescue Errno::ECONNRESET, SOAP::HTTPStreamError, SocketError => e
|
82
|
+
puts 'Connection Error: %s' % e
|
83
|
+
puts 'Source: %s' % e.backtrace.first
|
84
|
+
|
85
|
+
# API Error.
|
86
|
+
rescue AdwordsApi::Errors::ApiException => e
|
87
|
+
puts 'API Exception caught.'
|
88
|
+
puts 'Message: %s' % e.message
|
89
|
+
puts 'Code: %d' % e.code if e.code
|
90
|
+
puts 'Trigger: %s' % e.trigger if e.trigger
|
91
|
+
puts 'Errors:'
|
92
|
+
if e.errors
|
93
|
+
e.errors.each_with_index do |error, index|
|
94
|
+
puts ' %d. Error type is %s. Fields:' % [index + 1, error[:xsi_type]]
|
95
|
+
error.each_pair do |field, value|
|
96
|
+
if field != :xsi_type
|
97
|
+
puts ' %s: %s' % [field, value]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|