adwords4r 13.0.1 → 15.0.1

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.
Files changed (99) hide show
  1. data/Authors.txt +2 -1
  2. data/ChangeLog.txt +28 -0
  3. data/Copying.txt +1 -1
  4. data/{Licence.txt → License.txt} +1 -1
  5. data/Rakefile +49 -54
  6. data/Readme.txt +78 -24
  7. data/adwords.properties +1 -1
  8. data/examples/account_info.rb +20 -26
  9. data/examples/create_all.rb +51 -53
  10. data/examples/create_all_v200902.rb +204 -0
  11. data/examples/keyword_suggestions.rb +35 -38
  12. data/examples/multiple_versions.rb +167 -0
  13. data/examples/reports.rb +37 -75
  14. data/lib/adwords4r.rb +123 -123
  15. data/lib/adwords4r/adwordslogger.rb +56 -0
  16. data/lib/adwords4r/apiextensions.rb +79 -0
  17. data/lib/adwords4r/authtoken.rb +56 -0
  18. data/lib/adwords4r/credentials.rb +115 -19
  19. data/lib/adwords4r/services.rb +139 -14
  20. data/lib/adwords4r/soap4rpatches.rb +129 -0
  21. data/lib/adwords4r/v13/AccountService.rb +11 -11
  22. data/lib/adwords4r/v13/AccountServiceDriver.rb +7 -5
  23. data/lib/adwords4r/v13/AccountServiceMappingRegistry.rb +56 -56
  24. data/lib/adwords4r/v13/AdGroupService.rb +9 -9
  25. data/lib/adwords4r/v13/AdGroupServiceDriver.rb +11 -9
  26. data/lib/adwords4r/v13/AdGroupServiceMappingRegistry.rb +47 -47
  27. data/lib/adwords4r/v13/AdService.rb +37 -37
  28. data/lib/adwords4r/v13/AdServiceDriver.rb +12 -10
  29. data/lib/adwords4r/v13/AdServiceMappingRegistry.rb +148 -148
  30. data/lib/adwords4r/v13/CampaignService.rb +46 -25
  31. data/lib/adwords4r/v13/CampaignServiceDriver.rb +23 -13
  32. data/lib/adwords4r/v13/CampaignServiceMappingRegistry.rb +169 -135
  33. data/lib/adwords4r/v13/CriterionService.rb +19 -19
  34. data/lib/adwords4r/v13/CriterionServiceDriver.rb +11 -9
  35. data/lib/adwords4r/v13/CriterionServiceMappingRegistry.rb +90 -90
  36. data/lib/adwords4r/v13/InfoService.rb +3 -3
  37. data/lib/adwords4r/v13/InfoServiceDriver.rb +10 -8
  38. data/lib/adwords4r/v13/InfoServiceMappingRegistry.rb +29 -29
  39. data/lib/adwords4r/v13/KeywordToolService.rb +10 -10
  40. data/lib/adwords4r/v13/KeywordToolServiceDriver.rb +4 -2
  41. data/lib/adwords4r/v13/KeywordToolServiceMappingRegistry.rb +37 -37
  42. data/lib/adwords4r/v13/ReportService.rb +13 -13
  43. data/lib/adwords4r/v13/ReportServiceDriver.rb +9 -7
  44. data/lib/adwords4r/v13/ReportServiceMappingRegistry.rb +54 -54
  45. data/lib/adwords4r/v13/SiteSuggestionService.rb +15 -15
  46. data/lib/adwords4r/v13/SiteSuggestionServiceDriver.rb +6 -4
  47. data/lib/adwords4r/v13/SiteSuggestionServiceMappingRegistry.rb +57 -57
  48. data/lib/adwords4r/v13/TrafficEstimatorService.rb +17 -17
  49. data/lib/adwords4r/v13/TrafficEstimatorServiceDriver.rb +6 -4
  50. data/lib/adwords4r/v13/TrafficEstimatorServiceMappingRegistry.rb +96 -96
  51. data/lib/adwords4r/v200902/AdGroupAdService.rb +2021 -0
  52. data/lib/adwords4r/v200902/AdGroupAdServiceDriver.rb +63 -0
  53. data/lib/adwords4r/v200902/AdGroupAdServiceMappingRegistry.rb +2234 -0
  54. data/lib/adwords4r/v200902/AdGroupCriterionService.rb +1209 -0
  55. data/lib/adwords4r/v200902/AdGroupCriterionServiceDriver.rb +63 -0
  56. data/lib/adwords4r/v200902/AdGroupCriterionServiceMappingRegistry.rb +1434 -0
  57. data/lib/adwords4r/v200902/AdGroupService.rb +968 -0
  58. data/lib/adwords4r/{v12/KeywordToolServiceDriver.rb → v200902/AdGroupServiceDriver.rb} +15 -13
  59. data/lib/adwords4r/v200902/AdGroupServiceMappingRegistry.rb +1114 -0
  60. data/lib/adwords4r/v200902/CampaignCriterionService.rb +741 -0
  61. data/lib/adwords4r/v200902/CampaignCriterionServiceDriver.rb +63 -0
  62. data/lib/adwords4r/v200902/CampaignCriterionServiceMappingRegistry.rb +904 -0
  63. data/lib/adwords4r/v200902/CampaignService.rb +1249 -0
  64. data/lib/adwords4r/v200902/CampaignServiceDriver.rb +63 -0
  65. data/lib/adwords4r/v200902/CampaignServiceMappingRegistry.rb +1466 -0
  66. data/lib/adwords4r/v200902/CampaignTargetService.rb +1156 -0
  67. data/lib/adwords4r/v200902/CampaignTargetServiceDriver.rb +63 -0
  68. data/lib/adwords4r/v200902/CampaignTargetServiceMappingRegistry.rb +1304 -0
  69. data/setup.rb +0 -0
  70. metadata +57 -65
  71. data/lib/adwords4r/v12/AccountService.rb +0 -215
  72. data/lib/adwords4r/v12/AccountServiceDriver.rb +0 -69
  73. data/lib/adwords4r/v12/AccountServiceMappingRegistry.rb +0 -243
  74. data/lib/adwords4r/v12/AdGroupService.rb +0 -263
  75. data/lib/adwords4r/v12/AdGroupServiceDriver.rb +0 -109
  76. data/lib/adwords4r/v12/AdGroupServiceMappingRegistry.rb +0 -280
  77. data/lib/adwords4r/v12/AdService.rb +0 -769
  78. data/lib/adwords4r/v12/AdServiceDriver.rb +0 -125
  79. data/lib/adwords4r/v12/AdServiceMappingRegistry.rb +0 -813
  80. data/lib/adwords4r/v12/CampaignService.rb +0 -498
  81. data/lib/adwords4r/v12/CampaignServiceDriver.rb +0 -133
  82. data/lib/adwords4r/v12/CampaignServiceMappingRegistry.rb +0 -642
  83. data/lib/adwords4r/v12/CriterionService.rb +0 -445
  84. data/lib/adwords4r/v12/CriterionServiceDriver.rb +0 -117
  85. data/lib/adwords4r/v12/CriterionServiceMappingRegistry.rb +0 -509
  86. data/lib/adwords4r/v12/InfoService.rb +0 -242
  87. data/lib/adwords4r/v12/InfoServiceDriver.rb +0 -109
  88. data/lib/adwords4r/v12/InfoServiceMappingRegistry.rb +0 -228
  89. data/lib/adwords4r/v12/KeywordToolService.rb +0 -205
  90. data/lib/adwords4r/v12/KeywordToolServiceMappingRegistry.rb +0 -227
  91. data/lib/adwords4r/v12/ReportService.rb +0 -322
  92. data/lib/adwords4r/v12/ReportServiceDriver.rb +0 -101
  93. data/lib/adwords4r/v12/ReportServiceMappingRegistry.rb +0 -298
  94. data/lib/adwords4r/v12/SiteSuggestionService.rb +0 -242
  95. data/lib/adwords4r/v12/SiteSuggestionServiceDriver.rb +0 -77
  96. data/lib/adwords4r/v12/SiteSuggestionServiceMappingRegistry.rb +0 -271
  97. data/lib/adwords4r/v12/TrafficEstimatorService.rb +0 -312
  98. data/lib/adwords4r/v12/TrafficEstimatorServiceDriver.rb +0 -77
  99. data/lib/adwords4r/v12/TrafficEstimatorServiceMappingRegistry.rb +0 -483
