simplews 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-10-10
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,24 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/simplews.rb
9
+ lib/simplews/version.rb
10
+ script/console
11
+ script/destroy
12
+ script/generate
13
+ script/txt2html
14
+ setup.rb
15
+ tasks/deployment.rake
16
+ tasks/environment.rake
17
+ tasks/website.rake
18
+ test/test_helper.rb
19
+ test/test_simplews.rb
20
+ website/index.html
21
+ website/index.txt
22
+ website/javascripts/rounded_corners_lite.inc.js
23
+ website/stylesheets/screen.css
24
+ website/template.html.erb
data/PostInstall.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ For more information on simplews, see http://simplews.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,92 @@
1
+ = simpleWS
2
+
3
+ == DESCRIPTION:
4
+
5
+ This defines a class that can simplifies creating Web Services. It inherits from soap2r's
6
+ SOAP::RPC::StandaloneServer and provides a few enhancements, the most important the fact that
7
+ it is able to produce the WSDL automatically.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+
12
+ == SYNOPSIS:
13
+
14
+ Each Web Service provided is described using the method 'serve', which takes
15
+ as arguments the name of the service, the name of its arguments, the type of
16
+ its arguments and an optional block of code. If a block of code is provided,
17
+ it will be the one executed when the service is called, if not, a function
18
+ with the same name will be used. The types for the arguments are listed here,
19
+ along with the WSDL type that it is translated to:
20
+
21
+ :string => 'xsd:string',
22
+ :integer => 'xsd:integer',
23
+ :array => 'tns:ArrayOfString',
24
+ :hash => 'tns:Map',
25
+ :binary => 'xsd:base64Binary',
26
+
27
+ The type of the result value may also be specified using the name :return,
28
+ this means no argument may be called :return. If it is not specified there
29
+ will be no return value.
30
+
31
+ Following is an example of use:
32
+
33
+ class TestWS < SimpleWS
34
+ def hi(name)
35
+ "Hi #{name}, how are you?"
36
+ end
37
+
38
+ def initialize(*args)
39
+ super(*args)
40
+ serve :hi, %(name), :name => :string, :return => :string
41
+
42
+ serve :bye, %(name), :name => :string, :return => :string do |name
43
+ "Bye bye #{name}. See you soon."
44
+ end
45
+ end
46
+ end
47
+
48
+ The constructor accepts a number of parameters. The name of the server, a
49
+ description, the host and the port, along with any other arguments one wishes
50
+ to pass to the SOAP::RPC::StandaloneServer constructor
51
+
52
+ This is an example of instantiating the above server:
53
+
54
+ server = TestWS.new("TestWS", "Greeting Services", 'localhost', '1984')
55
+ server.wsdl("TestWS.wsdl")
56
+
57
+ The function 'wsdl' saves the WSDL describing the services and the location
58
+ provided as an argument.
59
+
60
+
61
+ == REQUIREMENTS:
62
+
63
+ Requires soap4r gem to be installed.
64
+
65
+ == INSTALL:
66
+
67
+ sudo gem install simpleWS
68
+
69
+ == LICENSE:
70
+
71
+ (The MIT License)
72
+
73
+ Copyright (c) 2008 Miguel Vazquez (miguel.vazquez@fdi.ucm.es)
74
+
75
+ Permission is hereby granted, free of charge, to any person obtaining
76
+ a copy of this software and associated documentation files (the
77
+ 'Software'), to deal in the Software without restriction, including
78
+ without limitation the rights to use, copy, modify, merge, publish,
79
+ distribute, sublicense, and/or sell copies of the Software, and to
80
+ permit persons to whom the Software is furnished to do so, subject to
81
+ the following conditions:
82
+
83
+ The above copyright notice and this permission notice shall be
84
+ included in all copies or substantial portions of the Software.
85
+
86
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
87
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
88
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
89
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
90
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
91
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
92
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'simplews/version'
2
+
3
+ AUTHOR = 'Miguel Vazquez' # can also be an array of Authors
4
+ EMAIL = "miguel.vazquez@fdi.ucm.es"
5
+ DESCRIPTION = "Simplifies the development of Web Services, producing WSDL automatically for example. Wraps soap4r."
6
+ GEM_NAME = 'simplews' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'simplews' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ # ['activesupport', '>= 1.3.1']
12
+ ] # An array of rubygem dependencies [name, version]
13
+
14
+ @config_file = "~/.rubyforge/user-config.yml"
15
+ @config = nil
16
+ RUBYFORGE_USERNAME = "unknown"
17
+ def rubyforge_username
18
+ unless @config
19
+ begin
20
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
21
+ rescue
22
+ puts <<-EOS
23
+ ERROR: No rubyforge config file found: #{@config_file}
24
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
25
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
26
+ EOS
27
+ exit
28
+ end
29
+ end
30
+ RUBYFORGE_USERNAME.replace @config["username"]
31
+ end
32
+
33
+
34
+ REV = nil
35
+ # UNCOMMENT IF REQUIRED:
36
+ # REV = YAML.load(`svn info`)['Revision']
37
+ VERS = Simplews::VERSION::STRING + (REV ? ".#{REV}" : "")
38
+ RDOC_OPTS = ['--quiet', '--title', 'simplews documentation',
39
+ "--opname", "index.html",
40
+ "--line-numbers",
41
+ "--main", "README",
42
+ "--inline-source"]
43
+
44
+ class Hoe
45
+ def extra_deps
46
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
47
+ @extra_deps
48
+ end
49
+ end
50
+
51
+ # Generate all the Rake tasks
52
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
53
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
54
+ p.developer(AUTHOR, EMAIL)
55
+ p.description = DESCRIPTION
56
+ p.summary = DESCRIPTION
57
+ p.url = HOMEPATH
58
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
59
+ p.test_globs = ["test/**/test_*.rb"]
60
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
61
+
62
+ # == Optional
63
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
64
+ #p.extra_deps = EXTRA_DEPENDENCIES
65
+
66
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
+ end
68
+
69
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
+ $hoe.rsync_args = '-av --delete --ignore-errors'
73
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -0,0 +1,10 @@
1
+ module Simplews
2
+ module VERSION #:nodoc:
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ self
9
+ end
10
+ end
data/lib/simplews.rb ADDED
@@ -0,0 +1,155 @@
1
+ require 'soap/rpc/standaloneServer'
2
+ require 'builder'
3
+
4
+
5
+ class SimpleWS < SOAP::RPC::StandaloneServer
6
+
7
+
8
+ def initialize(name="WS", description="", host="localhost", port="1984", *args)
9
+ super(description, "urn:#{ name }", host, port, *args)
10
+ @host = host
11
+ @port = port
12
+ @name = name
13
+ @description = description
14
+ @messages = []
15
+ @operations = []
16
+ @bindings = []
17
+ end
18
+
19
+ def serve(name, args=[], types={}, &block)
20
+
21
+ if block
22
+ add_to_ruby(name, &block)
23
+ end
24
+
25
+ add_to_wsdl(name, args, types)
26
+ add_method(self,name.to_s,*args)
27
+
28
+ nil
29
+ end
30
+
31
+ def wsdl(filename = nil)
32
+ wsdl = WSDL_STUB.dup
33
+ wsdl.gsub!(/\$\{MESSAGES\}/m,@messages.join("\n"))
34
+ wsdl.gsub!(/\$\{OPERATIONS\}/m,@operations.join("\n"))
35
+ wsdl.gsub!(/\$\{BINDINGS\}/m,@bindings.join("\n"))
36
+ wsdl.gsub!(/\$\{NAME\}/,@name)
37
+ wsdl.gsub!(/\$\{DESCRIPTION\}/,@description)
38
+ wsdl.gsub!(/\$\{LOCATION\}/,"http://#{ @host }:#{ @port }")
39
+ if filename
40
+ fwsdl = File.open(filename,'w')
41
+ fwsdl.write(wsdl)
42
+ fwsdl.close
43
+ nil
44
+ else
45
+ wsdl
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def add_to_ruby(name, &block)
52
+ self.class.send(:define_method, name, block)
53
+ end
54
+
55
+ def add_to_wsdl(name, args, types)
56
+ message = Builder::XmlMarkup.new(:indent => 2).message :name => "#{ name }Request" do |xml|
57
+ args.each{|param|
58
+ type = types[param.to_s] || types[param.to_sym] || :string
59
+ type = type.to_sym
60
+ xml.part :name => param, :type => @@type2wsdl[type]
61
+ }
62
+ end
63
+ @messages << message
64
+ message = Builder::XmlMarkup.new(:indent => 2).message :name => "#{ name }Response" do |xml|
65
+ type = types[:return] || types["return"]
66
+ if type
67
+ type = type.to_sym
68
+ xml.part :name => 'return', :type => @@type2wsdl[type]
69
+ end
70
+ end
71
+ @messages << message
72
+
73
+ operation = Builder::XmlMarkup.new(:indent => 2).operation :name => "#{ name }" do |xml|
74
+ xml.input :message => "#{ name }Request"
75
+ xml.output :message => "#{ name }Response"
76
+ end
77
+
78
+ @operations << operation
79
+
80
+ binding = Builder::XmlMarkup.new(:indent => 2).operation :name => "#{ name }" do |xml|
81
+ xml.tag! 'soap:operation'.to_sym, :soapAction => "urn:${NAME}##{name}", :style => 'rpc'
82
+ xml.input do |xml|
83
+ xml.tag! 'soap:body'.to_sym, :namespace => "urn:${NAME}", :encodingStyle => "http://schemas.xmlsoap.org/soap/encoding/", :use => "encoded"
84
+ end
85
+ xml.output do |xml|
86
+ xml.tag! 'soap:body'.to_sym, :namespace => "urn:${NAME}", :encodingStyle => "http://schemas.xmlsoap.org/soap/encoding/", :use => "encoded"
87
+ end
88
+ end
89
+
90
+ @bindings << binding
91
+
92
+ end
93
+
94
+ WSDL_STUB =<<EOT
95
+ <?xml version="1.0"?>
96
+ <definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
97
+ xmlns:tns="${NAME}-NS"
98
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
99
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
100
+ xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
101
+ xmlns:si="http://soapinterop.org/xsd"
102
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
103
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
104
+ xmlns="http://schemas.xmlsoap.org/wsdl/"
105
+ targetNamespace="${NAME}-NS">
106
+
107
+
108
+ <types>
109
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
110
+ targetNamespace="${NAME}-NS"
111
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
112
+ xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
113
+ <complexType name="ArrayOfString">
114
+ <complexContent>
115
+ <restriction base="soapenc:Array">
116
+ <attribute ref="soapenc:arrayType"
117
+ wsdl:arrayType="string[]"/>
118
+ </restriction>
119
+ </complexContent>
120
+ </complexType>
121
+ </schema>
122
+ </types>
123
+
124
+ ${MESSAGES}
125
+ <portType name="${NAME}">
126
+ ${OPERATIONS}
127
+ </portType>
128
+
129
+ <binding name="${NAME}Binding" type="tns:${NAME}">
130
+ <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
131
+ ${BINDINGS}
132
+ </binding>
133
+ <service name="${NAME}">
134
+ <documentation>${DESCRIPTION}</documentation>
135
+
136
+ <port name="${NAME}" binding="tns:${NAME}Binding">
137
+ <soap:address location="${LOCATION}"/>
138
+ </port>
139
+ </service>
140
+
141
+ </definitions>
142
+ EOT
143
+
144
+ @@type2wsdl = {
145
+ :string => 'xsd:string',
146
+ :integer => 'xsd:integer',
147
+ :array => 'tns:ArrayOfString',
148
+ :hash => 'tns:Map',
149
+ :binary => 'xsd:base64Binary',
150
+ }
151
+
152
+
153
+ end
154
+
155
+
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/simplews.rb'}"
9
+ puts "Loading simplews gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/script/txt2html ADDED
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ GEM_NAME = 'simplews' # what ppl will type to install your gem
4
+ RUBYFORGE_PROJECT = 'simplews'
5
+
6
+ require 'rubygems'
7
+ begin
8
+ require 'newgem'
9
+ require 'rubyforge'
10
+ rescue LoadError
11
+ puts "\n\nGenerating the website requires the newgem RubyGem"
12
+ puts "Install: gem install newgem\n\n"
13
+ exit(1)
14
+ end
15
+ require 'redcloth'
16
+ require 'syntax/convertors/html'
17
+ require 'erb'
18
+ require File.dirname(__FILE__) + "/../lib/#{GEM_NAME}/version.rb"
19
+
20
+ version = Simplews::VERSION::STRING
21
+ download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
22
+
23
+ def rubyforge_project_id
24
+ RubyForge.new.configure.autoconfig["group_ids"][RUBYFORGE_PROJECT]
25
+ end
26
+
27
+ class Fixnum
28
+ def ordinal
29
+ # teens
30
+ return 'th' if (10..19).include?(self % 100)
31
+ # others
32
+ case self % 10
33
+ when 1: return 'st'
34
+ when 2: return 'nd'
35
+ when 3: return 'rd'
36
+ else return 'th'
37
+ end
38
+ end
39
+ end
40
+
41
+ class Time
42
+ def pretty
43
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
44
+ end
45
+ end
46
+
47
+ def convert_syntax(syntax, source)
48
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
49
+ end
50
+
51
+ if ARGV.length >= 1
52
+ src, template = ARGV
53
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
54
+ else
55
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
56
+ exit!
57
+ end
58
+
59
+ template = ERB.new(File.open(template).read)
60
+
61
+ title = nil
62
+ body = nil
63
+ File.open(src) do |fsrc|
64
+ title_text = fsrc.readline
65
+ body_text_template = fsrc.read
66
+ body_text = ERB.new(body_text_template).result(binding)
67
+ syntax_items = []
68
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
69
+ ident = syntax_items.length
70
+ element, syntax, source = $1, $2, $3
71
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
72
+ "syntax-temp-#{ident}"
73
+ }
74
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
75
+ body = RedCloth.new(body_text).to_html
76
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
77
+ end
78
+ stat = File.stat(src)
79
+ created = stat.ctime
80
+ modified = stat.mtime
81
+
82
+ $stdout << template.result(binding)