Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
Removed thor dependency
Added wsdl2proxy executable
Moved service_proxy/base
Added proxy generator template
Updated specs to pass with new file heirarchy
  • Loading branch information
jeremydurham committed Jan 27, 2009
1 parent 1896095 commit d01e157
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 25 deletions.
26 changes: 16 additions & 10 deletions README
Expand Up @@ -2,32 +2,27 @@ ServiceProxy

ServiceProxy is a lightweight SOAP library for Ruby.

How it works
HOW IT WORKS

Loading the library:

require 'rubygems'
require 'service_proxy'
require 'service_proxy/base'

Using the library:
WRITING A PROXY BY HAND

Unlike SOAP4R, this library takes a very different approach to building
Unlike Soap4R, this library takes a very different approach to building
requests and parsing responses. There is little magic and no code
generation with this library.

You will need to understand some simple things about SOAP before you
can use this library. Using a tool like SOAPUI or SoapClient, you can
easily get enough information to use this library with existing SOAP
services.

For each service endpoint you want to connect to, you will need to
subclass ServiceProxy.

Let's say you want to call the method cool1 on a service:

First, you create a subclass:

class SuperCoolService < ServiceProxy
class SuperCoolService < ServiceProxy::Base

def build_cool1(options)
# This will generate a simple SOAP envelope. Using the xml block local, you
Expand All @@ -51,6 +46,17 @@ Next, you can attempt to call the service:
service = SuperCoolService.new(url_to_wsdl)
service.cool1

GENERATING A PROXY

ServiceProxy comes with a simple generator to get started. It can be invoked
as follows:

wsdl2proxy [wsdl]

This will generate a file named default.rb, in the current directory. The class
will be named GeneratedService, and will define build and parse methods for all
of the available service methods.

CONTRIBUTORS

Rich Cavanaugh
7 changes: 3 additions & 4 deletions Rakefile
Expand Up @@ -3,7 +3,7 @@ require 'rake/gempackagetask'
require 'rubygems/specification'
require 'rake/rdoctask'
require 'spec/rake/spectask'
require File.join(File.dirname(__FILE__), 'lib', 'service_proxy')
require File.join(File.dirname(__FILE__), 'lib', 'service_proxy', 'base')

NAME = "serviceproxy"
AUTHOR = "Jeremy Durham"
Expand Down Expand Up @@ -36,12 +36,11 @@ spec = Gem::Specification.new do |s|
s.email = EMAIL
s.homepage = HOMEPAGE
s.require_path = 'lib'
s.executables = ['wsdl2proxy']
s.executables = ['wsdl2proxy']
s.files = %w(LICENSE README Rakefile) + Dir.glob("{lib,spec}/**/*")

s.add_dependency "nokogiri"
s.add_dependency "hpricot"
s.add_dependency "thor"
end

Rake::GemPackageTask.new(spec) do |pkg|
Expand Down Expand Up @@ -93,4 +92,4 @@ namespace :spec do
end

desc 'Default: run unit tests.'
task :default => 'spec'
task :default => 'spec'
42 changes: 33 additions & 9 deletions bin/wsdl2proxy
@@ -1,16 +1,40 @@
#!/usr/bin/env ruby

require 'rubygems'
require 'thor'
require 'service_proxy'
require 'service_proxy/base'

module ServiceProxy
class Generator < Thor
desc "generate [endpoint] [filename]",
"parse endpoint and generate stubs"
def generate(endpoint, filename)
def underscore(camel_cased_word)
camel_cased_word.to_s.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("-", "_").
downcase
end

unless ARGV.size > 0
puts "Usage: #{$0} [endpoint]"
exit!
end

template_filename = File.dirname(__FILE__) + '/../lib/templates/proxy.rbt'
proxy = ServiceProxy::Base.new(ARGV[0])
output_filename = 'default.rb'
output = ''
proxy.service_methods.each do |service_method|
output << <<-EOS
def build_#{underscore(service_method)}(options)
soap_envelope(options) do |xml|
end
end
def parse_#{underscore(service_method)}(response)
Hpricot.XML(response.body)
end
EOS
end

ServiceProxy::Generator.start
template = File.read(template_filename)
template.gsub!(/%name%/, 'GeneratedService')
template.gsub!(/%body%/, output)
File.open(output_filename, 'w') { |f| f.puts template }
puts "Generated proxy #{output_filename} - You can use the proxy by executing GeneratedService.new('#{ARGV[0]}')"
File renamed without changes.
6 changes: 6 additions & 0 deletions lib/templates/proxy.rbt
@@ -0,0 +1,6 @@
require 'rubygems'
require 'service_proxy/base'

class %name% < ServiceProxy::Base
%body%
end
4 changes: 2 additions & 2 deletions spec/service_proxy_spec.rb
@@ -1,7 +1,7 @@
require 'rubygems'
require 'spec'
require File.dirname(__FILE__) + '/../lib/service_proxy.rb'
require File.dirname(__FILE__) + '/service_helper.rb'
require File.dirname(__FILE__) + '/../lib/service_proxy/base'
require File.dirname(__FILE__) + '/service_helper'

describe ServiceProxy do
it "should raise on an invalid URI" do
Expand Down

0 comments on commit d01e157

Please sign in to comment.