Permalink
Browse files

initial import

  • Loading branch information...
1 parent 413b132 commit 7fd5bc3f92e68cb16d623daa2243569534074f92 chanezon committed Sep 6, 2006
Showing with 12,706 additions and 0 deletions.
  1. +2 −0 Authors.txt
  2. +11 −0 ChangeLog.txt
  3. +28 −0 Copying.txt
  4. +10 −0 Licence.txt
  5. +208 −0 Rakefile
  6. +79 −0 Readme.txt
  7. +29 −0 Todo.txt
  8. +7 −0 adwords.properties
  9. +38 −0 examples/campaign.rb
  10. +6 −0 examples/framework.rb
  11. +16 −0 examples/get_free_usage_this_month.rb
  12. +16 −0 examples/get_unit_count.rb
  13. +27 −0 examples/keyword_tool_demo.rb
  14. +31 −0 examples/traffic_estimator.rb
  15. +162 −0 lib/adwords4r.rb
  16. +43 −0 lib/adwords4r/credentials.rb
  17. +37 −0 lib/adwords4r/services.rb
  18. +709 −0 lib/adwords4r/v4/AccountService.rb
  19. +174 −0 lib/adwords4r/v4/AccountServiceDriver.rb
  20. +316 −0 lib/adwords4r/v4/AdGroupService.rb
  21. +97 −0 lib/adwords4r/v4/AdGroupServiceDriver.rb
  22. +527 −0 lib/adwords4r/v4/CampaignService.rb
  23. +111 −0 lib/adwords4r/v4/CampaignServiceDriver.rb
  24. +368 −0 lib/adwords4r/v4/CreativeService.rb
  25. +104 −0 lib/adwords4r/v4/CreativeServiceDriver.rb
  26. +411 −0 lib/adwords4r/v4/CriterionService.rb
  27. +97 −0 lib/adwords4r/v4/CriterionServiceDriver.rb
  28. +260 −0 lib/adwords4r/v4/InfoService.rb
  29. +90 −0 lib/adwords4r/v4/InfoServiceDriver.rb
  30. +543 −0 lib/adwords4r/v4/KeywordService.rb
  31. +125 −0 lib/adwords4r/v4/KeywordServiceDriver.rb
  32. +227 −0 lib/adwords4r/v4/KeywordToolService.rb
  33. +55 −0 lib/adwords4r/v4/KeywordToolServiceDriver.rb
  34. +575 −0 lib/adwords4r/v4/ReportService.rb
  35. +83 −0 lib/adwords4r/v4/ReportServiceDriver.rb
  36. +274 −0 lib/adwords4r/v4/TrafficEstimatorService.rb
  37. +62 −0 lib/adwords4r/v4/TrafficEstimatorServiceDriver.rb
  38. +853 −0 lib/adwords4r/v5/AccountService.rb
  39. +188 −0 lib/adwords4r/v5/AccountServiceDriver.rb
  40. +352 −0 lib/adwords4r/v5/AdGroupService.rb
  41. +97 −0 lib/adwords4r/v5/AdGroupServiceDriver.rb
  42. +563 −0 lib/adwords4r/v5/CampaignService.rb
  43. +111 −0 lib/adwords4r/v5/CampaignServiceDriver.rb
  44. +404 −0 lib/adwords4r/v5/CreativeService.rb
  45. +104 −0 lib/adwords4r/v5/CreativeServiceDriver.rb
  46. +447 −0 lib/adwords4r/v5/CriterionService.rb
  47. +97 −0 lib/adwords4r/v5/CriterionServiceDriver.rb
  48. +296 −0 lib/adwords4r/v5/InfoService.rb
  49. +90 −0 lib/adwords4r/v5/InfoServiceDriver.rb
  50. +263 −0 lib/adwords4r/v5/KeywordToolService.rb
  51. +55 −0 lib/adwords4r/v5/KeywordToolServiceDriver.rb
  52. +788 −0 lib/adwords4r/v5/ReportService.rb
  53. +83 −0 lib/adwords4r/v5/ReportServiceDriver.rb
  54. +310 −0 lib/adwords4r/v5/TrafficEstimatorService.rb
  55. +62 −0 lib/adwords4r/v5/TrafficEstimatorServiceDriver.rb
  56. +1,585 −0 setup.rb