@@ -1,4 +1,5 @@
1
- jeffy@google.com (Current)
1
+ sgomes@google.com (Current)
2
+ jeffy@google.com
2
3
  opensource@google.com
3
4
  chanezon@google.com
4
5
  leavengood@gmail.com
@@ -1,3 +1,31 @@
1
+ 15.0.1
2
+ - Bugfix: added generation of ApiError exceptions upon SOAP faults.
3
+
4
+ 15.0.0
5
+ - Added support for the v200902 sandbox.
6
+ - Added support for multiple API versions on the same AdWords::API object.
7
+ - Added request and SOAP XML file logging options.
8
+ This complements the previously existing SOAP XML console output.
9
+ - Moved API classes to their own version and service-dependent modules.
10
+ This is necessary for multiple version support.
11
+ - Moved API methods from the AdWords::API object to service wrappers.
12
+ This is necessary to avoid collisions between similarly named methods in different services.
13
+ - Added get_service method to AdWords::API to be able to access a particular version of a service.
14
+ It returns the service wrapper containing the API methods for that service.
15
+ - Added extensions mechanism, allowing for plugging of client-side methods into the wrapper objects.
16
+ This allows us to provide smart methods at the service level that simplify common tasks.
17
+ - Added report download helper method, via the extension mechanism above.
18
+ - Moved unit tracking to happen within AdWords::API instances.
19
+ This allows for correct tracking with multiple AdWords::API objects.
20
+ The methods have been renamed total_units and last_units to fit with the getter conventions.
21
+ - Made code style more coherent.
22
+ - Updated v13 code samples to work with new client library model.
23
+ - Added v200902 and multiple version code samples.
24
+
25
+ 14.0.0
26
+ - Sérgio Gomes (api.sgomes@gmail.com) takes over as maintainer of this project.
27
+ - Removed support for v12 of the API, which has been deco'ed.
28
+
1
29
  13.0.1
