adwords4r 11.1.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog.txt +4 -0
- data/Rakefile +76 -70
- data/examples/campaign.rb +40 -0
- data/examples/{old/framework.rb → framework.rb} +0 -0
- data/examples/{old/get_free_usage_this_month.rb → get_free_usage_this_month.rb} +8 -6
- data/examples/get_unit_count.rb +21 -0
- data/examples/keyword_suggestions.rb +179 -0
- data/examples/keyword_tool_demo.rb +31 -0
- data/examples/reports.rb +6 -6
- data/examples/traffic_estimator.rb +34 -0
- data/lib/adwords4r.rb +26 -19
- data/lib/adwords4r/credentials.rb +4 -2
- data/lib/adwords4r/services.rb +4 -2
- data/lib/adwords4r/v11/AccountServiceDriver.rb +3 -3
- data/lib/adwords4r/v11/AdGroupServiceDriver.rb +8 -8
- data/lib/adwords4r/v11/AdServiceDriver.rb +10 -10
- data/lib/adwords4r/v11/CampaignServiceDriver.rb +10 -10
- data/lib/adwords4r/v11/CriterionServiceDriver.rb +9 -9
- data/lib/adwords4r/v11/InfoServiceDriver.rb +8 -8
- data/lib/adwords4r/v11/KeywordToolServiceDriver.rb +2 -2
- data/lib/adwords4r/v11/ReportServiceDriver.rb +7 -7
- data/lib/adwords4r/v11/SiteSuggestionServiceDriver.rb +4 -4
- data/lib/adwords4r/v11/TrafficEstimatorServiceDriver.rb +4 -4
- data/lib/adwords4r/{v10 → v12}/AccountService.rb +13 -32
- data/lib/adwords4r/{v10 → v12}/AccountServiceDriver.rb +12 -20
- data/lib/adwords4r/{v10 → v12}/AccountServiceMappingRegistry.rb +23 -38
- data/lib/adwords4r/{v10 → v12}/AdGroupService.rb +43 -37
- data/lib/adwords4r/{v10 → v12}/AdGroupServiceDriver.rb +27 -27
- data/lib/adwords4r/{v10 → v12}/AdGroupServiceMappingRegistry.rb +46 -42
- data/lib/adwords4r/{v10 → v12}/AdService.rb +68 -56
- data/lib/adwords4r/{v10 → v12}/AdServiceDriver.rb +33 -33
- data/lib/adwords4r/{v10 → v12}/AdServiceMappingRegistry.rb +113 -105
- data/lib/adwords4r/{v10 → v12}/CampaignService.rb +99 -44
- data/lib/adwords4r/{v10 → v12}/CampaignServiceDriver.rb +41 -33
- data/lib/adwords4r/{v10 → v12}/CampaignServiceMappingRegistry.rb +143 -65
- data/lib/adwords4r/{v10 → v12}/CriterionService.rb +46 -43
- data/lib/adwords4r/{v10 → v12}/CriterionServiceDriver.rb +30 -30
- data/lib/adwords4r/{v10 → v12}/CriterionServiceMappingRegistry.rb +67 -65
- data/lib/adwords4r/{v10 → v12}/InfoService.rb +19 -19
- data/lib/adwords4r/{v10 → v12}/InfoServiceDriver.rb +27 -27
- data/lib/adwords4r/{v10 → v12}/InfoServiceMappingRegistry.rb +25 -25
- data/lib/adwords4r/{v10 → v12}/KeywordToolService.rb +12 -12
- data/lib/adwords4r/{v10 → v12}/KeywordToolServiceDriver.rb +9 -9
- data/lib/adwords4r/{v10 → v12}/KeywordToolServiceMappingRegistry.rb +23 -23
- data/lib/adwords4r/v12/ReportService.rb +322 -0
- data/lib/adwords4r/{v10 → v12}/ReportServiceDriver.rb +29 -21
- data/lib/adwords4r/v12/ReportServiceMappingRegistry.rb +298 -0
- data/lib/adwords4r/{v10 → v12}/SiteSuggestionService.rb +18 -18
- data/lib/adwords4r/{v10 → v12}/SiteSuggestionServiceDriver.rb +15 -15
- data/lib/adwords4r/{v10 → v12}/SiteSuggestionServiceMappingRegistry.rb +45 -45
- data/lib/adwords4r/{v10 → v12}/TrafficEstimatorService.rb +29 -29
- data/lib/adwords4r/{v10 → v12}/TrafficEstimatorServiceDriver.rb +15 -15
- data/lib/adwords4r/{v10 → v12}/TrafficEstimatorServiceMappingRegistry.rb +55 -55
- data/svn-commit.2.tmp +60 -0
- data/svn-commit.tmp +60 -0
- metadata +41 -38
- data/examples/old/campaign.rb +0 -40
- data/examples/old/get_unit_count.rb +0 -21
- data/examples/old/keyword_tool_demo.rb +0 -30
- data/examples/old/traffic_estimator.rb +0 -34
- data/lib/adwords4r/v10/ReportService.rb +0 -652
- data/lib/adwords4r/v10/ReportServiceMappingRegistry.rb +0 -559
data/ChangeLog.txt
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
12.0.0
|
2
|
+
- Added support for v12 of the AdWords API.
|
3
|
+
Removed support for v10 of the API, which has been deco'ed.
|
4
|
+
|
1
5
|
11.1.0
|
2
6
|
- Added additional attributes to the AdWords::Error::ApiError class.
|
3
7
|
This should make it easier to get all the useful SOAP fault information, some of which wasn't available in the previous version.
|
data/Rakefile
CHANGED
@@ -16,7 +16,7 @@ require 'lib/adwords4r/services'
|
|
16
16
|
|
17
17
|
CLOBBER.include('pkg')
|
18
18
|
|
19
|
-
CURRENT_VERSION = '
|
19
|
+
CURRENT_VERSION = '12.0.0'
|
20
20
|
PKG_VERSION = ENV['REL'] ? ENV['REL'] : CURRENT_VERSION
|
21
21
|
|
22
22
|
SRC_RB = FileList['lib/**/*.rb']
|
@@ -29,8 +29,8 @@ logger = Logger.new(STDERR)
|
|
29
29
|
|
30
30
|
CLEAN.include(WSDLDIR)
|
31
31
|
AdWords::Service.getVersions.each do |v|
|
32
|
-
|
33
|
-
|
32
|
+
vname = "v#{v}"
|
33
|
+
CLEAN.include(File.join(GENDIR, vname))
|
34
34
|
end
|
35
35
|
|
36
36
|
desc "gets the wsdl and generates the classes"
|
@@ -38,73 +38,77 @@ task :default => [:getwsdl, :generate]
|
|
38
38
|
|
39
39
|
desc "gets the wsdl files for AdWords services"
|
40
40
|
task :getwsdl do
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
AdWords::Service.getVersions.each do |v|
|
42
|
+
vname = "v#{v}"
|
43
|
+
mkdir_p File.join(WSDLDIR, vname)
|
44
|
+
AdWords::Service.getServices(v).each {|s|
|
45
|
+
save(getfile("adwords.google.com",
|
46
|
+
"/api/adwords/#{vname}/#{s}Service?wsdl"),
|
47
|
+
getWsdlFileName(vname,s))}
|
48
|
+
end
|
46
49
|
end
|
47
50
|
|
48
51
|
desc "generates AdWords classes from the wsdl files"
|
49
52
|
task :generate do
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
53
|
+
AdWords::Service.getVersions.each do |v|
|
54
|
+
vname = "v#{v}"
|
55
|
+
gendir = "#{LIBDIR}/adwords4r/#{vname}"
|
56
|
+
mkdir_p gendir
|
57
|
+
AdWords::Service.getServices(v).each do |name|
|
58
|
+
worker = WSDL::SOAP::WSDL2Ruby.new
|
59
|
+
worker.logger = logger
|
60
|
+
worker.location = getWsdlFileName(vname,name)
|
61
|
+
worker.basedir = gendir
|
62
|
+
worker.opt.update(getWsdlOpt(name))
|
63
|
+
worker.run
|
64
|
+
fixImport(v, File.join(gendir, "#{name}Driver.rb"))
|
65
|
+
fixImport(v, File.join(gendir, "#{name}MappingRegistry.rb"))
|
66
|
+
fixImport(v, File.join(gendir, "#{name}.rb"))
|
65
67
|
end
|
68
|
+
end
|
66
69
|
end
|
67
70
|
|
68
71
|
def fixImport(version, file)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
72
|
+
vname = "v#{version}"
|
73
|
+
tempfile = file + '.tmp'
|
74
|
+
outfile = File.new(tempfile,"w")
|
75
|
+
File.open(file, "r") do |infile|
|
76
|
+
infile.each do |l|
|
77
|
+
if (l =~ /require.*Service.*\.rb/) then
|
78
|
+
outfile.puts l.gsub(/require '(.*)Service(.*)\.rb'/,
|
79
|
+
"require 'adwords4r/#{vname}/\\1Service\\2'")
|
80
|
+
else
|
81
|
+
outfile.puts l
|
82
|
+
end
|
80
83
|
end
|
81
|
-
|
82
|
-
|
84
|
+
end
|
85
|
+
outfile.close
|
86
|
+
File.rename(tempfile, file)
|
83
87
|
end
|
84
88
|
|
85
89
|
def getWsdlOpt(s)
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
# Causes soap4r to wrap the classes it outputs into the given modules
|
94
|
-
optcmd['module_path'] = ['AdWords', s]
|
95
|
-
return optcmd
|
96
|
-
end
|
90
|
+
optcmd= {}
|
91
|
+
s << "Service"
|
92
|
+
optcmd['classdef'] = s
|
93
|
+
optcmd['force'] = true
|
94
|
+
optcmd['mapping_registry'] = true
|
95
|
+
optcmd['driver'] = nil
|
97
96
|
|
97
|
+
# Causes soap4r to wrap the classes it outputs into the given modules
|
98
|
+
optcmd['module_path'] = ['AdWords', s]
|
99
|
+
return optcmd
|
100
|
+
end
|
101
|
+
|
98
102
|
def getWsdlFileName(v,s)
|
99
|
-
|
103
|
+
"#{WSDLDIR}/#{v}/#{s}.wsdl"
|
100
104
|
end
|
101
|
-
|
105
|
+
|
102
106
|
def getfile(host, path)
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
107
|
+
puts "getting https//#{host}#{path}"
|
108
|
+
https = Net::HTTP.new(host, 443)
|
109
|
+
https.use_ssl = true
|
110
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
111
|
+
https.start { |w| w.get2(path).body }
|
108
112
|
end
|
109
113
|
|
110
114
|
def fix_attribute(text, name, type)
|
@@ -112,21 +116,23 @@ def fix_attribute(text, name, type)
|
|
112
116
|
end
|
113
117
|
|
114
118
|
def fixWsdl(wsdl)
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
119
|
+
['type', 'base'].each {|name|
|
120
|
+
['long', 'string', 'date', 'int', 'boolean'].each {|type|
|
121
|
+
fix_attribute(wsdl, name, type)}}
|
122
|
+
schema_ns = "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
|
123
|
+
if wsdl !~ Regexp.new(schema_ns)
|
124
|
+
wsdl.gsub!(/(<wsdl:definitions[^>]*)>/, '\1 ' + schema_ns + '>')
|
125
|
+
end
|
126
|
+
return wsdl
|
127
|
+
#wsdl.gsub(/type=\"long\"/, 'type="xsd:long"')
|
122
128
|
end
|
123
129
|
|
124
130
|
# Saves this document to the specified @var path.
|
125
131
|
#doesn't create the file if contains markup for google 404 page
|
126
132
|
def save(content, path)
|
127
|
-
|
128
|
-
|
129
|
-
|
133
|
+
if content !~ /<H2>Error 404<\/H2>/
|
134
|
+
File::open(path, 'w') {|f| f.write(fixWsdl(content))}
|
135
|
+
end
|
130
136
|
end
|
131
137
|
|
132
138
|
# ====================================================================
|
@@ -138,7 +144,7 @@ PKG_FILES = FileList[
|
|
138
144
|
'Rakefile',
|
139
145
|
'lib/**/*.rb',
|
140
146
|
'examples/**/*.rb',
|
141
|
-
# 'test/**/*.rb',
|
147
|
+
# 'test/**/*.rb',
|
142
148
|
'scripts/**/*.rb'
|
143
149
|
]
|
144
150
|
|
@@ -152,7 +158,7 @@ else
|
|
152
158
|
spec = Gem::Specification.new do |s|
|
153
159
|
|
154
160
|
#### Basic information.
|
155
|
-
|
161
|
+
|
156
162
|
s.name = 'adwords4r'
|
157
163
|
s.version = PKG_VERSION
|
158
164
|
s.summary = "Client library for the AdWords API."
|
@@ -163,7 +169,7 @@ Currently the following AdWords API versions are supported:\
|
|
163
169
|
* V10\
|
164
170
|
* V11\
|
165
171
|
}
|
166
|
-
|
172
|
+
|
167
173
|
s.files = PKG_FILES.to_a
|
168
174
|
s.require_path = 'lib'
|
169
175
|
s.autorequire = 'adwords4r'
|
@@ -174,9 +180,9 @@ Currently the following AdWords API versions are supported:\
|
|
174
180
|
s.has_rdoc = false
|
175
181
|
#s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
|
176
182
|
#s.rdoc_options <<
|
177
|
-
# '--title' << 'Builder -- Easy XML Building' <<
|
178
|
-
# '--main' << 'README' <<
|
179
|
-
# '--line-numbers'
|
183
|
+
# '--title' << 'Builder -- Easy XML Building' <<
|
184
|
+
# '--main' << 'README' <<
|
185
|
+
# '--line-numbers'
|
180
186
|
|
181
187
|
s.author = "Jeffrey Posnick, Patrick Chanezon, Ryan Leavengood"
|
182
188
|
s.email = "jeffy@google.com"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Use adwords4r in parent dir
|
4
|
+
$LOAD_PATH.unshift '../lib/'
|
5
|
+
|
6
|
+
require 'adwords4r'
|
7
|
+
|
8
|
+
SEP = "---"
|
9
|
+
|
10
|
+
def dumpObj(o)
|
11
|
+
str = ""
|
12
|
+
o.instance_variables.each { |v| str << dumpAttr(o, v)}
|
13
|
+
return str << SEP
|
14
|
+
end
|
15
|
+
|
16
|
+
def dumpAttr(o, v)
|
17
|
+
name = v.sub(/@/,'')
|
18
|
+
value = eval("o.#{name}.to_s")
|
19
|
+
return "#{name}: #{value}\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
begin
|
23
|
+
adwords = AdWords::API.new
|
24
|
+
|
25
|
+
res = adwords.getAllAdWordsCampaigns(123).getAllAdWordsCampaignsReturn
|
26
|
+
res.each {|c| puts dumpObj(c)}
|
27
|
+
|
28
|
+
c = AdWords::Campaign.new
|
29
|
+
c.dailyBudget = 10000
|
30
|
+
c.status = 'Paused'
|
31
|
+
c.name = "Test Campaign #{rand(10000)}"
|
32
|
+
c.endDay = SOAP::SOAPDate.new("2010-01-01")
|
33
|
+
puts dumpObj(adwords.addCampaign(c).addCampaignReturn)
|
34
|
+
|
35
|
+
rescue AdWords::Error::UnknownAPICall => e
|
36
|
+
puts e
|
37
|
+
rescue AdWords::Error::ApiError => e
|
38
|
+
puts e.code
|
39
|
+
puts e.message
|
40
|
+
end
|
File without changes
|
@@ -6,13 +6,15 @@ $LOAD_PATH.unshift '../lib/'
|
|
6
6
|
require 'adwords4r'
|
7
7
|
|
8
8
|
begin
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
adwords = AdWords::API.new
|
10
|
+
result = adwords.getFreeUsageQuotaThisMonth().
|
11
|
+
getFreeUsageQuotaThisMonthReturn
|
12
|
+
puts "result = #{result}"
|
13
|
+
|
12
14
|
rescue AdWords::Error::UnknownAPICall => e
|
13
|
-
|
15
|
+
puts e
|
14
16
|
rescue AdWords::Error::ApiError => e
|
15
|
-
|
16
|
-
|
17
|
+
puts e.code
|
18
|
+
puts e.message
|
17
19
|
end
|
18
20
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Use adwords4r in parent dir
|
4
|
+
$LOAD_PATH.unshift '../lib/'
|
5
|
+
|
6
|
+
require 'adwords4r'
|
7
|
+
|
8
|
+
begin
|
9
|
+
adwords = AdWords::API.new
|
10
|
+
# Get the units for the last month or so
|
11
|
+
end = Date.today
|
12
|
+
start = end_date - 31
|
13
|
+
puts "result = #{adwords.getUnitCount(start, end).getUnitCountReturn}"
|
14
|
+
|
15
|
+
rescue AdWords::Error::UnknownAPICall => e
|
16
|
+
puts e
|
17
|
+
rescue AdWords::Error::ApiError => e
|
18
|
+
puts e.code
|
19
|
+
puts e.message
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,179 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Copyright 2008, Google Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
# This code sample illustrates how to get keyword variations for seed keyword(s)
|
18
|
+
# and then estimate the traffic that the "top" variations might receive.
|
19
|
+
|
20
|
+
require 'rubygems'
|
21
|
+
gem 'soap4r', '>= 1.5.8'
|
22
|
+
require 'adwords4r'
|
23
|
+
|
24
|
+
|
25
|
+
def main()
|
26
|
+
begin
|
27
|
+
# AdWords::AdWordsCredentials.new will read a credentials file from
|
28
|
+
# ENV['HOME']/adwords.properties when called without parameters.
|
29
|
+
# The latest versioned release of the API will be assumed.
|
30
|
+
#
|
31
|
+
# Credentials can be either for the production or Sandbox environments.
|
32
|
+
# Production environment credentials overview:
|
33
|
+
# http://www.google.com/apis/adwords/developer/index.html
|
34
|
+
# Sandbox environment credentials overview:
|
35
|
+
# http://www.google.com/apis/adwords/developer/adwords_api_sandbox.html
|
36
|
+
#
|
37
|
+
# Instead of reading them from a file, the credentials can be
|
38
|
+
# specified inline as a hash:
|
39
|
+
#
|
40
|
+
# creds = {
|
41
|
+
# 'developerToken' => 'user@domain.com++USD',
|
42
|
+
# 'useragent' => 'Sample User Agent',
|
43
|
+
# 'password' => 'password',
|
44
|
+
# 'email' => 'user@domain.com',
|
45
|
+
# 'clientEmail' => 'client_1+user@domain.com',
|
46
|
+
# 'applicationToken' => 'IGNORED',
|
47
|
+
# 'alternateUrl' => 'https://sandbox.google.com/api/adwords/v11/',
|
48
|
+
# }
|
49
|
+
# adwords = AdWords::API.new(AdWords::AdWordsCredentials.new(creds), 11)
|
50
|
+
|
51
|
+
adwords = AdWords::API.new
|
52
|
+
|
53
|
+
# Modify the following values to set the seed keywords, language,
|
54
|
+
# country targeting, and synonyms options.
|
55
|
+
|
56
|
+
keywords = ['hot dog']
|
57
|
+
languages = %w{en}
|
58
|
+
countries = %w{US}
|
59
|
+
use_synonyms = false
|
60
|
+
|
61
|
+
seed_keywords = []
|
62
|
+
keywords.each do |keyword|
|
63
|
+
seed_keyword = AdWords::KeywordToolService::SeedKeyword.new
|
64
|
+
seed_keyword.text = keyword
|
65
|
+
seed_keyword.type = 'Broad' # Or 'Phrase' or 'Exact' if desired.
|
66
|
+
seed_keywords << seed_keyword
|
67
|
+
end
|
68
|
+
|
69
|
+
variations = adwords.getKeywordVariations(seed_keywords, use_synonyms,
|
70
|
+
languages, countries
|
71
|
+
).getKeywordVariationsReturn
|
72
|
+
|
73
|
+
variation_objects = []
|
74
|
+
unless variations.moreSpecific.nil?
|
75
|
+
variation_objects.concat(variations.moreSpecific)
|
76
|
+
end
|
77
|
+
unless variations.additionalToConsider.nil?
|
78
|
+
variation_objects.concat(variations.additionalToConsider)
|
79
|
+
end
|
80
|
+
variation_objects.sort! do |a, b|
|
81
|
+
if b.searchVolumeScale == a.searchVolumeScale
|
82
|
+
a.advertiserCompetitionScale <=> b.advertiserCompetitionScale
|
83
|
+
else
|
84
|
+
b.searchVolumeScale <=> a.searchVolumeScale
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
max_estimates = 3
|
89
|
+
keywords_to_estimate = []
|
90
|
+
variation_objects[0..max_estimates - 1].each do |variation_object|
|
91
|
+
keywords_to_estimate << variation_object.text
|
92
|
+
end
|
93
|
+
|
94
|
+
ad_group_request = AdWords::TrafficEstimatorService::AdGroupRequest.new
|
95
|
+
ad_group_request.maxCpc = 1000000
|
96
|
+
keywords_to_estimate.each do |keyword_to_estimate|
|
97
|
+
keyword_request = AdWords::TrafficEstimatorService::KeywordRequest.new
|
98
|
+
keyword_request.text = keyword_to_estimate
|
99
|
+
keyword_request.type = 'Broad' # Or 'Phrase' or 'Exact' if desired.
|
100
|
+
ad_group_request.keywordRequests << keyword_request
|
101
|
+
end
|
102
|
+
|
103
|
+
geo_targeting = AdWords::TrafficEstimatorService::GeoTarget.new
|
104
|
+
geo_targeting.countryTargets = countries
|
105
|
+
|
106
|
+
campaign_request = AdWords::TrafficEstimatorService::CampaignRequest.new
|
107
|
+
campaign_request.adGroupRequests = ad_group_request
|
108
|
+
campaign_request.geoTargeting = geo_targeting
|
109
|
+
campaign_request.languageTargeting = languages
|
110
|
+
campaign_request.networkTargeting = %w{SearchNetwork ContentNetwork}
|
111
|
+
|
112
|
+
campaign_estimate = adwords.estimateCampaignList([campaign_request]).first
|
113
|
+
ad_group_estimate = campaign_estimate.adGroupEstimates.first
|
114
|
+
keyword_estimates = ad_group_estimate.keywordEstimates
|
115
|
+
for i in 0..keyword_estimates.length - 1
|
116
|
+
estimate = keyword_estimates[i]
|
117
|
+
text = keywords_to_estimate[i]
|
118
|
+
|
119
|
+
puts "Keyword: %s\tClicks: %f - %f\tCPC: %d - %d\tPosition: %f - %f" %
|
120
|
+
[text, estimate.lowerClicksPerDay, estimate.upperClicksPerDay,
|
121
|
+
estimate.lowerCpc, estimate.upperCpc, estimate.lowerAvgPosition,
|
122
|
+
estimate.upperAvgPosition]
|
123
|
+
end
|
124
|
+
|
125
|
+
rescue Errno::ECONNRESET, SOAP::HTTPStreamError, SocketError => e
|
126
|
+
# This exception indicates a connection-level error.
|
127
|
+
# In general, it is likely to be transitory.
|
128
|
+
|
129
|
+
puts 'Connection Error: %s' % e
|
130
|
+
puts 'Source: %s' % e.backtrace.first
|
131
|
+
|
132
|
+
rescue AdWords::Error::UnknownAPICall => e
|
133
|
+
# This exception is thrown when an unknown SOAP method is invoked.
|
134
|
+
|
135
|
+
puts e
|
136
|
+
puts 'Source: %s' % e.backtrace.first
|
137
|
+
|
138
|
+
rescue AdWords::Error::ApiError => e
|
139
|
+
# This exception maps to receiving a SOAP Fault back from the service.
|
140
|
+
# The e.soap_faultstring_ex, e.code_ex, and potentially e.trigger_ex
|
141
|
+
# attributes are the most useful, but other attributes may be populated
|
142
|
+
# as well. To display all attributes, the following can be used:
|
143
|
+
#
|
144
|
+
# e.instance_variables.each do |var|
|
145
|
+
# value = e.instance_variable_get(var)
|
146
|
+
# if ! value.nil?
|
147
|
+
# puts '%s => %s' % [var, value]
|
148
|
+
# end
|
149
|
+
# end
|
150
|
+
|
151
|
+
puts 'SOAP Error: %s (code: %d)' % [e.soap_faultstring_ex, e.code_ex]
|
152
|
+
puts 'Trigger: %s' % e.trigger_ex unless e.trigger_ex.nil?
|
153
|
+
puts 'Source: %s' % e.backtrace.first
|
154
|
+
|
155
|
+
ensure
|
156
|
+
# Display API unit usage info. This data is stored as a class variable
|
157
|
+
# in the AdWords::API class and accessed via static methods.
|
158
|
+
# AdWords::API.get_total_units() returns a running total of units used in
|
159
|
+
# the scope of the current program.
|
160
|
+
# AdWords::API.get_last_units() returns the number used in the last call.
|
161
|
+
|
162
|
+
puts
|
163
|
+
puts '%d API units consumed total (%d in last call).' %
|
164
|
+
[AdWords::API.get_total_units(), AdWords::API.get_last_units()]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
if __FILE__ == $0
|
170
|
+
# The adwords4r library can log all SOAP requests and responses to files.
|
171
|
+
# This is often useful for debugging purposes.
|
172
|
+
# To enable this, set the ADWORDS4R_DEBUG environement varaible to 'true'.
|
173
|
+
# This can be done either from your operating system environment or via
|
174
|
+
# code, as done below.
|
175
|
+
|
176
|
+
ENV['ADWORDS4R_DEBUG'] = 'false'
|
177
|
+
|
178
|
+
main()
|
179
|
+
end
|