sinatra-soap 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODgxNTkzMGM0NzM2NWQwM2U1NDdkYzlkYWU5YWUyMjA5Y2EyNWFjYQ==
5
+ data.tar.gz: !binary |-
6
+ NTcyMjRlYjNkZGNjYWVmYjY1NzExYjEwNGI0ZGI1Y2FhODIwOGIzYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ODVmODE5OTQxODUyMmQ2MDJiMjlkNjFmZjZmMWFiZWViNWFlYTlmODg0NTc1
10
+ YzRmNmNlZGVlYmI0NDU4NGQ2YWVjNDkxMjkzNjdmMDk2Nzc0ZjNjOWRmOGYw
11
+ MWMyNzk5MjFmN2RjZDdkZmQyMjFjNWExZmNjYjE2NjQ0ZjlkMDk=
12
+ data.tar.gz: !binary |-
13
+ MjUwZGYwMjBmMjI5NDZjZjlkOTViNmYzODU2ZDY3NTkzNjE5MjE0OWZlYzU5
14
+ ZmE4MzY4NTRhYzNlMjcwNGExNGJlYjc2ZDA4NWMzYmU2OGI5YmUwZDQyYjI5
15
+ OTI2ZGJkNTA5ZGVjYTBlYzZhYWJiMWExODUxZDdkNzk2M2NkY2U=
@@ -0,0 +1,7 @@
1
+ .rbx/
2
+ .bundle/
3
+ *.gem
4
+ .idea/
5
+ .rvmrc
6
+ *.swp*.gem
7
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,5 @@
1
+ before_install:
2
+ - gem install bundler
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sinatra-soap.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ivan Shamatov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # Sinatra::Soap — Under construction
2
+
3
+ [![Build Status](https://travis-ci.org/IvanShamatov/sinatra-soap.png?branch=master)](https://travis-ci.org/IvanShamatov/sinatra-soap) [![Code Climate](https://codeclimate.com/github/IvanShamatov/sinatra-soap.png)](https://codeclimate.com/github/IvanShamatov/sinatra-soap) [![Gem Version](https://badge.fury.io/rb/sinatra-soap.png)](http://badge.fury.io/rb/sinatra-soap)
4
+
5
+ Sinatra-soap gem makes task to create SOAP API really simple. Inspired by WashOut gem for Rails. But remember, the only reason why you should use SOAP is legacy code.
6
+
7
+
8
+ ## Overview
9
+
10
+ In case of simplicity and quick first working release:
11
+
12
+ - WSDL would not be generated
13
+ - WSDL would not be checked
14
+ - Response would be ```"#{soap_action}Response"``` and types would guessed.
15
+
16
+
17
+ ## Usage
18
+
19
+ A classic application would work like that:
20
+
21
+ ```ruby
22
+ require 'sinatra'
23
+ require 'sinatra/soap'
24
+
25
+ soap "SomeAction" do |params|
26
+ do_something_with_params # hash to be returned
27
+ end
28
+ ```
29
+
30
+ A modular application would look like that:
31
+
32
+ ```ruby
33
+ require 'sinatra/base'
34
+ require 'sinatra/soap'
35
+
36
+ class SoapAPI < Sinatra::Base
37
+
38
+ #remember to register extenstion if you are using modular style
39
+ register Sinatra::Soap
40
+
41
+ soap "SomeAction" do |params|
42
+ params # hash to be returned
43
+ end
44
+ end
45
+ ```
46
+
47
+
48
+
49
+
50
+
51
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,16 @@
1
+ require 'sinatra/base'
2
+ require 'sinatra/soap'
3
+
4
+ # require './lib/sinatra/soap/wsdl'
5
+ # require './lib/sinatra/soap/helpers'
6
+ class App < Sinatra::Base
7
+ register Sinatra::Soap
8
+ soap :test do |params|
9
+ puts params.inspect
10
+ end
11
+
12
+ get '/' do
13
+ puts params.inspect
14
+ end
15
+ end
16
+ puts App.run!
@@ -0,0 +1,67 @@
1
+ require "sinatra/base"
2
+ require "sinatra/soap/version"
3
+ require "sinatra/soap/helpers"
4
+ require "sinatra/soap/wsdl"
5
+ require "sinatra/soap/error"
6
+ # require "sinatra/soap/builder"
7
+ require "builder"
8
+
9
+
10
+ module Sinatra
11
+ module Soap
12
+
13
+ # soap :LogEvent,
14
+ # args: {},
15
+ # return: {},
16
+ # namespace: "",
17
+ # to: method_name do
18
+ # end
19
+ def soap(name, *args, &block)
20
+ Soap::Wsdl.instance.register_action(name, *args, &block)
21
+ end
22
+
23
+ def self.registered(app)
24
+ app.helpers Sinatra::Soap::Helpers
25
+ app.set :soap_path, '/action' unless defined?(app.settings.soap_path)
26
+ app.set :wsdl_path, '/wsdl' unless defined?(app.settings.wsdl_path)
27
+
28
+ app.post(app.settings.soap_path) do
29
+ begin
30
+ response = call_action_block
31
+ builder do |xml|
32
+ xml.instruct!
33
+ xml.tag! 'soap:Envelope', 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
34
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' do
35
+ xml.tag! 'soap:Body' do
36
+ xml.tag! "soap:#{params[:action]}Response" do
37
+ response.each do |key, value|
38
+ xml.tag! key, value
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ rescue Soap::SoapFault => e
45
+ builder do |xml|
46
+ xml.instruct!
47
+ xml.tag! 'soap:Envelope', 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
48
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' do
49
+ xml.tag! 'soap:Body' do
50
+ xml.tag! 'soap:Fault', :encodingStyle => 'http://schemas.xmlsoap.org/soap/encoding/' do
51
+ xml.faultcode 'Client'
52
+ xml.faultstring e.message
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ app.get(app.settings.wsdl_path) do
61
+ wsdl.generate
62
+ end
63
+ end
64
+ end
65
+ Delegator.delegate :soap
66
+ register Soap
67
+ end
@@ -0,0 +1,5 @@
1
+ module Sinatra
2
+ module Soap
3
+ class SoapFault < StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ require "nori"
2
+
3
+ module Sinatra
4
+ module Soap
5
+ module Helpers
6
+
7
+ def call_action_block
8
+ parse_request
9
+ wsdl[params[:action]][:block].call(params[:soap][params[:action]])
10
+ end
11
+
12
+ def parse_request
13
+ action = soap_action
14
+ soap_params
15
+ raise Soap::SoapFault, "Undefined Soap Action" unless wsdl.actions.include?(action)
16
+ end
17
+
18
+ def soap_action
19
+ return params[:action] unless params[:action].nil?
20
+ params[:action] = env['HTTP_SOAPACTION'].to_s.gsub(/^"(.*)"$/, '\1').to_sym
21
+ end
22
+
23
+ def soap_params
24
+ return params[:soap] unless params[:soap].nil?
25
+ rack_input = env["rack.input"].read
26
+ env["rack.input"].rewind
27
+ params[:soap] = nori.parse(rack_input)[:Envelope][:Body]
28
+ end
29
+
30
+ def wsdl
31
+ Soap::Wsdl.instance
32
+ end
33
+
34
+ def nori(snakecase=false)
35
+ Nori.new(
36
+ :strip_namespaces => true,
37
+ :advanced_typecasting => true,
38
+ :convert_tags_to => (
39
+ snakecase ? lambda { |tag| tag.snakecase.to_sym }
40
+ : lambda { |tag| tag.to_sym }
41
+ )
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ module Sinatra
2
+ module Soap
3
+ VERSION = "0.1.4"
4
+ end
5
+ end
@@ -0,0 +1,34 @@
1
+ require 'singleton'
2
+
3
+ module Sinatra
4
+ module Soap
5
+ class Wsdl
6
+ include Singleton
7
+
8
+ attr_accessor :actions, :namespace
9
+
10
+ def initialize
11
+ @actions = {}
12
+ end
13
+
14
+ def generate
15
+ # raise "Not implemented"
16
+ end
17
+
18
+ def [](key)
19
+ actions[key]
20
+ end
21
+
22
+ def register_action(name, *args, &block)
23
+ actions[name] = {}
24
+ args = args.pop
25
+ unless args.nil?
26
+ args.each do |key, value|
27
+ actions[name][key] = value
28
+ end
29
+ end
30
+ actions[name][:block] = block if block_given?
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sinatra/soap/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sinatra-soap"
8
+ spec.version = Sinatra::Soap::VERSION
9
+ spec.authors = ["Ivan Shamatov"]
10
+ spec.email = ["status.enable@gmail.com"]
11
+ spec.description = %q{Sinatra-soap gem makes task to create SOAP API really simple. Inspired by WashOut gem for Rails. But remember, the only reason why you should use SOAP is legacy code.}
12
+ spec.summary = %q{Handling SOAP requests for sinatra inspired by washout}
13
+ spec.homepage = "https://github.com/IvanShamatov/sinatra-soap"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rack-test"
25
+
26
+ spec.add_dependency "sinatra"
27
+ spec.add_dependency "nori", ">= 2.0.0"
28
+ spec.add_dependency "nokogiri"
29
+ spec.add_dependency "builder"
30
+ end
@@ -0,0 +1,74 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+ require File.join(File.join(File.expand_path(File.dirname(__FILE__))), '..', 'lib', 'sinatra', 'soap')
3
+ require 'rspec'
4
+ require 'rack/test'
5
+
6
+ class SoapApp < Sinatra::Base
7
+ register Sinatra::Soap
8
+ soap :test do |params|
9
+ params
10
+ end
11
+ end
12
+
13
+ module RSpecMixin
14
+ include Rack::Test::Methods
15
+ end
16
+
17
+ RSpec.configure { |c| c.include RSpecMixin }
18
+
19
+
20
+ describe 'A default soap sinatra application' do
21
+ def app
22
+ SoapApp
23
+ end
24
+
25
+
26
+ it "should parse soap request and send response" do
27
+ headers = {"HTTP_SOAPACTION" => 'test'}
28
+ message = '<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="any" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><wsdl:test><par>one</par><par2>bar</par2><foo>wat</foo></wsdl:test></env:Body></env:Envelope>'
29
+ post '/action', message, headers
30
+ response =<<-XML
31
+ <?xml version="1.0" encoding="UTF-8"?>
32
+ <soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
33
+ <soap:Body>
34
+ <soap:testResponse>
35
+ <par>one</par>
36
+ <par2>bar</par2>
37
+ <foo>wat</foo>
38
+ </soap:testResponse>
39
+ </soap:Body>
40
+ </soap:Envelope>
41
+ XML
42
+ last_response.body.should == response
43
+ end
44
+
45
+
46
+ it "should raise soap fault on unknown action" do
47
+ headers = {"HTTP_SOAPACTION" => 'test2'}
48
+ message = '<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="any" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><wsdl:test><par>one</par><par2>bar</par2><foo>wat</foo></wsdl:test></env:Body></env:Envelope>'
49
+ post '/action', message, headers
50
+ response =<<-XML
51
+ <?xml version="1.0" encoding="UTF-8"?>
52
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
53
+ <soap:Body>
54
+ <soap:Fault encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
55
+ <faultcode>Client</faultcode>
56
+ <faultstring>Undefined Soap Action</faultstring>
57
+ </soap:Fault>
58
+ </soap:Body>
59
+ </soap:Envelope>
60
+ XML
61
+ last_response.body.should == response
62
+ end
63
+
64
+ it "should have endpoint for soap actions" do
65
+ endpoint = app.routes["POST"].select {|k| k[0].to_s.match('action')}.count
66
+ endpoint.should eq 1
67
+ end
68
+
69
+ it "should have route for wsdl" do
70
+ wsdl = app.routes["GET"].select {|k| k[0].to_s.match('wsdl')}.count
71
+ wsdl.should == 1
72
+ end
73
+
74
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-soap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Shamatov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: nori
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 2.0.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 2.0.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: nokogiri
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: builder
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Sinatra-soap gem makes task to create SOAP API really simple. Inspired
126
+ by WashOut gem for Rails. But remember, the only reason why you should use SOAP
127
+ is legacy code.
128
+ email:
129
+ - status.enable@gmail.com
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - .rspec
136
+ - .travis.yml
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - examples/app.rb
142
+ - lib/sinatra/soap.rb
143
+ - lib/sinatra/soap/error.rb
144
+ - lib/sinatra/soap/helpers.rb
145
+ - lib/sinatra/soap/version.rb
146
+ - lib/sinatra/soap/wsdl.rb
147
+ - sinatra-soap.gemspec
148
+ - spec/soap_spec.rb
149
+ homepage: https://github.com/IvanShamatov/sinatra-soap
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.1.10
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Handling SOAP requests for sinatra inspired by washout
173
+ test_files:
174
+ - spec/soap_spec.rb