2
30
  - Modified the file permissions on many of the files to make them world-readable.
3
31
 
@@ -1,4 +1,4 @@
1
- Copyright 2008, Google Inc. All Rights Reserved.
1
+ Copyright 2009, Google Inc. All Rights Reserved.
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- Copyright 2008, Google Inc. All Rights Reserved.
1
+ Copyright 2009, Google Inc. All Rights Reserved.
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ require 'lib/adwords4r/services'
16
16
 
17
17
  CLOBBER.include('pkg')
18
18
 
19
- CURRENT_VERSION = '13.0.1'
19
+ CURRENT_VERSION = '15.0.1'
20
20
  PKG_VERSION = ENV['REL'] ? ENV['REL'] : CURRENT_VERSION
21
21
 
22
22
  SRC_RB = FileList['lib/**/*.rb']
@@ -28,7 +28,7 @@ GENDIR = LIBDIR + '/adwords4r'
28
28
  logger = Logger.new(STDERR)
29
29
 
30
30
  CLEAN.include(WSDLDIR)
31
- AdWords::Service.getVersions.each do |v|
31
+ AdWords::Service.get_versions.each do |v|
32
32
  vname = "v#{v}"
33
33
  CLEAN.include(File.join(GENDIR, vname))
34
34
  end
@@ -38,37 +38,44 @@ task :default => [:getwsdl, :generate]
38
38
 
39
39
  desc "gets the wsdl files for AdWords services"
40
40
  task :getwsdl do
41
- AdWords::Service.getVersions.each do |v|
41
+ AdWords::Service.get_versions.each do |v|
42
42
  vname = "v#{v}"
