-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathrequest.rb
More file actions
83 lines (65 loc) · 1.96 KB
/
Copy pathrequest.rb
File metadata and controls
83 lines (65 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require "nori"
module Sinatra
module Soap
class Request
attr_reader :wsdl, :action, :env, :request, :params, :response
alias_method :body, :params
def initialize(env, request, params)
@env = env
@request = request
@params = params
@header = {}
parse_request
end
def execute
request_block = wsdl.block
@response = Soap::Response.new(wsdl, nil)
response_hash = self.instance_eval(&request_block)
if @response.params == nil
if response_hash.is_a?(Array)
@response.params, @response.headers = response_hash
else
@response.params = response_hash
end
end
@response
end
alias_method :orig_params, :params
def action
return orig_params[:action] unless orig_params[:action].nil?
orig_params[:action] = env['HTTP_SOAPACTION'].to_s.gsub(/^"(.*)"$/, '\1').to_sym
end
def params
return orig_params[:soap] unless orig_params[:soap].nil?
rack_input = env["rack.input"].read
env["rack.input"].rewind
orig_params[:soap] = nori.parse(rack_input)[:Envelope][:Body][action]
end
def header
return orig_params[:soap_header] unless orig_params[:soap_header].nil?
rack_input = env["rack.input"].read
env["rack.input"].rewind
orig_params[:soap_header] = nori.parse(rack_input)[:Envelope][:Header]
end
alias_method :soap_header, :header
def wsdl
@wsdl = Soap::Wsdl.new(action)
end
private
def parse_request
action
params
end
def nori(snakecase=false)
Nori.new(
:strip_namespaces => true,
:advanced_typecasting => true,
:convert_tags_to => (
snakecase ? lambda { |tag| tag.snakecase.to_sym }
: lambda { |tag| tag.to_sym }
)
)
end
end
end
end