sinatra-soap 0.1.4 → 0.1.5

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODgxNTkzMGM0NzM2NWQwM2U1NDdkYzlkYWU5YWUyMjA5Y2EyNWFjYQ==
4
+ ZTQ4NzFhOWQyMzE0NDkzYjJmZDAzZjZmYzUyNGVlZTEyYzA5MzQ2Ng==
5
5
  data.tar.gz: !binary |-
6
- NTcyMjRlYjNkZGNjYWVmYjY1NzExYjEwNGI0ZGI1Y2FhODIwOGIzYQ==
6
+ ZDY2YjA5M2IwOWJmOWE0NjE0MDFhYTdhZWE4ZTFjNWJhNjgzODliYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODVmODE5OTQxODUyMmQ2MDJiMjlkNjFmZjZmMWFiZWViNWFlYTlmODg0NTc1
10
- YzRmNmNlZGVlYmI0NDU4NGQ2YWVjNDkxMjkzNjdmMDk2Nzc0ZjNjOWRmOGYw
11
- MWMyNzk5MjFmN2RjZDdkZmQyMjFjNWExZmNjYjE2NjQ0ZjlkMDk=
9
+ MjE1NGM1ODRmODU3ZmZjYjNkODhmNjM0NjE2Nzg4ZDZjZDQ5ODg0NDBjMzdm
10
+ MzI5MGM0ZGMxZDJjNzI5ZjNiMjdhZWY2ZDgwMDM4MmVhNTY3MTM4ZWVkY2I2
11
+ YzU4OWNiMzRiOTg2MTU3NWY1NzMxNjc3YzQ2YjEwOTU5OWUzNDc=
12
12
  data.tar.gz: !binary |-
13
- MjUwZGYwMjBmMjI5NDZjZjlkOTViNmYzODU2ZDY3NTkzNjE5MjE0OWZlYzU5
14
- ZmE4MzY4NTRhYzNlMjcwNGExNGJlYjc2ZDA4NWMzYmU2OGI5YmUwZDQyYjI5
15
- OTI2ZGJkNTA5ZGVjYTBlYzZhYWJiMWExODUxZDdkNzk2M2NkY2U=
13
+ ODA0YThhZTAxMzZlMDVlNGFmOWU0YWQ3MDEwYTVmMGE2YzkyMDcyY2FmMWJi
14
+ ZDc0NTJkYzI0MGE3NmZiNzI1NmJhYWNkNmE3MTM1YjQwMjJlMDM4ZmYzNTg3
15
+ MmI0ZjU0M2VhMzNjY2YzYmE2YTdkNTI5ZWEyYjBhNzNiNDExYjY=
data/README.md CHANGED
@@ -7,12 +7,7 @@ Sinatra-soap gem makes task to create SOAP API really simple. Inspired by WashOu
7
7
 
8
8
  ## Overview
9
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
-
10
+ In case of simplicity and quick first working release:
16
11
 
17
12
  ## Usage
18
13
 
@@ -22,7 +17,7 @@ A classic application would work like that:
22
17
  require 'sinatra'
23
18
  require 'sinatra/soap'
24
19
 
25
- soap "SomeAction" do |params|
20
+ soap "SomeAction"
26
21
  do_something_with_params # hash to be returned
27
22
  end