43
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))}
44
+ AdWords::Service.get_services(v).each do |s|
45
+ if v.to_i <= 13
46
+ save(getfile("adwords.google.com",
47
+ "/api/adwords/#{vname}/#{s}Service?wsdl"),
48
+ get_wsdl_file_name(vname, s))
49
+ else
50
+ save(getfile("adwords-sandbox.google.com",
51
+ "/api/adwords/cm/#{vname}/#{s}Service?wsdl"),
52
+ get_wsdl_file_name(vname, s))
53
+ end
54
+ end
48
55
  end
49
56
  end
50
57
 
51
58
  desc "generates AdWords classes from the wsdl files"
52
59
  task :generate do
53
- AdWords::Service.getVersions.each do |v|
60
+ AdWords::Service.get_versions.each do |v|
54
61
  vname = "v#{v}"
55
62
  gendir = "#{LIBDIR}/adwords4r/#{vname}"
56
63
  mkdir_p gendir
57
- AdWords::Service.getServices(v).each do |name|
64
+ AdWords::Service.get_services(v).each do |name|
58
65
  worker = WSDL::SOAP::WSDL2Ruby.new
59
66
  worker.logger = logger
60
- worker.location = getWsdlFileName(vname,name)
67
+ worker.location = get_wsdl_file_name(vname,name)
61
68
  worker.basedir = gendir
62
- worker.opt.update(getWsdlOpt(name))
69
+ worker.opt.update(get_wsdl_opt(vname,name))
63
70
  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"))
71
+ fix_import(v, File.join(gendir, "#{name}Driver.rb"))
72
+ fix_import(v, File.join(gendir, "#{name}MappingRegistry.rb"))
73
+ fix_import(v, File.join(gendir, "#{name}.rb"))
67
74
  end
68
75
  end
69
76
  end
70
77
 
71
- def fixImport(version, file)
78
+ def fix_import(version, file)
72
79
  vname = "v#{version}"
73
80
  tempfile = file + '.tmp'
74
81
  outfile = File.new(tempfile,"w")
@@ -86,25 +93,25 @@ def fixImport(version, file)
86
93
  File.rename(tempfile, file)
87
94
  end
88
95
 
89
- def getWsdlOpt(s)
96
+ def get_wsdl_opt(v,s)
90
97
  optcmd= {}
91
98
  s << "Service"
92
99
  optcmd['classdef'] = s
93
100
  optcmd['force'] = true
94
101
  optcmd['mapping_registry'] = true
95
102
  optcmd['driver'] = nil
96
-
103
+
97
104
  # Causes soap4r to wrap the classes it outputs into the given modules
98
- optcmd['module_path'] = ['AdWords', s]
105
+ optcmd['module_path'] = ['AdWords', v.capitalize, s]
99
106
  return optcmd
100
107
  end
101
108
 
102
- def getWsdlFileName(v,s)
109
+ def get_wsdl_file_name(v,s)
103
110
  "#{WSDLDIR}/#{v}/#{s}.wsdl"
104
111
  end
105
112
 
106
113
  def getfile(host, path)
107
- puts "getting https//#{host}#{path}"
114
+ puts "getting https://#{host}#{path}"
108
115
  https = Net::HTTP.new(host, 443)
109
116
  https.use_ssl = true
110
117
  https.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -115,8 +122,8 @@ def fix_attribute(text, name, type)
115
122
  text.gsub!(Regexp.new("#{name}=\"#{type}\""),"#{name}=\"xsd:#{type}\"")
116
123
  end
117
124
 