View
@@ -0,0 +1,2 @@
+opensource@google.com
+chanezon@google.com
View
@@ -0,0 +1,11 @@
+0.6
+- added support for API v5
+- added support for alternateUrl header, in order to work with sandbox
+- tested with sandbox
+0.5 Now supports AdWords API v4. Got rid of yaml dependency. Changed properties file name for default credentials to adwords.properties. Enhanced the readme.txt a bit. Added a few samples.
+0.4 Now all generated classes are within the Adwords module. Will make it easier to use that in Rails. Support for gen classes in a module is not implemented in soap4r for doc/literal style (it works for rpc/encoded). I logged a bug for soap4r. In the meantime I had to fix adwords4r from my module using module_eval to patch the Mapping class.
+0.3 fixed the bug in InfoService and many others. I fix the wsdl before generation.
+0.2 added packaging, made it a gem, and added a setup program, for easy installation in all configurations (gem and non gem).
+0.1 -first version, not fully tested
+works for Campaigns
+
View
@@ -0,0 +1,28 @@
+Copyright (c) 2006, Google Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+ * Neither the name of Google Inc. nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -0,0 +1,10 @@
+Copyright (c) 2006, Google Inc
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+ * Neither the name of Google, Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -0,0 +1,208 @@
+require 'wsdl/soap/wsdl2ruby'
+require 'net/https'
+require 'fileutils'
+require 'rake/clean'
+require 'logger'
+begin
+ require 'rubygems'
+ require 'rake/gempackagetask'
+rescue Exception
+ nil
+end
+begin
+ require 'lib/adwords4r/services'
+rescue Exception
+ puts 'require services not found'
+ nil
+end
+
+# Determine the current version of the software
+
+CLOBBER.include('pkg')
+
+CURRENT_VERSION = '0.6'
+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.
+
+#desc "Default Task"
+#task :default => :test_all
+
+WSDLDIR = 'wsdl'
+LIBDIR = 'lib'
+GENDIR = LIBDIR + '/adwords4r'
+
+logger = Logger.new(STDERR)
+
+CLEAN.include(WSDLDIR)
+AdWords::Service.getVersions.each do |v|
+ vname = "v#{v}"
+ CLEAN.include(File.join(GENDIR, vname))
+end
+
+desc "gets the wsdl and generates the classes"
+task :default => [:getwsdl, :generate]
+
+desc "gets the wsdl files for AdWords services"
+task :getwsdl do
+ AdWords::Service.getVersions.each do |v|
+ vname = "v#{v}"
+ mkdir_p File.join(WSDLDIR, vname)
+ AdWords::Service.getServices(v).each {|s| save(getfile("adwords.google.com", "/api/adwords/#{vname}/#{s}Service?wsdl"), getWsdlFileName(vname,s))}
+ end
+end
+
+desc "generates AdWords classes from the wsdl files"
+task :generate do
+ AdWords::Service.getVersions.each do |v|
+ vname = "v#{v}"
+ gendir = "#{LIBDIR}/adwords4r/#{vname}"
+ mkdir_p gendir
+ AdWords::Service.getServices(v).each do |name|
+ worker = WSDL::SOAP::WSDL2Ruby.new
+ worker.logger = logger
+ 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|
+ outfile.puts "module AdWords"
+ #outfile.puts "module AdWordsV#{version}"
+ infile.each do |l|
+ 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\'')
+ else
+ outfile.puts l
+ end
+ end
+ outfile.puts "end"
+ end
+ outfile.close
+ File.rename(tempfile, file)
+end
+
+
+def getWsdlOpt(s)
+ optcmd= {}
+ s << "Service"
+ optcmd['classdef'] = s
+ #should work but doesn't, driver name is derived from classname
+ #if you specify both it breaks, same thing for client_skelton
+ #optcmd['driver'] = s
+ optcmd['driver'] = nil
+ #optcmd['client_skelton'] = nil
+ optcmd['force'] = true
+ return optcmd
+end
+
+def getWsdlFileName(v,s)
+ "#{WSDLDIR}/#{v}/#{s}.wsdl"
+end
+
+def getfile(host, path)
+ puts "getting https//#{host}#{path}"
+ https = Net::HTTP.new(host, 443)
+ 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(fixWsdl(content))}
+ end
+end
+
+# ====================================================================
+# Create a task that will package the Rake software into distributable
+# gem files.
+
+PKG_FILES = FileList[
+ '*.*',
+ 'Rakefile',
+ 'lib/**/*.rb',
+ 'examples/**/*.rb',
+# 'test/**/*.rb',
+ 'scripts/**/*.rb'
+]
+
+puts PKG_FILES
+
+PKG_FILES.exclude(/\._/)
+
+if ! defined?(Gem)
+ puts "Package Target requires RubyGEMs"
+else
+ spec = Gem::Specification.new do |s|
+
+ #### Basic information.
+
+ s.name = 'adwords4r'
+ s.version = PKG_VERSION
+ s.summary = "Client library for the AdWords API."
+ s.description = %{\
+Adwords4r provides an easy to use way to access the AdWords API in ruby.\
+Currently the following AdWords API versions are supported:\
+\
+* V4\
+* V5\
+}
+
+ s.files = PKG_FILES.to_a
+ s.require_path = 'lib'
+ s.autorequire = 'adwords4r'
+
+ #s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }
+
+ #s.has_rdoc = true
+ s.has_rdoc = false
+ #s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
+ #s.rdoc_options <<
+# '--title' << 'Builder -- Easy XML Building' <<
+# '--main' << 'README' <<
+# '--line-numbers'
+
+ s.author = "Patrick Chanezon"
+ s.email = "patrick@chanezon.com"
+ s.homepage = "http://rubyforge.org/projects/adwords4r/"
+ s.requirements << 'soap4r v 1.5.4 or greater'
+ s.requirements << 'http-access2 v 2.0.5 or greater'
+ s.rubyforge_project = 'adwords4r'
+ end
+
+ Rake::GemPackageTask.new(spec) do |t|
+ t.need_tar = true
+ end
+end
+
+#require 'scripts/publish'
+
View
@@ -0,0 +1,79 @@
+Google adwwords4r Library
+----------------------
+
+Welcome to adwords4r, bringing the delights of ruby programming to the AdWords world: AdWords::API.new.getAllAdWordsCampaigns(123).each {|c| puts c.name}
+
+Not much doc or comments yet
+
+docs for users
+--------------
+
+adwords4r is a ruby gem. See http://docs.rubygems.org/read/book/1
+Install it using the gem install command.
+> gem install --remote adwords4r
+
+It's pretty easy to use.
+See http://docs.rubygems.org/read/chapter/3#page70 for how to set the rubygem environment.
+export RUBYOPT=rubygems
+or ruby -rubygems my_program_that_uses_gems
+
+If you do not use the rubygems option, you need to add
+require 'rubygems'
+at the beginning of your programs.
+
+Then
+require 'adwords4r'
+
+adwords = AdWords::API.new
+creates a driver for the latest version of AdWords API using credentials provided in ~/adwords.properties
+There is an example in the root adwords4r directory.
+You can also pass API a manually constructed AdWordsCredentials object like:
+adwords = AdWords::API.new(AdWords::AdWordsCredentials.new(
+{ 'token' => 'mytoken',
+ 'useragent' => 'P@ playing with the API from ruby',
+ 'password' => 'mypasswd',
+ 'email' => 'em...@example.com'}
+))
+
+If you want something more specific, use the optional parameters of the constructor
+adwords = AdWords::API.new(credentials, version)
+
+In order to use the sandbox, you can add a credential named
+alternateUrl, like:
+alternateUrl=https://sandbox.google.com/api/adwords/v5/
+
+Then just use methods of the API against your driver.
+adwords.getAllAdWordsCampaigns(123).each {|c| puts c.name}
+
+See sample code in examples.
+
+The client code will generate warnings in the console:
+Many: warning: already initialized constant XXX
+A few: at depth 0 - 20: unable to get local issuer certificate
+These are not serious: I need to make them go but they do not affect the correctness of the program.
+
+docs for developers
+-------------------
+rake getwsdl
+ to get the wsdl files
+rake generate
+ to regenerate the bindings if needed
+rake package
+ to package the gem and create a release
+rake publish
+ to publish the gem to rubyforge
+
+adwords4r is licensed under the BSD License
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+It is fun to use adwords4r anyway...
View
@@ -0,0 +1,29 @@
+adwords4r todo list
+---
+- use XSD::CodeGen::GenSupport.capitalize and unCapitalize instead of my own methods
+- use SOAP::Property.loadproperty
+0% ruby -rpp -rsoap/property -e 'pp
+SOAP::Property.loadproperty("adwords.properties")'
+#<SOAP::Property:0xb7ebd5b8
+ @hook={},
+ @locked=false,
+ @self_hook=[],
+ @store=
+ {"password"=>"my_very_secret_password",
+ "useragent"=>"P@ playing with the API from ruby",
+ "token"=>"my_token",
+ "email"=>"toto@example.com"}>
+- fix the bug in reports
+- handling quota management in the driver
+- pass in a hash for complex objects
+- comments everywhere, rdoc
+- documentation
+- more samples: traffic_estimator, report,
+
+OK- generate v4
+OK- get rid of yaml dependency
+OK- change the property file name to adwords.properties
+OK- make it work with all generated classes in their own module
+OK- fix bug in InfoService
+OK- gem file
+OK- traditional setup file
View
@@ -0,0 +1,7 @@
+token=my_token
+useragent=P@ playing with the API from ruby
+password=my_very_secret_password
+email=toto@example.com
+#clientEmail=titi@example.com
+#applicationToken=
+#alternateUrl=https://sandbox.google.com/api/adwords/v5/
Oops, something went wrong.

0 comments on commit 7fd5bc3

Please sign in to comment.