google-ads-common 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/ChangeLog +5 -0
  2. data/README +1 -4
  3. data/Rakefile +2 -2
  4. data/lib/ads_common/api.rb +106 -16
  5. data/lib/ads_common/api_config.rb +2 -3
  6. data/lib/ads_common/auth/base_handler.rb +22 -3
  7. data/lib/ads_common/auth/client_login_handler.rb +27 -32
  8. data/lib/ads_common/auth/oauth_handler.rb +260 -0
  9. data/lib/ads_common/build/savon_abstract_generator.rb +12 -11
  10. data/lib/ads_common/build/savon_generator.rb +31 -27
  11. data/lib/ads_common/build/savon_registry.rb +46 -23
  12. data/lib/ads_common/build/savon_registry_generator.rb +23 -10
  13. data/lib/ads_common/build/savon_service_generator.rb +17 -3
  14. data/lib/ads_common/config.rb +1 -1
  15. data/lib/ads_common/credential_handler.rb +3 -7
  16. data/lib/ads_common/errors.rb +18 -6
  17. data/lib/ads_common/savon_headers/base_header_handler.rb +80 -0
  18. data/lib/ads_common/{soap4r_logger.rb → savon_headers/httpi_request_proxy.rb} +27 -20
  19. data/lib/ads_common/savon_headers/oauth_header_handler.rb +92 -0
  20. data/lib/ads_common/savon_headers/simple_header_handler.rb +17 -49
  21. data/lib/ads_common/savon_service.rb +129 -41
  22. data/test/test_savon_service.rb +9 -4
  23. metadata +39 -43
  24. data/lib/ads_common/build/rake_common.rb +0 -343
  25. data/lib/ads_common/build/soap4r_generator.rb +0 -565
  26. data/lib/ads_common/savon_headers/client_login_header_handler.rb +0 -60
  27. data/lib/ads_common/soap4r_headers/nested_header_handler.rb +0 -50
  28. data/lib/ads_common/soap4r_headers/single_header_handler.rb +0 -44
  29. data/lib/ads_common/soap4r_patches.rb +0 -210
  30. data/lib/ads_common/soap4r_response_handler.rb +0 -80
@@ -21,11 +21,14 @@
21
21
 
22
22
  require 'rubygems'
23
23
  require 'test/unit'
24
- require 'pp'
24
+
25
25
  require 'ads_common/savon_service'
26
26
 
27
27
  # SavonService is abstract, defining a child class for the test.
28
28
  class SomeService < AdsCommon::SavonService
29
+ def initialize(namespace, endpoint, version)
30
+ super(nil, namespace, endpoint, version)
31
+ end
29
32
  def private_get_service_registry()
30
33
  return get_service_registry
31
34
  end
@@ -49,18 +52,20 @@ end
49
52
  class TestSavonService < Test::Unit::TestCase
50
53
  TEST_NAMESPACE = 'namespace'
51
54
  TEST_ENDPOINT = 'endpoint'
55
+ TEST_VERSION = :vVersion
52
56
 
53
57
  # Initialize tests.
54
58
  def setup
55
- @some_service = SomeService.new(TEST_NAMESPACE, TEST_ENDPOINT)
59
+ @some_service = SomeService.new(TEST_NAMESPACE, TEST_ENDPOINT, TEST_VERSION)
56
60
  end
57
61
 
58
62
  def test_initialize_abstract
59
63
  assert_raises(NoMethodError) do
60
- AdsCommon::SavonService.new(TEST_NAMESPACE, TEST_ENDPOINT)
64
+ AdsCommon::SavonService.new(nil, TEST_NAMESPACE, TEST_ENDPOINT,
65
+ TEST_VERSION)
61
66
  end
62
67
  assert_nothing_raised do
63
- SomeService.new(TEST_NAMESPACE, TEST_ENDPOINT)
68
+ SomeService.new(TEST_NAMESPACE, TEST_ENDPOINT, TEST_VERSION)
64
69
  end
65
70
  end
66
71
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-ads-common
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 0.4.0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sergio Gomes
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-06-20 00:00:00 +04:00
19
+ date: 2011-08-02 00:00:00 +04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -25,62 +25,62 @@ dependencies:
25
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
- - - ~>
28
+ - - "="
29
29
  - !ruby/object:Gem::Version
30
- hash: 57
30
+ hash: 55
31
31
  segments:
32
32
  - 0
33
33
  - 9
34
- - 1
35
- version: 0.9.1
34
+ - 6
35
+ version: 0.9.6
36
36
  type: :runtime
37
37
  version_requirements: *id001
38
38
  - !ruby/object:Gem::Dependency