28
23
  ```
@@ -38,7 +33,7 @@ class SoapAPI < Sinatra::Base
38
33
  #remember to register extenstion if you are using modular style
39
34
  register Sinatra::Soap
40
35
 
41
- soap "SomeAction" do |params|
36
+ soap "SomeAction"
42
37
  params # hash to be returned
43
38
  end
44
39
  end
@@ -1,16 +1,10 @@
1
1
  require 'sinatra/base'
2
2
  require 'sinatra/soap'
3
3
 
4
- # require './lib/sinatra/soap/wsdl'
5
- # require './lib/sinatra/soap/helpers'
6
4
  class App < Sinatra::Base
7
5
  register Sinatra::Soap
8
- soap :test do |params|
9
- puts params.inspect
10
- end
11
-
12
- get '/' do
13
- puts params.inspect
6
+ soap :test do
7
+ params
14
8
  end
15
9
  end
16
- puts App.run!
10
+ App.run!
@@ -1,66 +1,35 @@
1
1
  require "sinatra/base"
2
2
  require "sinatra/soap/version"
3
- require "sinatra/soap/helpers"
4
3
  require "sinatra/soap/wsdl"
5
4
  require "sinatra/soap/error"
6
- # require "sinatra/soap/builder"
5
+ require "sinatra/soap/dsl_methods"
6
+ require "sinatra/soap/request_context_methods"
7
+ require "sinatra/soap/request"
8
+ require "sinatra/soap/response"
7
9
  require "builder"
8
10
 
9
11
 
10
12
  module Sinatra
11
13
  module Soap
12
14
 
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
15
+ include DslMethods
22
16
 
23
17
  def self.registered(app)
24
- app.helpers Sinatra::Soap::Helpers
18
+ app.helpers Soap::RequestContextMethods
19
+
25
20
  app.set :soap_path, '/action' unless defined?(app.settings.soap_path)
26
21
  app.set :wsdl_path, '/wsdl' unless defined?(app.settings.wsdl_path)
27
22
 
28
23
  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
24
+ content_type 'text/xml'
25
+ call_action_block
58
26
  end
59
27
 
60
28
  app.get(app.settings.wsdl_path) do
61
- wsdl.generate
29
+ get_wsdl
62
30
  end
63
31
  end
32
+
64
33
  end
65
34
  Delegator.delegate :soap
66
35
  register Soap
@@ -0,0 +1,11 @@
1
+ module Sinatra
2
+ module Soap
3
+ module DslMethods
4
+
5
+ def soap(action, *args, &block)
6
+ Soap::Wsdl.register(action, *args, &block)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Soap
3
- class SoapFault < StandardError; end
3
+ class Error < StandardError; end
4
4
  end
5
5
  end
@@ -0,0 +1,63 @@
1
+ require "nori"
2
+
3
+ module Sinatra
4
+ module Soap
5
+ class Request
6
+
7
+ attr_reader :wsdl, :action, :env, :request, :params
8
+
9
+ def initialize(env, request, params)
10
+ @env = env
11
+ @request = request
12
+ @params = params
13
+ parse_request
14
+ end
15
+
16
+
17
+ def execute
18
+ request_block = wsdl.block
19
+ response_hash = self.instance_eval(&request_block)
20
+ Soap::Response.new(wsdl, response_hash)
21
+ end
22
+
23
+ alias_method :orig_params, :params
24
+
25
+ def action
26
+ return orig_params[:action] unless orig_params[:action].nil?
27
+ orig_params[:action] = env['HTTP_SOAPACTION'].to_s.gsub(/^"(.*)"$/, '\1').to_sym
28
+ end
29
+
30
+
31
+ def params
32
+ return orig_params[:soap] unless orig_params[:soap].nil?
33
+ rack_input = env["rack.input"].read
34
+ env["rack.input"].rewind
35
+ orig_params[:soap] = nori.parse(rack_input)[:Envelope][:Body][action]
36
+ end
37
+
38
+
39
+ def wsdl
40
+ @wsdl = Soap::Wsdl.new(action)
41
+ end
42
+
43
+ private
44
+
45
+ def parse_request
46
+ action
47
+ params
48
+ end
49
+
50
+ def nori(snakecase=false)
51
+ Nori.new(
52
+ :strip_namespaces => true,
53
+ :advanced_typecasting => true,
54
+ :convert_tags_to => (
55
+ snakecase ? lambda { |tag| tag.snakecase.to_sym }
56
+ : lambda { |tag| tag.to_sym }
57
+ )
58
+ )
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,19 @@
1
+ module Sinatra
2
+ module Soap
3
+ module RequestContextMethods
4
+
5
+ def call_action_block
6
+ request = Soap::Request.new(env, request, params)
7
+ response = request.execute
8
+ builder :response, locals: {wsdl: response.wsdl, params: response.params}
9
+ rescue Soap::Error => e
10
+ builder :error, locals: {e: e}
11
+ end
12
+
13
+ def get_wsdl
14
+ Soap::Wsdl.generate
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Sinatra
2
+ module Soap
3
+ class Response
4
+
5
+ attr_reader :wsdl, :params
6
+
7
+ def initialize(wsdl, params)
8
+ @wsdl = wsdl
9
+ @params = params
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Soap
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  end
@@ -1,34 +1,41 @@
1
- require 'singleton'
2
-
3
1
  module Sinatra
4
2
  module Soap
5
3
  class Wsdl
6
- include Singleton
7
4
 
8
- attr_accessor :actions, :namespace
5
+ # class << self
6
+ # attr_accessor :actions
7
+ # end
8
+ @@actions = {}
9
9
 
10
- def initialize
11
- @actions = {}
10
+ def self.register(name, *args, &block)
11
+ @@actions = {} if @@actions.nil?
12
+ @@actions[name] = {}
13
+ args = args.pop
14
+ unless args.nil?
15
+ args.each do |key, value|
16
+ @@actions[name][key] = value
17
+ end
18
+ end
19
+ @@actions[name][:block] = block if block_given?
12
20
  end
13
21
 
14
- def generate
15
- # raise "Not implemented"
22
+ def self.generate
16
23
  end
17
24
 
18
- def [](key)
19
- actions[key]
25
+ attr_accessor :action, :block, :arguments
26
+
27
+ def initialize(action)
28
+ data = all[action]
29
+ raise Soap::Error, "Undefined Soap Action" if data.nil?
30
+ @action = action
31
+ @block = data[:block]
32
+ @arguments = data.select {|k,v| k != :block}
20
33
  end
21
34
 
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?
35
+ def all
36
+ @@actions
31
37
  end
38
+
32
39
  end
33
40
  end
34
41
  end
@@ -0,0 +1,10 @@
1
+ xml.instruct!
2
+ xml.tag! 'soap:Envelope', 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
3
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' do
4
+ xml.tag! 'soap:Body' do
5
+ xml.tag! 'soap:Fault', :encodingStyle => 'http://schemas.xmlsoap.org/soap/encoding/' do
6
+ xml.faultcode 'Client'
7
+ xml.faultstring e.message
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ xml.instruct!
2
+ xml.tag! 'soap:Envelope', 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
3
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' do
4
+ xml.tag! 'soap:Body' do
5
+ xml.tag! "soap:#{wsdl.action}Response" do
6
+ params.each do |key, value|
7
+ xml.tag! key, value
8
+ end
9
+ end
10
+ end
11
+ end
@@ -22,9 +22,11 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rspec"
23
23
  spec.add_development_dependency "rake"
24
24
  spec.add_development_dependency "rack-test"
25
+ spec.add_development_dependency "builder"
26
+ spec.add_development_dependency "debugger"
27
+
25
28
 
26
29
  spec.add_dependency "sinatra"
27
30
  spec.add_dependency "nori", ">= 2.0.0"
28
31
  spec.add_dependency "nokogiri"
29
- spec.add_dependency "builder"
30
32
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Request" do
4
+ it "should get soap_action" do
5
+ pending
6
+ end
7
+
8
+ it "should get soap arguments" do
9
+ pending
10
+ end
11
+
12
+ it "should build response" do
13
+ pending
14
+ end
15
+
16
+ it "should validate input with WSDL" do
17
+ pending
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Response" do
4
+
5
+ it "should build response" do
6
+ pending
7
+ end
8
+
9
+ it "should build soap faults" do
10
+ pending
11
+ end
12
+ end
@@ -1,20 +1,4 @@
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 }
1
+ require 'spec_helper'
18
2
 
19
3
 
20
4
  describe 'A default soap sinatra application' do
@@ -0,0 +1,17 @@
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
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 }
@@ -0,0 +1,10 @@
1
+ xml.instruct!
2
+ xml.tag! 'soap:Envelope', 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
3
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' do
4
+ xml.tag! 'soap:Body' do
5
+ xml.tag! 'soap:Fault', :encodingStyle => 'http://schemas.xmlsoap.org/soap/encoding/' do
6
+ xml.faultcode 'Client'
7
+ xml.faultstring e.message
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ xml.instruct!
2
+ xml.tag! 'soap:Envelope', 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
3
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' do
4
+ xml.tag! 'soap:Body' do
5
+ xml.tag! "soap:#{wsdl.action}Response" do
6
+ params.each do |key, value|
7
+ xml.tag! key, value
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe "WSDL" do
5
+ it "should hold registered actions with arguments and blocks" do
6
+ pending
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-soap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Shamatov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-28 00:00:00.000000000 Z
11
+ date: 2013-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,13 +67,13 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: sinatra
70
+ name: builder
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ! '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
- type: :runtime
76
+ type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
@@ -81,21 +81,21 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: nori
84
+ name: debugger
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
- version: 2.0.0
90
- type: :runtime
89
+ version: '0'
90
+ type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ! '>='
95
95
  - !ruby/object:Gem::Version
96
- version: 2.0.0
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: nokogiri
98
+ name: sinatra
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ! '>='
@@ -109,7 +109,21 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: builder
112
+ name: nori
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 2.0.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: 2.0.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: nokogiri
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - ! '>='
@@ -140,12 +154,23 @@ files:
140
154
  - Rakefile
141
155
  - examples/app.rb
142
156
  - lib/sinatra/soap.rb
157
+ - lib/sinatra/soap/dsl_methods.rb
143
158
  - lib/sinatra/soap/error.rb
144
- - lib/sinatra/soap/helpers.rb
159
+ - lib/sinatra/soap/request.rb
160
+ - lib/sinatra/soap/request_context_methods.rb
161
+ - lib/sinatra/soap/response.rb
145
162
  - lib/sinatra/soap/version.rb
146
163
  - lib/sinatra/soap/wsdl.rb
164
+ - lib/sinatra/views/error.builder
165
+ - lib/sinatra/views/response.builder
147
166
  - sinatra-soap.gemspec
167
+ - spec/request_spec.rb
168
+ - spec/response_spec.rb
148
169
  - spec/soap_spec.rb
170
+ - spec/spec_helper.rb
171
+ - spec/views/error.builder
172
+ - spec/views/response.builder
173
+ - spec/wsdl_spec.rb
149
174
  homepage: https://github.com/IvanShamatov/sinatra-soap
150
175
  licenses:
151
176
  - MIT
@@ -171,4 +196,10 @@ signing_key:
171
196
  specification_version: 4
172
197
  summary: Handling SOAP requests for sinatra inspired by washout
173
198
  test_files:
199
+ - spec/request_spec.rb
200
+ - spec/response_spec.rb
174
201
  - spec/soap_spec.rb
202
+ - spec/spec_helper.rb
203
+ - spec/views/error.builder
204
+ - spec/views/response.builder
205
+ - spec/wsdl_spec.rb
@@ -1,46 +0,0 @@
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