google-adwords-api 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/examples/v201101/add_conversion.rb +97 -0
- data/examples/v201101/add_user_list.rb +28 -2
- data/examples/v201101/get_all_conversions.rb +88 -0
- data/examples/v201101/get_keyword_opportunities.rb +103 -0
- data/examples/v201101/update_conversion.rb +96 -0
- data/lib/adwords_api/api_config.rb +6 -3
- data/lib/adwords_api/errors.rb +4 -1
- data/lib/adwords_api/extensions.rb +1 -1
- data/lib/adwords_api/v13/AccountServiceDriver.rb +5 -5
- data/lib/adwords_api/v13/ReportServiceDriver.rb +7 -7
- data/lib/adwords_api/v13/TrafficEstimatorServiceDriver.rb +4 -4
- data/lib/adwords_api/v200909/AdExtensionOverrideServiceDriver.rb +2 -2
- data/lib/adwords_api/v200909/AdGroupAdServiceDriver.rb +2 -2
- data/lib/adwords_api/v200909/AdGroupCriterionService.rb +506 -506
- data/lib/adwords_api/v200909/AdGroupCriterionServiceDriver.rb +2 -2
- data/lib/adwords_api/v200909/AdGroupCriterionServiceMappingRegistry.rb +428 -428
- data/lib/adwords_api/v200909/AdGroupServiceDriver.rb +2 -2
- data/lib/adwords_api/v200909/AdParamServiceDriver.rb +2 -2
- data/lib/adwords_api/v200909/BulkMutateJobServiceDriver.rb +2 -2
- data/lib/adwords_api/v200909/CampaignAdExtensionServiceDriver.rb +2 -2
- data/lib/adwords_api/v200909/CampaignCriterionService.rb +133 -133
- data/lib/adwords_api/v200909/CampaignCriterionServiceDriver.rb +2 -2
- data/lib/adwords_api/v200909/CampaignCriterionServiceMappingRegistry.rb +184 -184
- data/lib/adwords_api/v200909/CampaignServiceDriver.rb +2 -2
- data/lib/adwords_api/v200909/CampaignTargetServiceDriver.rb +2 -2
- data/lib/adwords_api/v200909/GeoLocationServiceDriver.rb +1 -1
- data/lib/adwords_api/v200909/InfoServiceDriver.rb +1 -1
- data/lib/adwords_api/v200909/TargetingIdeaService.rb +907 -907
- data/lib/adwords_api/v200909/TargetingIdeaServiceDriver.rb +2 -2
- data/lib/adwords_api/v200909/TargetingIdeaServiceMappingRegistry.rb +384 -384
- data/lib/adwords_api/v201003/AdExtensionOverrideServiceDriver.rb +2 -2
- data/lib/adwords_api/v201003/AdGroupAdServiceDriver.rb +2 -2
- data/lib/adwords_api/v201003/AdGroupCriterionService.rb +527 -527
- data/lib/adwords_api/v201003/AdGroupCriterionServiceDriver.rb +2 -2
- data/lib/adwords_api/v201003/AdGroupCriterionServiceMappingRegistry.rb +469 -469
- data/lib/adwords_api/v201003/AdGroupServiceDriver.rb +2 -2
- data/lib/adwords_api/v201003/AdParamServiceDriver.rb +2 -2
- data/lib/adwords_api/v201003/BidLandscapeServiceDriver.rb +1 -1
- data/lib/adwords_api/v201003/BulkMutateJobServiceDriver.rb +2 -2
- data/lib/adwords_api/v201003/CampaignAdExtensionServiceDriver.rb +2 -2
- data/lib/adwords_api/v201003/CampaignCriterionService.rb +133 -133
- data/lib/adwords_api/v201003/CampaignCriterionServiceDriver.rb +2 -2
- data/lib/adwords_api/v201003/CampaignCriterionServiceMappingRegistry.rb +186 -186
- data/lib/adwords_api/v201003/CampaignServiceDriver.rb +2 -2
- data/lib/adwords_api/v201003/CampaignTargetServiceDriver.rb +2 -2
- data/lib/adwords_api/v201003/GeoLocationServiceDriver.rb +1 -1
- data/lib/adwords_api/v201003/InfoServiceDriver.rb +1 -1
- data/lib/adwords_api/v201003/MediaServiceDriver.rb +2 -2
- data/lib/adwords_api/v201003/ReportDefinitionServiceDriver.rb +3 -3
- data/lib/adwords_api/v201003/TargetingIdeaService.rb +1304 -1304
- data/lib/adwords_api/v201003/TargetingIdeaServiceDriver.rb +2 -2
- data/lib/adwords_api/v201003/TargetingIdeaServiceMappingRegistry.rb +401 -401
- data/lib/adwords_api/v201008/AdExtensionOverrideServiceDriver.rb +2 -2
- data/lib/adwords_api/v201008/AdGroupAdServiceDriver.rb +2 -2
- data/lib/adwords_api/v201008/AdGroupCriterionService.rb +598 -598
- data/lib/adwords_api/v201008/AdGroupCriterionServiceDriver.rb +2 -2
- data/lib/adwords_api/v201008/AdGroupCriterionServiceMappingRegistry.rb +680 -680
- data/lib/adwords_api/v201008/AdGroupServiceDriver.rb +2 -2
- data/lib/adwords_api/v201008/AdParamServiceDriver.rb +2 -2
- data/lib/adwords_api/v201008/AlertServiceDriver.rb +1 -1
- data/lib/adwords_api/v201008/BidLandscapeServiceDriver.rb +1 -1
- data/lib/adwords_api/v201008/BulkMutateJobServiceDriver.rb +2 -2
- data/lib/adwords_api/v201008/CampaignAdExtensionServiceDriver.rb +2 -2
- data/lib/adwords_api/v201008/CampaignCriterionService.rb +178 -178
- data/lib/adwords_api/v201008/CampaignCriterionServiceDriver.rb +2 -2
- data/lib/adwords_api/v201008/CampaignCriterionServiceMappingRegistry.rb +228 -228
- data/lib/adwords_api/v201008/CampaignServiceDriver.rb +2 -2
- data/lib/adwords_api/v201008/CampaignTargetServiceDriver.rb +2 -2
- data/lib/adwords_api/v201008/CustomerSyncServiceDriver.rb +1 -1
- data/lib/adwords_api/v201008/ExperimentServiceDriver.rb +2 -2
- data/lib/adwords_api/v201008/GeoLocationServiceDriver.rb +1 -1
- data/lib/adwords_api/v201008/InfoServiceDriver.rb +1 -1
- data/lib/adwords_api/v201008/MediaServiceDriver.rb +2 -2
- data/lib/adwords_api/v201008/ReportDefinitionServiceDriver.rb +3 -3
- data/lib/adwords_api/v201008/ServicedAccountServiceDriver.rb +1 -1
- data/lib/adwords_api/v201008/TargetingIdeaService.rb +1459 -1459
- data/lib/adwords_api/v201008/TargetingIdeaServiceDriver.rb +2 -2
- data/lib/adwords_api/v201008/TargetingIdeaServiceMappingRegistry.rb +447 -447
- data/lib/adwords_api/v201008/TrafficEstimatorService.rb +855 -855
- data/lib/adwords_api/v201008/TrafficEstimatorServiceDriver.rb +1 -1
- data/lib/adwords_api/v201008/TrafficEstimatorServiceMappingRegistry.rb +126 -126
- data/lib/adwords_api/v201008/UserListServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/AdExtensionOverrideServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/AdGroupAdService.rb +2 -0
- data/lib/adwords_api/v201101/AdGroupAdServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/AdGroupCriterionService.rb +700 -700
- data/lib/adwords_api/v201101/AdGroupCriterionServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/AdGroupCriterionServiceMappingRegistry.rb +670 -670
- data/lib/adwords_api/v201101/AdGroupServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/AdParamServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/AlertServiceDriver.rb +1 -1
- data/lib/adwords_api/v201101/BulkMutateJobService.rb +2 -0
- data/lib/adwords_api/v201101/BulkMutateJobServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/BulkOpportunityService.rb +1367 -0
- data/lib/adwords_api/v201101/BulkOpportunityServiceDriver.rb +55 -0
- data/lib/adwords_api/v201101/BulkOpportunityServiceMappingRegistry.rb +1668 -0
- data/lib/adwords_api/v201101/BulkOpportunityServiceWrapper.rb +303 -0
- data/lib/adwords_api/v201101/CampaignAdExtensionServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/CampaignCriterionService.rb +216 -216
- data/lib/adwords_api/v201101/CampaignCriterionServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/CampaignCriterionServiceMappingRegistry.rb +234 -234
- data/lib/adwords_api/v201101/CampaignServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/CampaignTargetServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/ConversionTrackerService.rb +1105 -0
- data/lib/adwords_api/v201101/ConversionTrackerServiceDriver.rb +63 -0
- data/lib/adwords_api/v201101/ConversionTrackerServiceMappingRegistry.rb +1161 -0
- data/lib/adwords_api/v201101/ConversionTrackerServiceWrapper.rb +332 -0
- data/lib/adwords_api/v201101/CustomerSyncServiceDriver.rb +1 -1
- data/lib/adwords_api/v201101/DataServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/ExperimentServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/GeoLocationServiceDriver.rb +1 -1
- data/lib/adwords_api/v201101/InfoServiceDriver.rb +1 -1
- data/lib/adwords_api/v201101/MediaServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/ReportDefinitionServiceDriver.rb +3 -3
- data/lib/adwords_api/v201101/ReportDefinitionServiceWrapper.rb +14 -0
- data/lib/adwords_api/v201101/ServicedAccountServiceDriver.rb +1 -1
- data/lib/adwords_api/v201101/TargetingIdeaService.rb +1490 -1490
- data/lib/adwords_api/v201101/TargetingIdeaServiceDriver.rb +2 -2
- data/lib/adwords_api/v201101/TargetingIdeaServiceMappingRegistry.rb +507 -507
- data/lib/adwords_api/v201101/TrafficEstimatorService.rb +841 -841
- data/lib/adwords_api/v201101/TrafficEstimatorServiceDriver.rb +1 -1
- data/lib/adwords_api/v201101/TrafficEstimatorServiceMappingRegistry.rb +126 -126
- data/lib/adwords_api/v201101/UserListServiceDriver.rb +2 -2
- metadata +17 -5
data/Rakefile
CHANGED
@@ -56,7 +56,7 @@ end
|
|
56
56
|
$GEM_DESCRIPTION = description
|
57
57
|
$GEM_AUTHORS = ['Sergio Gomes']
|
58
58
|
$GEM_EMAIL = 'api.sgomes@gmail.com'
|
59
|
-
$GEM_HOMEPAGE = 'http://code.google.com/p/google-api-
|
59
|
+
$GEM_HOMEPAGE = 'http://code.google.com/p/google-api-ads-ruby/'
|
60
60
|
|
61
61
|
|
62
62
|
# Configure code generation for the AdWords API client library.
|
@@ -0,0 +1,97 @@
|
|
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 add an AdWords conversion.
|
21
|
+
#
|
22
|
+
# Tags: ConversionTrackerService.mutate
|
23
|
+
|
24
|
+
require 'rubygems'
|
25
|
+
gem 'google-adwords-api'
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
API_VERSION = :v201101
|
29
|
+
|
30
|
+
def add_conversion()
|
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
|
+
conv_tracker_srv = adwords.service(:ConversionTrackerService, API_VERSION)
|
35
|
+
|
36
|
+
# Prepare for adding conversion.
|
37
|
+
operation = {
|
38
|
+
:operator => 'ADD',
|
39
|
+
:operand => {
|
40
|
+
# The 'xsi_type' field allows you to specify the xsi:type of the object
|
41
|
+
# being created. It's only necessary when you must provide an explicit
|
42
|
+
# type that the client library can't infer.
|
43
|
+
:xsi_type => 'AdWordsConversionTracker',
|
44
|
+
:name => 'Earth to Mars Cruises Conversion #%s' %
|
45
|
+
(Time.new.to_f * 1000).to_i,
|
46
|
+
:category => 'DEFAULT',
|
47
|
+
:markup_language => 'HTML',
|
48
|
+
:http_protocol => 'HTTP',
|
49
|
+
:text_format => 'HIDDEN'
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
# Add conversion.
|
54
|
+
response = conv_tracker_srv.mutate([operation])
|
55
|
+
if response and response[:value]
|
56
|
+
conversion = response[:value].first
|
57
|
+
puts "Conversion with id #{conversion[:id]}, name " +
|
58
|
+
"\"#{conversion[:name]}\", status \"#{conversion[:status]}\" and " +
|
59
|
+
" category \"#{conversion[:category]}\" was added."
|
60
|
+
else
|
61
|
+
puts 'No conversions were added.'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
if __FILE__ == $0
|
66
|
+
# To enable logging of SOAP requests, set the ADWORDSAPI_DEBUG environment
|
67
|
+
# variable to 'true'. This can be done either from your operating system
|
68
|
+
# environment or via code, as done below.
|
69
|
+
ENV['ADWORDSAPI_DEBUG'] = 'false'
|
70
|
+
|
71
|
+
begin
|
72
|
+
add_conversion()
|
73
|
+
|
74
|
+
# Connection error. Likely transitory.
|
75
|
+
rescue Errno::ECONNRESET, SOAP::HTTPStreamError, SocketError => e
|
76
|
+
puts 'Connection Error: %s' % e
|
77
|
+
puts 'Source: %s' % e.backtrace.first
|
78
|
+
|
79
|
+
# API Error.
|
80
|
+
rescue AdwordsApi::Errors::ApiException => e
|
81
|
+
puts 'API Exception caught.'
|
82
|
+
puts 'Message: %s' % e.message
|
83
|
+
puts 'Code: %d' % e.code if e.code
|
84
|
+
puts 'Trigger: %s' % e.trigger if e.trigger
|
85
|
+
puts 'Errors:'
|
86
|
+
if e.errors
|
87
|
+
e.errors.each_with_index do |error, index|
|
88
|
+
puts ' %d. Error type is %s. Fields:' % [index + 1, error[:xsi_type]]
|
89
|
+
error.each_pair do |field, value|
|
90
|
+
if field != :xsi_type
|
91
|
+
puts ' %s: %s' % [field, value]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -17,9 +17,10 @@
|
|
17
17
|
# See the License for the specific language governing permissions and
|
18
18
|
# limitations under the License.
|
19
19
|
#
|
20
|
-
# This example illustrates how to create a user list
|
20
|
+
# This example illustrates how to create a user list and show its associated
|
21
|
+
# conversion tracker code snippet.
|
21
22
|
#
|
22
|
-
# Tags: UserListService.mutate
|
23
|
+
# Tags: UserListService.mutate, ConversionTrackerService.get
|
23
24
|
|
24
25
|
require 'rubygems'
|
25
26
|
gem 'google-adwords-api'
|
@@ -32,6 +33,7 @@ def add_user_list()
|
|
32
33
|
# when called without parameters.
|
33
34
|
adwords = AdwordsApi::Api.new
|
34
35
|
user_list_srv = adwords.service(:UserListService, API_VERSION)
|
36
|
+
conv_tracker_srv = adwords.service(:ConversionTrackerService, API_VERSION)
|
35
37
|
|
36
38
|
# Prepare for adding remarketing user list.
|
37
39
|
name = 'Mars cruise customers #%s' % (Time.new.to_f * 1000).to_i
|
@@ -54,8 +56,32 @@ def add_user_list()
|
|
54
56
|
response = user_list_srv.mutate([operation])
|
55
57
|
if response and response[:value]
|
56
58
|
user_list = response[:value].first
|
59
|
+
|
60
|
+
# Get conversion snippets.
|
61
|
+
if user_list and user_list[:conversion_types]
|
62
|
+
conversion_ids = user_list[:conversion_types].map {|type| type[:id]}
|
63
|
+
selector = {
|
64
|
+
# We're actually interested in the 'Snippet' field, which is returned
|
65
|
+
# automatically.
|
66
|
+
:fields => ['Id'],
|
67
|
+
:predicates => [
|
68
|
+
{:field => 'Id', :operator => 'IN', :values => conversion_ids}
|
69
|
+
]
|
70
|
+
}
|
71
|
+
conv_tracker_response = conv_tracker_srv.get(selector)
|
72
|
+
if conv_tracker_response and conv_tracker_response[:entries]
|
73
|
+
conversions = conv_tracker_response[:entries]
|
74
|
+
end
|
75
|
+
end
|
57
76
|
puts 'User list with name "%s" and id %d was added.' %
|
58
77
|
[user_list[:name], user_list[:id]]
|
78
|
+
# Display user list associated conversion code snippets.
|
79
|
+
if conversions
|
80
|
+
conversions.each do |conversion|
|
81
|
+
puts "Conversion type code snipped associated to the list:\n%s\n" %
|
82
|
+
conversion[:snippet]
|
83
|
+
end
|
84
|
+
end
|
59
85
|
else
|
60
86
|
puts 'No user lists were added.'
|
61
87
|
end
|
@@ -0,0 +1,88 @@
|
|
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 conversions in the account. To add conversions, run
|
21
|
+
# add_conversion.rb.
|
22
|
+
#
|
23
|
+
# Tags: ConversionTrackerService.get
|
24
|
+
|
25
|
+
require 'rubygems'
|
26
|
+
gem 'google-adwords-api'
|
27
|
+
require 'adwords_api'
|
28
|
+
|
29
|
+
API_VERSION = :v201101
|
30
|
+
|
31
|
+
def get_all_conversions()
|
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
|
+
conv_tracker_srv = adwords.service(:ConversionTrackerService, API_VERSION)
|
36
|
+
|
37
|
+
# Get all conversions.
|
38
|
+
selector = {
|
39
|
+
:fields => ['Id', 'Name', 'Status', 'Category'],
|
40
|
+
:ordering => [{:field => 'Name', :sort_order => 'ASCENDING'}],
|
41
|
+
}
|
42
|
+
response = conv_tracker_srv.get(selector)
|
43
|
+
if response and response[:entries]
|
44
|
+
conversions = response[:entries]
|
45
|
+
puts "#{conversions.length} conversions(s) found."
|
46
|
+
conversions.each do |conversion|
|
47
|
+
puts " Conversion with id \"#{conversion[:id]}\", status \"" +
|
48
|
+
"#{conversion[:status]}\" and category \"#{conversion[:category]}\"" +
|
49
|
+
" was found. Code snippet: \n#{conversion[:snippet]}\n"
|
50
|
+
end
|
51
|
+
else
|
52
|
+
puts "No conversions found."
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if __FILE__ == $0
|
57
|
+
# To enable logging of SOAP requests, set the ADWORDSAPI_DEBUG environment
|
58
|
+
# variable to 'true'. This can be done either from your operating system
|
59
|
+
# environment or via code, as done below.
|
60
|
+
ENV['ADWORDSAPI_DEBUG'] = 'false'
|
61
|
+
|
62
|
+
begin
|
63
|
+
get_all_conversions()
|
64
|
+
|
65
|
+
# Connection error. Likely transitory.
|
66
|
+
rescue Errno::ECONNRESET, SOAP::HTTPStreamError, SocketError => e
|
67
|
+
puts 'Connection Error: %s' % e
|
68
|
+
puts 'Source: %s' % e.backtrace.first
|
69
|
+
|
70
|
+
# API Error.
|
71
|
+
rescue AdwordsApi::Errors::ApiException => e
|
72
|
+
puts 'API Exception caught.'
|
73
|
+
puts 'Message: %s' % e.message
|
74
|
+
puts 'Code: %d' % e.code if e.code
|
75
|
+
puts 'Trigger: %s' % e.trigger if e.trigger
|
76
|
+
puts 'Errors:'
|
77
|
+
if e.errors
|
78
|
+
e.errors.each_with_index do |error, index|
|
79
|
+
puts ' %d. Error type is %s. Fields:' % [index + 1, error[:xsi_type]]
|
80
|
+
error.each_pair do |field, value|
|
81
|
+
if field != :xsi_type
|
82
|
+
puts ' %s: %s' % [field, value]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
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 example reads all the keyword opportunities for the customer.
|
21
|
+
#
|
22
|
+
# Tags: BulkOpportunityService.get
|
23
|
+
|
24
|
+
require 'rubygems'
|
25
|
+
gem 'google-adwords-api'
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
API_VERSION = :v201101
|
29
|
+
PAGE_SIZE = 20
|
30
|
+
|
31
|
+
def get_keyword_opportunities()
|
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_opportunity_srv = adwords.service(:BulkOpportunityService, API_VERSION)
|
36
|
+
|
37
|
+
# Construct selector object.
|
38
|
+
selector = {
|
39
|
+
:requested_attribute_types => ['KEYWORD', 'IDEA_TYPE'],
|
40
|
+
:paging => {
|
41
|
+
:start_index => 0,
|
42
|
+
:number_results => PAGE_SIZE
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
# Perform request.
|
47
|
+
ideas = []
|
48
|
+
index = 0
|
49
|
+
begin
|
50
|
+
page = bulk_opportunity_srv.get(selector)
|
51
|
+
if page and page[:entries]
|
52
|
+
page[:entries].each do |entry|
|
53
|
+
ideas += entry[:opportunity_ideas] if entry[:opportunity_ideas]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
break if page[:total_num_entries] <= index
|
57
|
+
index += PAGE_SIZE
|
58
|
+
selector[:paging][:start_index] = index
|
59
|
+
end while page[:total_num_entries] > index
|
60
|
+
|
61
|
+
# Display results.
|
62
|
+
ideas.each do |idea|
|
63
|
+
data = AdwordsApi::Utils.map(idea[:data])
|
64
|
+
keyword = data['KEYWORD'][:value][:text]
|
65
|
+
idea_type = data['IDEA_TYPE'][:value]
|
66
|
+
puts " Found opportunity idea of type \"%s\": \"%s\"" % [idea_type, keyword]
|
67
|
+
end
|
68
|
+
puts "Total opportunity ideas: %d." % [ideas.length]
|
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_keyword_opportunities()
|
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
|
@@ -0,0 +1,96 @@
|
|
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 update a conversion by setting its status to
|
21
|
+
# 'DISABLED'. To get conversions, run get_all_conversions.rb.
|
22
|
+
#
|
23
|
+
# Tags: ConversionTrackerService.mutate
|
24
|
+
|
25
|
+
require 'rubygems'
|
26
|
+
gem 'google-adwords-api'
|
27
|
+
require 'adwords_api'
|
28
|
+
|
29
|
+
API_VERSION = :v201101
|
30
|
+
|
31
|
+
def update_conversion()
|
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
|
+
conv_tracker_srv = adwords.service(:ConversionTrackerService, API_VERSION)
|
36
|
+
|
37
|
+
conversion_id = 'INSERT_CONVERSION_ID_HERE'.to_i
|
38
|
+
|
39
|
+
# Prepare for updating conversion.
|
40
|
+
operation = {
|
41
|
+
:operator => 'SET',
|
42
|
+
:operand => {
|
43
|
+
# The 'xsi_type' field allows you to specify the xsi:type of the object
|
44
|
+
# being created. It's only necessary when you must provide an explicit
|
45
|
+
# type that the client library can't infer.
|
46
|
+
:xsi_type => 'AdWordsConversionTracker',
|
47
|
+
:id => conversion_id,
|
48
|
+
:status => 'DISABLED'
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
# Update conversion.
|
53
|
+
response = conv_tracker_srv.mutate([operation])
|
54
|
+
if response and response[:value]
|
55
|
+
conversion = response[:value].first
|
56
|
+
puts "Conversion with id #{conversion[:id]}, name " +
|
57
|
+
"\"#{conversion[:name]}\", status \"#{conversion[:status]}\" and " +
|
58
|
+
" category \"#{conversion[:category]}\" was disabled."
|
59
|
+
else
|
60
|
+
puts 'No conversions were updated.'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
if __FILE__ == $0
|
65
|
+
# To enable logging of SOAP requests, set the ADWORDSAPI_DEBUG environment
|
66
|
+
# variable to 'true'. This can be done either from your operating system
|
67
|
+
# environment or via code, as done below.
|
68
|
+
ENV['ADWORDSAPI_DEBUG'] = 'false'
|
69
|
+
|
70
|
+
begin
|
71
|
+
update_conversion()
|
72
|
+
|
73
|
+
# Connection error. Likely transitory.
|
74
|
+
rescue Errno::ECONNRESET, SOAP::HTTPStreamError, SocketError => e
|
75
|
+
puts 'Connection Error: %s' % e
|
76
|
+
puts 'Source: %s' % e.backtrace.first
|
77
|
+
|
78
|
+
# API Error.
|
79
|
+
rescue AdwordsApi::Errors::ApiException => e
|
80
|
+
puts 'API Exception caught.'
|
81
|
+
puts 'Message: %s' % e.message
|
82
|
+
puts 'Code: %d' % e.code if e.code
|
83
|
+
puts 'Trigger: %s' % e.trigger if e.trigger
|
84
|
+
puts 'Errors:'
|
85
|
+
if e.errors
|
86
|
+
e.errors.each_with_index do |error, index|
|
87
|
+
puts ' %d. Error type is %s. Fields:' % [index + 1, error[:xsi_type]]
|
88
|
+
error.each_pair do |field, value|
|
89
|
+
if field != :xsi_type
|
90
|
+
puts ' %s: %s' % [field, value]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|