shapewear 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ree@shapewear
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ # https://github.com/travis-ci/travis-ci/wiki/.travis.yml-options
2
+ script: "bundle exec rake"
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - ree
8
+ - rbx
9
+ - rbx-2.0
10
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Elementar Sistemas Ltda
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ shapewear [![Build Status](https://secure.travis-ci.org/elementar/shapewear.png)](http://travis-ci.org/elementar/shapewear)
2
+ =========
3
+
4
+ Make your fat service look skinny.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Shapewear is available through [Rubygems](http://rubygems.org/gems/shapewear) and can be installed via:
10
+
11
+ ```
12
+ $ gem install shapewear
13
+ ```
14
+
15
+ Introduction
16
+ ------------
17
+
18
+ First, describe your SOAP service:
19
+
20
+ ``` ruby
21
+ require "shapewear"
22
+
23
+ class MyFirstService
24
+ include Shapewear::DSL
25
+
26
+ def hello(name)
27
+ "hello, #{name}"
28
+ end
29
+
30
+ def sum(x, y)
31
+ x + y
32
+ end
33
+ end
34
+ ```
35
+
36
+ Then bind to your web application in a non-intrusive way.
37
+
38
+ Rails example:
39
+
40
+ ``` ruby
41
+ # don't forget to write the appropriate routes
42
+ class MyFirstServiceController < ApplicationController
43
+ def wsdl
44
+ render :xml => MyHelloService.to_wsdl
45
+ end
46
+
47
+ def serve
48
+ render :xml => MyHelloService.serve(params)
49
+ end
50
+ end
51
+ ```
52
+
53
+ Sinatra example:
54
+
55
+ ``` ruby
56
+ class MySinatraApp < Sinatra::App
57
+ get "my_first_service/wsdl" do
58
+ content_type "application/xml"
59
+ MyHelloService.to_wsdl
60
+ end
61
+
62
+ post "my_first_service" do
63
+ content_type "application/xml"
64
+ MyHelloService.serve(params)
65
+ end
66
+ end
67
+ ```
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
data/lib/shapewear.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'nokogiri'
2
+
3
+ require 'shapewear/version'
4
+ require 'shapewear/dsl'
5
+
6
+ # defines String.camelize if it is not defined by, e.g. Rails
7
+ unless String.respond_to? :camelize
8
+ class String
9
+ def camelize
10
+ self.split('_').map(&:capitalize).join
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,107 @@
1
+ require 'builder'
2
+
3
+ module Shapewear
4
+ module DSL
5
+ def self.included(receiver)
6
+ receiver.extend(ClassMethods)
7
+ end
8
+
9
+ #noinspection RubyArgCount,RubyResolve
10
+ module ClassMethods
11
+
12
+ # reference: http://www.w3.org/TR/wsdl
13
+ def to_wsdl
14
+ tns = "http://shapewear.elementarsistemas.com.br/auto/#{self.name}.wsdl"
15
+ xsd = "http://shapewear.elementarsistemas.com.br/auto/#{self.name}.xsd"
16
+
17
+ xm = Builder::XmlMarkup.new
18
+
19
+ xm.instruct!
20
+ xm.definitions :name => self.name, 'targetNamespace' => tns,
21
+ 'xmlns' => 'http://schemas.xmlsoap.org/wsdl/',
22
+ 'xmlns:soap' => 'http://schemas.xmlsoap.org/wsdl/soap/',
23
+ 'xmlns:xsd1' => xsd, 'tns' => tns do |xdef|
24
+
25
+ xdef.types do |xtypes|
26
+ xtypes.schema 'xmlns' => 'http://www.w3.org/2000/10/XMLSchema', 'targetNamespace' => xsd do |xschema|
27
+
28
+ # define elements for each defined method
29
+ instance_methods(false).each do |m|
30
+ build_type_elements_for_method(m, xschema)
31
+ end
32
+ end
33
+ end
34
+
35
+ instance_methods(false).each do |m|
36
+ xdef.message :name => "#{m.camelize}Input" do |xmsg|
37
+ xmsg.part :name => :body, :element => "xsd1:#{m.camelize}Request"
38
+ end unless instance_method(m).arity == 0
39
+ xdef.message :name => "#{m.camelize}Output" do |xmsg|
40
+ xmsg.part :name => :body, :element => "xsd1:#{m.camelize}"
41
+ end
42
+ end
43
+
44
+ xdef.portType :name => "#{self.name}PortType" do |xpt|
45
+ instance_methods(false).each do |m|
46
+ xpt.operation :name => m.camelize do |xop|
47
+ xop.input :message => "tns:#{m.camelize}Input" unless instance_method(m).arity == 0
48
+ xop.output :message => "tns:#{m.camelize}Output"
49
+ end
50
+ end
51
+ end
52
+
53
+ xdef.binding :name => "#{self.name}Binding", :type => "tns:#{self.name}PortType" do |xbind|
54
+ xbind.tag! 'soap:binding', :style => 'document', :transport => 'http://schemas.xmlsoap.org/soap/http'
55
+ instance_methods(false).each do |m|
56
+ xbind.operation :name => m.camelize do |xop|
57
+ xbind.tag! 'soap:operation', :soapAction => "http://shapewear.elementarsistemas.com.br/auto/op/#{m.camelize}"
58
+ xbind.input { |xin| xin.tag! 'soap:body', :use => 'literal' } unless instance_method(m).arity == 0
59
+ xbind.output { |xin| xin.tag! 'soap:body', :use => 'literal' }
60
+ end
61
+ end
62
+ end
63
+
64
+ xdef.service :name => self.name do |xsrv|
65
+ xsrv.documentation "WSDL auto-generated by shapewear."
66
+ xsrv.port :name => "#{self.name}Port", :binding => "#{self.name}Binding" do |xport|
67
+ xport.tag! 'soap:address', :location => "..." # TODO: let the developer configure
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ def build_type_elements_for_method(m, xschema)
74
+ # element for method arguments
75
+ um = instance_method(m)
76
+
77
+ if um.arity > 0
78
+ xschema.element :name => "#{m.camelize}Request" do |xreq|
79
+ xreq.complexType do |xct|
80
+ xct.all do |xall|
81
+ if um.respond_to?(:parameters)
82
+ # with Ruby 1.9, we can create the parameters with the correct names
83
+ params = um.parameters.select { |p| p.first == :in }.map &:first
84
+ else
85
+ params = (0..um.arity).map { |i| "arg#{i}" }
86
+ end
87
+
88
+ params.each do |p|
89
+ xall.element :name => p, :type => 'xsd:string' # TODO: there must be a better way
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ # element for method result
97
+ xschema.element :name => "#{m.camelize}" do |xreq|
98
+ xreq.complexType do |xct|
99
+ xct.all do |xall|
100
+ xall.element :name => 'result', :type => 'xsd:string'
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,5 @@
1
+ module Shapewear
2
+
3
+ Version = "0.0.1"
4
+
5
+ end
data/shapewear.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $:.unshift lib unless $:.include? lib
3
+
4
+ require 'shapewear/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "shapewear"
8
+ s.version = Shapewear::Version
9
+ s.authors = "Fábio Batista"
10
+ s.email = "fabio@elementarsistemas.com.br"
11
+ s.homepage = "https://github.com/elementar/shapewear"
12
+ s.summary = "Make your fat service look skinny"
13
+ s.description = "Shapewear is a Ruby library for handling SOAP requests from within your Rails or Sinatra application. It makes your fat services look skinny."
14
+
15
+ s.rubyforge_project = s.name
16
+
17
+ s.add_dependency "builder", ">= 2.1.2"
18
+ s.add_dependency "nokogiri", ">= 1.5.0"
19
+
20
+ s.add_development_dependency "rake", "~> 0.9.2"
21
+ s.add_development_dependency "rspec", "~> 2.7.0"
22
+
23
+ s.files = `git ls-files`.split("\n")
24
+ s.require_path = "lib"
25
+ end
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+
3
+ describe Shapewear::DSL do
4
+
5
+ let(:xmlns) { {'wsdl' => 'http://schemas.xmlsoap.org/wsdl/', 'soap' => 'http://schemas.xmlsoap.org/wsdl/soap/'} }
6
+
7
+ describe "basic DSL" do
8
+ it "should describe parameterless, 'hello world' services" do
9
+ class ParameterlessHelloWorldService
10
+ include Shapewear::DSL
11
+
12
+ def hello_world
13
+ "hello"
14
+ end
15
+ end
16
+
17
+ wsdl = ParameterlessHelloWorldService.to_wsdl
18
+ puts wsdl
19
+ wsdl_doc = nil
20
+ expect { wsdl_doc = Nokogiri::XML(wsdl) { |c| c.strict } }.not_to raise_error
21
+
22
+ # there should be a definition with the class' name
23
+ wsdl_def = wsdl_doc.xpath("/wsdl:definitions[@name='ParameterlessHelloWorldService']", xmlns)
24
+ wsdl_def.should have(1).node
25
+ wsdl_def.xpath("wsdl:service[@name='ParameterlessHelloWorldService']/wsdl:port[@name='ParameterlessHelloWorldServicePort']/soap:address", xmlns).should have(1).node
26
+
27
+ # the message element for the input should not be there, as the method does not accept parameters
28
+ wsdl_def.xpath("wsdl:message[@name='HelloWorldInput']", xmlns).should have(0).node
29
+
30
+ # the message element for the output must be there, as a simple string
31
+ wsdl_def.xpath("wsdl:message[@name='HelloWorldOutput']/wsdl:part[@name='body']", xmlns).should have(1).node
32
+
33
+ # there must be an operation named 'HelloWorld'
34
+ wsdl_def.xpath("wsdl:portType/wsdl:operation[@name='HelloWorld']", xmlns).should have(1).node
35
+ wsdl_def.xpath("wsdl:binding/wsdl:operation[@name='HelloWorld']", xmlns).should have(1).node
36
+ end
37
+ it "should describe services with basic parameters and return values"
38
+ it "should describe services with array parameters"
39
+ end
40
+
41
+ describe "complex types DSL" do
42
+ it "should allow definition of complex types using class introspection"
43
+ it "should allow definition of complex types using a builder-like DSL"
44
+ it "should accept complex types as input"
45
+ it "should accept complex types as output"
46
+ end
47
+
48
+ describe "WSDL customization" do
49
+ it "should allow customization of namespace"
50
+ end
51
+
52
+ describe "existing WSDL" do
53
+ it "should accept an existing WSDL"
54
+ end
55
+ end
@@ -0,0 +1,5 @@
1
+ require "bundler"
2
+ Bundler.require :default, :development
3
+
4
+ RSpec.configure do |config|
5
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shapewear
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - "F\xC3\xA1bio Batista"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-01-02 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: builder
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 2
31
+ - 1
32
+ - 2
33
+ version: 2.1.2
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: nokogiri
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 1
47
+ - 5
48
+ - 0
49
+ version: 1.5.0
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rake
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 63
61
+ segments:
62
+ - 0
63
+ - 9
64
+ - 2
65
+ version: 0.9.2
66
+ type: :development
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: rspec
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ hash: 19
77
+ segments:
78
+ - 2
79
+ - 7
80
+ - 0
81
+ version: 2.7.0
82
+ type: :development
83
+ version_requirements: *id004
84
+ description: Shapewear is a Ruby library for handling SOAP requests from within your Rails or Sinatra application. It makes your fat services look skinny.
85
+ email: fabio@elementarsistemas.com.br
86
+ executables: []
87
+
88
+ extensions: []
89
+
90
+ extra_rdoc_files: []
91
+
92
+ files:
93
+ - .gitignore
94
+ - .rspec
95
+ - .rvmrc
96
+ - .travis.yml
97
+ - Gemfile
98
+ - Gemfile.lock
99
+ - LICENSE
100
+ - README.md
101
+ - Rakefile
102
+ - lib/shapewear.rb
103
+ - lib/shapewear/dsl.rb
104
+ - lib/shapewear/version.rb
105
+ - shapewear.gemspec
106
+ - spec/shapewear/dsl_spec.rb
107
+ - spec/spec_helper.rb
108
+ homepage: https://github.com/elementar/shapewear
109
+ licenses: []
110
+
111
+ post_install_message:
112
+ rdoc_options: []
113
+
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ requirements: []
135
+
136
+ rubyforge_project: shapewear
137
+ rubygems_version: 1.8.11
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Make your fat service look skinny
141
+ test_files: []
142
+