39
- name: soap4r
39
+ name: httpclient
40
40
  prerelease: false
41
41
  requirement: &id002 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
- - - "="
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
- hash: 19
46
+ hash: 7
47
47
  segments:
48
+ - 2
48
49
  - 1
49
- - 5
50
- - 8
51
- version: 1.5.8
50
+ - 6
51
+ version: 2.1.6
52
52
  type: :runtime
53
53
  version_requirements: *id002
54
54
  - !ruby/object:Gem::Dependency
55
- name: httpclient
55
+ name: httpi
56
56
  prerelease: false
57
57
  requirement: &id003 !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements:
60
- - - ">="
60
+ - - ~>
61
61
  - !ruby/object:Gem::Version
62
- hash: 7
62
+ hash: 63
63
63
  segments:
64
+ - 0
65
+ - 9
64
66
  - 2
65
- - 1
66
- - 6
67
- version: 2.1.6
67
+ version: 0.9.2
68
68
  type: :runtime
69
69
  version_requirements: *id003
70
70
  - !ruby/object:Gem::Dependency
71
- name: httpi
71
+ name: oauth
72
72
  prerelease: false
73
73
  requirement: &id004 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ~>
77
77
  - !ruby/object:Gem::Version
78
- hash: 63
78
+ hash: 5
79
79
  segments:
80
80
  - 0
81
- - 9
82
- - 2
83
- version: 0.9.2
81
+ - 4
82
+ - 5
83
+ version: 0.4.5
84
84
  type: :runtime
85
85
  version_requirements: *id004
86
86
  description: google-ads-common provides essential utilities shared by all Ads Ruby client libraries.
@@ -94,29 +94,25 @@ extra_rdoc_files:
94
94
  - COPYING
95
95
  - ChangeLog
96
96
  files:
97
- - lib/ads_common/auth/base_handler.rb
98
- - lib/ads_common/auth/client_login_handler.rb
99
- - lib/ads_common/api_config.rb
100
97
  - lib/ads_common/config.rb
101
- - lib/ads_common/credential_handler.rb
102
- - lib/ads_common/errors.rb
103
- - lib/ads_common/http.rb
104
- - lib/ads_common/api.rb
105
- - lib/ads_common/savon_service.rb
106
- - lib/ads_common/soap4r_patches.rb
107
- - lib/ads_common/soap4r_response_handler.rb
108
- - lib/ads_common/build/rake_common.rb
109
98
  - lib/ads_common/build/savon_abstract_generator.rb
99
+ - lib/ads_common/build/savon_service_generator.rb
110
100
  - lib/ads_common/build/savon_generator.rb
111
- - lib/ads_common/build/savon_registry.rb
112
101
  - lib/ads_common/build/savon_registry_generator.rb
113
- - lib/ads_common/build/savon_service_generator.rb
114
- - lib/ads_common/build/soap4r_generator.rb
102
+ - lib/ads_common/build/savon_registry.rb
103
+ - lib/ads_common/savon_headers/base_header_handler.rb
115
104
  - lib/ads_common/savon_headers/simple_header_handler.rb
116
- - lib/ads_common/savon_headers/client_login_header_handler.rb
117
- - lib/ads_common/soap4r_headers/nested_header_handler.rb
118
- - lib/ads_common/soap4r_headers/single_header_handler.rb
119
- - lib/ads_common/soap4r_logger.rb
105
+ - lib/ads_common/savon_headers/httpi_request_proxy.rb
106
+ - lib/ads_common/savon_headers/oauth_header_handler.rb
107
+ - lib/ads_common/savon_service.rb
108
+ - lib/ads_common/api_config.rb
109
+ - lib/ads_common/http.rb
110
+ - lib/ads_common/api.rb
111
+ - lib/ads_common/auth/oauth_handler.rb
112
+ - lib/ads_common/auth/base_handler.rb
113
+ - lib/ads_common/auth/client_login_handler.rb
114
+ - lib/ads_common/errors.rb
115
+ - lib/ads_common/credential_handler.rb
120
116
  - Rakefile
121
117
  - test/test_config.rb
122
118
  - test/test_savon_service.rb
