Rakefile in adwords4r-0.2 vs Rakefile in adwords4r-0.3

- old
+ new

@@ -18,11 +18,11 @@ # Determine the current version of the software CLOBBER.include('pkg') -CURRENT_VERSION = '0.2' +CURRENT_VERSION = '0.3' PKG_VERSION = ENV['REL'] ? ENV['REL'] : CURRENT_VERSION SRC_RB = FileList['lib/**/*.rb'] # The default task is run if rake is given no explicit arguments. @@ -60,35 +60,32 @@ worker.location = getWsdlFileName(vname,name) worker.basedir = gendir worker.opt.update(getWsdlOpt(name)) worker.run fixImport(v, File.join(gendir, "#{name}Driver.rb")) + #fixImport(v, File.join(gendir, "#{name}.rb")) end end end def fixImport(version, file) vname = "v#{version}" tempfile = file + '.tmp' outfile = File.new(tempfile,"w") File.open(file, "r") do |infile| - req = 0 +# outfile.puts "module AdWords" + #outfile.puts "module AdWordsV#{version}" infile.each do |l| - if (l =~/require/) then + if (l =~/require.*Service.rb/) then # outfile.puts l.gsub(/require \'(.*)Service.rb\'/, 'require #\'adwords4r/' + vname + '/\1Service\'') outfile.puts l.gsub(/require \'(.*)Service.rb\'/, 'require \'adwords4r/' + vname + '/\1Service\'') - req = req + 1 else - if (req == 2) then - outfile.puts "module AdWordsV#{version}" - req = req + 1 - end outfile.puts l end end + # outfile.puts "end" end - outfile.puts "end" outfile.close File.rename(tempfile, file) end @@ -115,14 +112,28 @@ https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE https.start { |w| w.get2(path).body } end +def fix_attribute(text, name, type) + text.gsub!(Regexp.new("#{name}=\"#{type}\""),"#{name}=\"xsd:#{type}\"") +end + +def fixWsdl(wsdl) + ['type', 'base'].each {|name| ['long', 'string', 'date', 'int', 'boolean'].each {|type| fix_attribute(wsdl, name, type)}} + schema_ns = "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" + if wsdl !~ Regexp.new(schema_ns) + wsdl.gsub!(/(<wsdl:definitions[^>]*)>/, '\1 ' + schema_ns + '>') + end + return wsdl + #wsdl.gsub(/type=\"long\"/, 'type="xsd:long"') +end + # Saves this document to the specified @var path. #doesn't create the file if contains markup for google 404 page def save(content, path) if content !~ /<H2>Error 404<\/H2>/ - File::open(path, 'w') {|f| f.write(content)} + File::open(path, 'w') {|f| f.write(fixWsdl(content))} end end # ==================================================================== # Create a task that will package the Rake software into distributable