118
- def fixWsdl(wsdl)
119
- ['type', 'base'].each {|name|
125
+ def fix_wsdl(wsdl)
126
+ ['type', 'base'].each {|name|
120
127
  ['long', 'string', 'date', 'int', 'boolean'].each {|type|
121
128
  fix_attribute(wsdl, name, type)}}
122
129
  schema_ns = "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
@@ -124,14 +131,13 @@ def fixWsdl(wsdl)
124
131
  wsdl.gsub!(/(<wsdl:definitions[^>]*)>/, '\1 ' + schema_ns + '>')
125
132
  end
126
133
  return wsdl
127
- #wsdl.gsub(/type=\"long\"/, 'type="xsd:long"')
128
134
  end
129
135
 
130
136
  # Saves this document to the specified @var path.
131
- #doesn't create the file if contains markup for google 404 page
137
+ # doesn't create the file if contains markup for google 404 page
132
138
  def save(content, path)
133
139
  if content !~ /<H2>Error 404<\/H2>/
134
- File::open(path, 'w') {|f| f.write(fixWsdl(content))}
140
+ File::open(path, 'w') {|f| f.write(fix_wsdl(content))}
135
141
  end
136
142
  end
137
143
 
@@ -140,60 +146,49 @@ end
140
146
  # gem files.
141
147
 
142
148
  PKG_FILES = FileList[
143
- '*.*',
144
- 'Rakefile',
145
- 'lib/**/*.rb',
146
- 'examples/**/*.rb',
147
- # 'test/**/*.rb',
149
+ '*.*',
150
+ 'Rakefile',
151
+ 'lib/**/*.rb',
152
+ 'examples/**/*.rb',
148
153
  'scripts/**/*.rb'
149
154
  ]
150
155
 
151
- #puts PKG_FILES
152
-
153
156
  PKG_FILES.exclude(/\._/)
154
157
 
155
158
  if ! defined?(Gem)
156
159
  puts "Package Target requires RubyGems"
157
160
  else
158
161
  spec = Gem::Specification.new do |s|
159
-
162
+
160
163
  #### Basic information.
161
-
164
+
162
165
  s.name = 'adwords4r'
163
166
  s.version = PKG_VERSION
164
167
  s.summary = "Client library for the AdWords API."
165
168
  s.description = %{\
166
- Adwords4r provides an easy to use way to access the AdWords API in ruby.\
169
+ Adwords4r provides an easy to use way to access the AdWords API in Ruby.\
167
170
  Currently the following AdWords API versions are supported:\
168
171
  \
169
- * V12\
170
172
  * V13\
173
+ * V200902 (sandbox)
171
174
  }
172
-
175
+
173
176
  s.files = PKG_FILES.to_a
174
177
  s.require_path = 'lib'
175
178
  s.autorequire = 'adwords4r'
176
-
177
- #s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }
178
-
179
- #s.has_rdoc = true
179
+
180
180
  s.has_rdoc = false
181
- #s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
182
- #s.rdoc_options <<
183
- # '--title' << 'Builder -- Easy XML Building' <<
184
- # '--main' << 'README' <<
185
- # '--line-numbers'
186
-
187
- s.author = "Jeffrey Posnick, Patrick Chanezon, Ryan Leavengood"
188
- s.email = "jeffy@google.com"
189
- s.homepage = "http://rubyforge.org/projects/google4r/"
190
- s.requirements << 'soap4r v1.5.8 or greater'
181
+
182
+ s.author =
183
+ "Sergio Gomes, Jeffrey Posnick, Patrick Chanezon, Ryan Leavengood"
184
+ s.email = "api.sgomes@gmail.com"
185
+ s.homepage = "http://code.google.com/p/google-api-adwords-ruby/"
186
+ s.requirements << 'soap4r v1.5.8'
191
187
  s.requirements << 'httpclient v2.1.2 or greater'
192
- s.rubyforge_project = 'google4r'
193
- s.add_dependency('soap4r', '>= 1.5.8')
188
+ s.add_dependency('soap4r', '= 1.5.8')
194
189
  s.add_dependency('httpclient', '>= 2.1.2')
195
190
  end
196
-
191
+
197
192
  Rake::GemPackageTask.new(spec) do |t|
198
193
  t.need_tar = true
199
194
  end
data/Readme.txt CHANGED
@@ -1,7 +1,8 @@
1
- Google adwwords4r Library
1
+ Google adwords4r Library
2
2
  -------------------------
3
3
 
4
- Welcome to adwords4r: Bringing the delights of ruby programming to the AdWords world!
4
+ Welcome to adwords4r: Bringing the delights of Ruby programming to the AdWords
5
+ world!
5
6
 
6
7
  Documentation and comments are a work in progress.
7
8
 
@@ -9,26 +10,36 @@ Documentation and comments are a work in progress.
9
10
  Useful Web Resources
10
11
  --------------------
11
12
 
12
- - AdWords home: https://adwords.google.com/
13
- - AdWords API discussion forum: http://groups.google.com/group/adwords-api
14
- - AdWords API documentation: http://www.google.com/apis/adwords/developer/index.html
15
- - This project's Google Code page: http://code.google.com/p/google-api-adwords-ruby/
13
+ - AdWords home:
14
+ https://adwords.google.com/
15
+ - AdWords API discussion forum:
16
+ http://groups.google.com/group/adwords-api
17
+ - AdWords API documentation:
18
+ http://code.google.com/apis/adwords/docs/developer/index.html
19
+ - This project's Google Code page:
20
+ http://code.google.com/p/google-api-adwords-ruby/
16
21
 
17
22
 
18
23
  Docs for Users
19
24
  --------------
20
25
 
26
+ 1 - Instalation:
27
+
21
28
  adwords4r is a ruby gem. See http://docs.rubygems.org/read/book/1
22
29
 
23
30
  Install it using the gem install command.
24
- > gem install --remote adwords4r
31
+ > gem install --local adwords4r
25
32
 
26
33
  The following gem libraries are required:
27
- - soap4r v1.5.8 or greater
34
+ - soap4r v1.5.8
28
35
  - httpclient v2.1.2 or greater
29
36
 
37
+
38
+ 2 - Using the client library:
39
+
30
40
  It's pretty easy to use.
31
- See http://docs.rubygems.org/read/chapter/3#page70 for how to set the rubygem environment.
41
+ See http://docs.rubygems.org/read/chapter/3#page70 for how to set the rubygem
42
+ environment.
32
43
  export RUBYOPT=rubygems
33
44
  or ruby -rubygems my_program_that_uses_gems
34
45
 
@@ -36,11 +47,12 @@ If you do not use the rubygems option, you need to add
36
47
  require 'rubygems'
37
48
  at the beginning of your programs.
38
49
 
39
- Then
50
+ Then:
40
51
  require 'adwords4r'
41
52
 
42
53
  adwords = AdWords::API.new
43
- creates a driver for the latest version of AdWords API using a credentials file in ENV['HOME']/adwords.properties
54
+ creates a driver for the latest version of AdWords API using a credentials file
55
+ in ENV['HOME']/adwords.properties
44
56
  There is an example credentials in the root adwords4r directory.
45
57
  You can also pass API a manually constructed AdWordsCredentials object like:
46
58
  adwords = AdWords::API.new(AdWords::AdWordsCredentials.new({
@@ -52,21 +64,63 @@ adwords = AdWords::API.new(AdWords::AdWordsCredentials.new({
52
64
  'clientEmail' => 'user2@domain.com',
53
65
  }))
54
66
 
55
- If you want something more specific, use the optional parameters of the constructor
56
- adwords = AdWords::API.new(credentials, version)
67
+ Then, just specify which service you're looking to use, and which version:
68
+ account_srv = adwords.get_service(13, 'Account')
69
+
70
+ and you should now be able to just use the API methods in the object you were
71
+ returned:
72
+ client_accounts = account_srv.getClientAccounts
73
+
74
+ See the code in the examples directory for working examples you can build from.
75
+
76
+
77
+ 2.1 - Using the Sandbox:
78
+
79
+ In order to use the v13 sandbox, you can add a credential named alternateUrl:
80
+ alternateUrl=https://sandbox.google.com/api/adwords/v13/
57
81
 
58
- In order to use the sandbox, you can add a credential named
59
- alternateUrl like:
60
- alternateUrl=https://sandbox.google.com/api/adwords/v12/
82
+ As for v200902, the alternateUrl parameter is currently ignored, since only the
83
+ sandbox is available at the moment. For this API version, all requests will be
84
+ sent to the sandbox, using the "email" and "password" fields defined in the
85
+ credentials for authentication, and clientEmail for specifying which client
86
+ account to access. Developer and application tokens are ignored.
61
87
 
62
- Then just use methods of the API against your driver.
63
- See sample code in the examples directory for working examples you can build from.
88
+ This way, it's possible to access both the v13 and v200902 sandboxes
89
+ simultaneously. Since they share a common backend storage, it is possible for
90
+ your application to choose between v13 and v200902 services at will, mixing and
91
+ matching them.
92
+
93
+ The multiple_versions.rb code sample shows you how to build an application using
94
+ v13 and v200902 services simultaneously.
95
+
96
+
97
+ 2.2 - Logging:
64
98
 
65
99
  It is often useful to see a trace of the raw SOAP XML being sent and received.
66
- To enable this, set the ADWORDS4R_DEBUG environment variable to TRUE.
67
- e.g. in the bash shell, export ADWORDS4R_DEBUG=TRUE
68
- or from your Ruby code, ENV['ADWORDS4R_DEBUG'] = 'TRUE'
69
- The SOAP logs will be written to the current directory.
100
+ The quickest way of achieving this when debugging your application is by setting
101
+ the ADWORDS4R_DEBUG environment variable to TRUE; e.g. in the bash shell:
102
+ export ADWORDS4R_DEBUG=TRUE
103
+ or from your Ruby code:
104
+ ENV['ADWORDS4R_DEBUG'] = 'TRUE'
105
+
106
+ This will output the SOAP XML to stderr, which will usually show up in your
107
+ terminal window.
108
+
109
+ There's also the option of logging requests and XML to files. In order to enable
110
+ this, you should use the write_to_file method of the loggers inside your
111
+ AdWords::API object:
112
+ adwords = AdWords::API.new
113
+ adwords.unit_logger.log_to_file
114
+ adwords.xml_logger.log_to_file
115
+
116
+ The first logs the units spent and the requests made, whereas the second logs
117
+ the full SOAP XML being sent and received over the wire. These will be written
118
+ to the current directory by default, but you can specify a path as an optional
119
+ parameter to log_to_file:
120
+ adwords.unit_logger.log_to_file('/var/log/my_app')
121
+ adwords.xml_logger.log_to_file('/var/log/my_app')
122
+
123
+ The files will be named request_info and soap_xml, respectively.
70
124
 
71
125
 
72
126
  Docs for Developers
@@ -78,12 +132,12 @@ rake generate
78
132
  to regenerate the bindings if needed
79
133
  rake package
80
134
  to package the gem and create a release
81
-
135
+
82
136
 
83
137
  Copyright/License Info
84
138
  ----------------------
85
139
 
86
- Copyright 2008, Google Inc. All Rights Reserved.
140
+ Copyright 2009, Google Inc. All Rights Reserved.
87
141
 
88
142
  Licensed under the Apache License, Version 2.0 (the "License");
89
143
  you may not use this file except in compliance with the License.
@@ -4,4 +4,4 @@ useragent=APPLICATION_NAME
4
4
  password=ADWORDS_PASSWORD
5
5
  email=ADWORDS_MCC_LOGIN
6
6
  clientEmail=OPTIONAL_CLIENT_LOGIN
7
- #alternateUrl=https://sandbox.google.com/api/adwords/v12/
7
+ #alternateUrl=https://sandbox.google.com/api/adwords/v13/
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/ruby
2
2
  #
3
- # Copyright 2008, Google Inc. All Rights Reserved.
3
+ # Copyright 2009, Google Inc. All Rights Reserved.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
18
18
  # MCC account, and then iteratively retrieves information about each account.
19
19
 
20
20
  require 'rubygems'
21
- gem 'soap4r', '>= 1.5.8'
21
+ gem 'soap4r', '= 1.5.8'
22
22
  require 'adwords4r'
23
23
 
24
24
 
@@ -38,30 +38,30 @@ def main()
38
38
  # specified inline as a hash:
39
39
  #
40
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/v13/',
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/v13/',
48
48
  # }
49
- # adwords = AdWords::API.new(AdWords::AdWordsCredentials.new(creds), 13)
50
-
49
+ # adwords = AdWords::API.new(AdWords::AdWordsCredentials.new(creds))
51
50
  adwords = AdWords::API.new
52
51
 
53
52
  # Clear out the clientEmail header temporarily so that we run under the
54
53
  # context of the MCC user.
55
- adwords.credentials.setHeader('clientEmail', '')
54
+ adwords.credentials.set_header('clientEmail', '')
56
55
 
57
- client_accounts = adwords.getClientAccounts
56
+ account_srv = adwords.get_service(13, 'Account')
57
+ client_accounts = account_srv.getClientAccounts
58
58
 
59
59
  if client_accounts.length > 0 then
60
60
  client_accounts.each do |client_account|
61
61
  # Set the clientEmail header to each account's login email so that API
62
62
  # calls are made in the context of that account.
63
- adwords.credentials.setHeader('clientEmail', client_account)
64
- account_info = adwords.getAccountInfo.getAccountInfoReturn
63
+ adwords.credentials.set_header('clientEmail', client_account)
64
+ account_info = account_srv.getAccountInfo.getAccountInfoReturn
65
65
 
66
66
  puts 'Client Email: %s' % client_account
67
67
  if ! account_info.descriptiveName.empty? then
@@ -77,16 +77,14 @@ def main()
77
77
  rescue Errno::ECONNRESET, SOAP::HTTPStreamError, SocketError => e
78
78
  # This exception indicates a connection-level error.
79
79
  # In general, it is likely to be transitory.
80
-
81
80
  puts 'Connection Error: %s' % e
82
81
  puts 'Source: %s' % e.backtrace.first
83
-
82
+
84
83
  rescue AdWords::Error::UnknownAPICall => e
85
84
  # This exception is thrown when an unknown SOAP method is invoked.
86
-
87
85
  puts e
88
86
  puts 'Source: %s' % e.backtrace.first
89
-
87
+
90
88
  rescue AdWords::Error::ApiError => e
91
89
  # This exception maps to receiving a SOAP Fault back from the service.
92
90
  # The e.soap_faultstring_ex, e.code_ex, and potentially e.trigger_ex
@@ -99,7 +97,6 @@ def main()
99
97
  # puts '%s => %s' % [var, value]
100
98
  # end
101
99
  # end
102
-
103
100
  puts 'SOAP Error: %s (code: %d)' % [e.soap_faultstring_ex, e.code_ex]
104
101
  puts 'Trigger: %s' % e.trigger_ex unless e.trigger_ex.nil?
105
102
  puts 'Source: %s' % e.backtrace.first
@@ -107,13 +104,11 @@ def main()
107
104
  ensure
108
105
  # Display API unit usage info. This data is stored as a class variable
109
106
  # in the AdWords::API class and accessed via static methods.
110
- # AdWords::API.get_total_units() returns a running total of units used in
111
- # the scope of the current program.
112
- # AdWords::API.get_last_units() returns the number used in the last call.
113
-
107
+ # total_units() returns a running total of units used in the scope of the
108
+ # current program. last_units() returns the number used in the last call.
114
109
  puts
115
110
  puts '%d API units consumed total (%d in last call).' %
116
- [AdWords::API.get_total_units(), AdWords::API.get_last_units()]
111
+ [adwords.total_units, adwords.last_units]
117
112
  end
118
113
  end
119
114
 
@@ -124,7 +119,6 @@ if __FILE__ == $0
124
119
  # To enable this, set the ADWORDS4R_DEBUG environement varaible to 'true'.
125
120
  # This can be done either from your operating system environment or via
126
121
  # code, as done below.
127
-
128
122
  ENV['ADWORDS4R_DEBUG'] = 'false'
129
123
 
130
124
  main()