@@ -1,343 +0,0 @@
1
- #!/usr/bin/ruby
2
- #
3
- # Authors:: api.sgomes@gmail.com (Sérgio Gomes)
4
- # api.jeffy@gmail.com (Jeffrey Posnick)
5
- # chanezon@google.com (Patrick Chanezon)
6
- # leavengood@gmail.com (Ryan Leavengood)
7
- #
8
- # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
9
- #
10
- # License:: Licensed under the Apache License, Version 2.0 (the "License");
11
- # you may not use this file except in compliance with the License.
12
- # You may obtain a copy of the License at
13
- #
14
- # http://www.apache.org/licenses/LICENSE-2.0
15
- #
16
- # Unless required by applicable law or agreed to in writing, software
17
- # distributed under the License is distributed on an "AS IS" BASIS,
18
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
19
- # implied.
20
- # See the License for the specific language governing permissions and
21
- # limitations under the License.
22
- #
23
- # Common Rake tasks for Ads client libraries.
24
-
25
- require 'fileutils'
26
- require 'logger'
27
- require 'rubygems'
28
- gem 'rake'
29
- require 'rake/gempackagetask'
30
- require 'rake/rdoctask'
31
- require 'rake/clean'
32
- require 'rake/testtask'
33
- gem 'soap4r', '=1.5.8'
34
- require 'wsdl/soap/wsdl2ruby'
35
- require 'xsd/codegen/classdef'
36
- require 'ads_common/soap4r_patches'
37
- require 'ads_common/http'
38
-
39
- $API_CONFIG = $MODULE::ApiConfig
40
-
41
- $WSDLDIR = 'wsdl'
42
- $LIBDIR = 'lib'
43
- $DOCDIR = 'doc'
44
- $TESTDIR = 'test'
45
- $GENDIR = File.join($LIBDIR, $PROJECT_NAME)
46
- $PKG_VERSION = ENV['REL'] ? ENV['REL'] : $CURRENT_VERSION
47
-
48
- SRC_RB = FileList["#{$LIBDIR}/**/*.rb"]
49
-
50
- logger = Logger.new(STDOUT)
51
- logger.level = Logger::INFO
52
-
53
- CLEAN.include($WSDLDIR)
54
- CLEAN.include($DOCDIR)
55
- $API_CONFIG.versions.each do |version|
56
- CLEAN.include(File.join($GENDIR, version.to_s))
57
- end
58
-
59
- CLOBBER.include('pkg')
60
-
61
- # ====================================================================
62
- # Create a default task to prepare library for usage.
63
- desc "gets the wsdl and generates the classes"
64
- task :default => [:getwsdl, :generate]
65
-
66
- # ====================================================================
67
- # Create a task to retrieve the WSDL files for the services.
68
- desc "gets the wsdl files for API services"
69
- task :getwsdl do
70
- $API_CONFIG.versions.each do |version|
71
- urls = $API_CONFIG.get_wsdls(version)
72
- mkdir_p File.join($WSDLDIR, version.to_s)
73
- config = Generator.config
74
- config.set('library.logger', logger)
75
- urls.each do |service, url|
76
- logger.info("Getting #{url}...")
77
- save(AdsCommon::Http.get(url, config),
78
- get_wsdl_file_name(version.to_s, service.to_s))
79
- end
80
- end
81
- end
82
-
83
- # Return the full file name of the WSDL file for a given version and service
84
- def get_wsdl_file_name(version, service)
85
- File.join($WSDLDIR, version.to_s, service.to_s) + '.wsdl'
86
- end
87
-
88
- # Apply fixes to the WSDL content in order to make it understandable for the
89
- # soap4r code generator. The fixes are applied to the original object.
90
- def fix_wsdl!(wsdl)
91
- ['type', 'base'].each do |name|
92
- ['long', 'string', 'date', 'int', 'boolean'].each do |type|
93
- # Fix this attribute over the entire document
94
- wsdl.gsub!(Regexp.new("#{name}=\"#{type}\""), "#{name}=\"xsd:#{type}\"")
95
- end
96
- end
97
- schema_ns = "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
98
- if wsdl !~ Regexp.new(schema_ns)
99
- wsdl.gsub!(/(<wsdl:definitions[^>]*)>/, '\1 ' + schema_ns + '>')
100
- end
101
- return wsdl
102
- end
103
-
104
- # Saves this document to the specified path.
105
- # Doesn't create the file if a 404 error page is returned.
106
- def save(content, path)
107
- if content !~ /<H2>Error 404<\/H2>/
108
- File::open(path, 'w') {|f| f.write(fix_wsdl!(content))}
109
- end
110
- end
111
-
112
- # ====================================================================
113
- # Set the default generation task to use soap4r (can be overriden for client
114
- # libraries).
115
- desc "generates API classes from the wsdl files"
116
- task :generate => [:soap4r_generate]
117
-
118
- # ====================================================================
119
- # Create a task to generate all the service classes with soap4r.
120
- desc "generates API classes from the wsdl files using soap4r"
121
- task :soap4r_generate do
122
- $API_CONFIG.versions.each do |version|
123
- gendir = File.join($LIBDIR, $PRODDIR, version.to_s)
124
- mkdir_p gendir
125
- $API_CONFIG.services(version).each do |service|
126
- # Generate SOAP classes with soap4r
127
- service_name = service.to_s
128
- worker = WSDL::SOAP::WSDL2Ruby.new
129
- worker.logger = logger
130
- worker.location = get_wsdl_file_name(version, service)
131
- worker.basedir = gendir
132
- worker.opt.update(get_wsdl_opt(version, service_name))
133
- worker.run
134
-
135
- # Fix the "require" statements so that they work in the client library's
136
- # directory structure
137
- fix_import(version, File.join(gendir, "#{service_name}Driver.rb"))
138
- fix_import(version,
139
- File.join(gendir, "#{service_name}MappingRegistry.rb"))
140
- fix_import(version, File.join(gendir, "#{service_name}.rb"))
141
-
142
- # Fix the comments in the file so that we get better-looking RDoc, and
143
- # only for the things we want
144
- fix_rdoc(File.join(gendir, "#{service_name}.rb"))
145
-
146
- # Generate the wrapper files
147
- eval("require '#{File.join(gendir, "#{service_name}Driver.rb")}'")
148
- wrapper_file = File.join(gendir, "#{service_name}Wrapper.rb")
149
- File.open(wrapper_file, 'w') do |file|
150
- file.write(Generator.generate_wrapper_class(version, service))
151
- end
152
- logger.info("Generated #{version} #{service_name} " +
153
- "wrapper: #{wrapper_file}")
154
- end
155
- end
156
- end
157
-
158
- # Fix "require" statements for client lib usage
159
- def fix_import(version, file)
160
- tempfile = file + '.tmp'
161
- outfile = File.new(tempfile, 'w')
162
- File.open(file, 'r') do |infile|
163
- infile.each do |line|
164
- if (line =~ /require.*Service.*\.rb/)
165
- outfile << line.gsub(/require '(.*)Service(.*)\.rb'/,
166
- "require '#{$PRODDIR}/#{version.to_s}/\\1Service\\2'")
167
- else
168
- outfile << line
169
- end
170
- end
171
- end
172
- outfile.close
173
- File.rename(tempfile, file)
174
- end
175
-
176
- # Fix RDoc comments in the generated *Service.rb files
177
- def fix_rdoc(file)
178
- tempfile = file + '.tmp'
179
- outfile = File.new(tempfile, 'w')
180
- should_doc = true
181
- File.open(file, 'r') do |infile|
182
- infile.each do |line|
183
- if (line =~ /# \{.*\}[A-Z]\w*/)
184
- # This is a regular class. Document and clean up how it's displayed.
185
- should_doc = true
186
- outfile << line.gsub(/\{.*\}(.*)/, "\\1")
187
- elsif (line =~ /# \{.*\}[a-z]\w*/)
188
- # This is a method wrapping class. Do not document, but still clean up
189
- # its comment.
190
- should_doc = false
191
- outfile << line.gsub(/\{.*\}(.*)/, "\\1")
192
- elsif (line =~ /# \w+/)
193
- # Itemize member variables
194
- outfile << line.gsub(/# (.*)/, "# - \\1")
195
- elsif (line =~ /class [A-Z].*/)
196
- if should_doc
197
- outfile << line
198
- else
199
- # Avoid documenting the method classes, since they're made invisible
200
- # thanks to our service wrappers
201
- outfile << line.gsub(/(.*)(\w)/, "\\1\\2 #:nodoc: all")
202
- end
203
- else
204
- outfile << line
205
- end
206
- end
207
- end
208
- outfile.close
209
- File.rename(tempfile, file)
210
- end
211
-
212
- # Create options to be used for class generation from WSDL
213
- def get_wsdl_opt(version, service_name)
214
- optcmd= {}
215
- optcmd['classdef'] = service_name
216
- optcmd['force'] = true
217
- optcmd['mapping_registry'] = true
218
- optcmd['driver'] = nil
219
-
220
- # Causes soap4r to wrap the classes it outputs into the given modules
221
- optcmd['module_path'] = [$MODULE.name, version.to_s.capitalize, service_name]
222
- return optcmd
223
- end
224
-
225
- # ====================================================================
226
- # Create a task to build the RDOC documentation tree.
227
- Rake::RDocTask.new("rdoc") do |rdoc|
228
- # Try to use SDoc to generate the docs
229
- begin
230
- require 'sdoc'
231
- rdoc.options << '--fmt' << 'shtml'
232
- rdoc.template = 'direct'
233
- rescue LoadError
234
- # Do nothing, give up on SDoc and continue with whatever is the default.
235
- end
236
- rdoc.rdoc_dir = $DOCDIR
237
- rdoc.title = "#{$PROJECT_NAME} -- Client library for the #{$API_NAME}"
238
- rdoc.main = 'README'
239
- rdoc.rdoc_files.include('README', 'COPYING', 'ChangeLog')
240
- rdoc.rdoc_files.include("#{$LIBDIR}/*.rb", "#{$LIBDIR}/#{$PRODDIR}/*.rb")
241
- rdoc.rdoc_files.include("#{$LIBDIR}/#{$PRODDIR}/v*/*Wrapper.rb")
242
- rdoc.rdoc_files.include("#{$LIBDIR}/#{$PRODDIR}/v*/*Service.rb")
243
- rdoc.rdoc_files.exclude("#{$LIBDIR}/#{$PRODDIR}/soap4rpatches.rb")
244
- end
245
-
246
- # ====================================================================
247
- # Create a task to perform the unit testing.
248
- Rake::TestTask.new("test") do |test|
249
- test.libs << $TESTDIR
250
- test.pattern = "#{$TESTDIR}/**/test_*.rb"
251
- test.verbose = true
252
- end
253
-
254
- # ====================================================================
255
- # Create a task that will package the Rake software into distributable
256
- # gem files.
257
-
258
- # Utility method to create readable version ranges. May not cover a few edge
259
- # cases, but this is a best effort approach.
260
- def readable_version_range(version_string)
261
- return '' if version_string.nil?
262
-
263
- version_string = version_string.to_s.strip
264
- pattern = /^(>|<|>=|<=|~>)(\s*)(\d[\d\.]*)$/
265
- result = pattern.match(version_string)
266
-
267
- return version_string unless result
268
-
269
- case result[1]
270
- when '>'
271
- return 'greater than version ' + result[3]
272
- when '<'
273
- return 'lower than version ' + result[3]
274
- when '>='
275
- return 'version ' + result[3] + ' or later'
276
- when '<='
277
- return 'version ' + result[3] + ' or earlier'
278
- when '~>'
279
- version_pattern = /^(\d[\d\.]*)(\d)$/
280
- version_result = version_pattern.match(result[3])
281
- if version_result
282
- return 'version ' + version_result[1] + 'x'
283
- else
284
- return version_string
285
- end
286
- else
287
- return version_string
288
- end
289
- end
290
-
291
- PKG_FILES = FileList[
292
- '*.*',
293
- 'Rakefile',
294
- "#{$LIBDIR}/**/*.rb",
295
- "#{$LIBDIR}/#{$PRODDIR}/data/*.*",
296
- 'examples/**/*.rb',
297
- "#{$DOCDIR}/**/*.*",
298
- "#{$TESTDIR}/**/*.*"
299
- ]
300
-
301
- PKG_FILES.exclude(/\._/)
302
-
303
- if ! defined?(Gem)
304
- logger.fatal('Package Target requires RubyGems')
305
- else
306
- spec = Gem::Specification.new do |s|
307
-
308
- # Basic information
309
- s.name = $GEM_NAME
310
- s.version = $PKG_VERSION
311
- s.summary = $GEM_SUMMARY
312
- s.description = $GEM_DESCRIPTION
313
-
314
- # Files and dependencies
315
- dependencies = [['soap4r', '= 1.5.8'],
316
- ['httpclient', '>= 2.1.2'],
317
- ['google-ads-common', $ADS_COMMON_VERSION]]
318
- dependencies += $EXTRA_DEPENDENCIES if $EXTRA_DEPENDENCIES
319
- s.files = PKG_FILES.to_a
320
- s.require_path = $LIBDIR
321
- dependencies.each do |dep|
322
- s.add_dependency(dep[0], dep[1])
323
- end
324
-
325
- # RDoc information
326
- s.has_rdoc = true
327
- s.extra_rdoc_files = ['README', 'COPYING', 'ChangeLog']
328
- s.rdoc_options << '--main' << 'README'
329
-
330
- # Metadata
331
- s.authors = $GEM_AUTHORS
332
- s.email = $GEM_EMAIL
333
- s.homepage = $GEM_HOMEPAGE
334
- s.rubyforge_project = $PROJECT_NAME
335
- dependencies.each do |dep|
336
- s.requirements << dep[0] + ' ' + readable_version_range(dep[1])
337
- end
338
- end
339
-
340
- Rake::GemPackageTask.new(spec) do |t|
341
- t.need_tar = true
342
- end
343
- end