-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
1896095
commit d01e157
Showing
6 changed files
with
60 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'rubygems' | ||
require 'service_proxy/base' | ||
|
||
class %name% < ServiceProxy::Base | ||
%body% | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters