canned_soap 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +59 -12
- data/lib/canned_soap/client.rb +7 -25
- data/lib/canned_soap/version.rb +1 -1
- data/lib/canned_soap.rb +0 -1
- metadata +1 -2
- data/lib/canned_soap/wcf_handler.rb +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd7e448086fd09cb538b48f828f002e0c0c415b5
|
4
|
+
data.tar.gz: 1ea6a961e2e01bfe607e451104a6d5817be2af50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2b1571c901a2bc276c89d7310180ca36823e5c789b98f5bd1f32acc72fd3c1917b36da9fd0e9780301bda87dfa9ce6ed8067f98fdade457bf14bce3b97272f7
|
7
|
+
data.tar.gz: '090cb3f336f8e87f18c5268a2a603f8fa74837766b3f173ae1a58d3591cfad03d682eaea0e92c841718af727dab4d62f944b66d4e38ced6bae13cc4b15ef2501'
|
data/README.md
CHANGED
@@ -1,11 +1,58 @@
|
|
1
|
-
#CannedSoap
|
1
|
+
# CannedSoap
|
2
2
|
|
3
3
|
A rewrite version of the [ruby2soap](https://github.com/ericman93/ruby2soap) gem.
|
4
4
|
|
5
|
-
##Motivation
|
5
|
+
## Motivation
|
6
6
|
The original gem has a lot of bugs and don't work on Linux environments. I started to maintain an old gem that uses this gem, so I started to maintain this gem too.
|
7
7
|
|
8
|
-
|
8
|
+
## Getting Started
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'canned_soap'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
```sh
|
19
|
+
bundle install
|
20
|
+
```
|
21
|
+
|
22
|
+
Or if you don't use bundler:
|
23
|
+
|
24
|
+
```sh
|
25
|
+
gem install canned_soap
|
26
|
+
```
|
27
|
+
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Initialize the client
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
client = CannedSoap::Client.new('http://www.webservicex.net/CurrencyConvertor.asmx')
|
35
|
+
```
|
36
|
+
|
37
|
+
### Simple objects
|
38
|
+
```ruby
|
39
|
+
client.ConversionRate(FromCurrency: 'ILS', ToCurrency: 'GBP')
|
40
|
+
```
|
41
|
+
|
42
|
+
### Statefull
|
43
|
+
```ruby
|
44
|
+
client.Init(userName: 'ericman93')
|
45
|
+
client.IncreaseScore() #the cookies saved automaticly
|
46
|
+
```
|
47
|
+
|
48
|
+
### Complex type
|
49
|
+
```ruby
|
50
|
+
client = WcfHandler.new('http://localhost:1659/Service1.svc')
|
51
|
+
res = client.GetDataUsingDataContract(composite: {BoolValue: true, StringValue: "canedo_soap"})
|
52
|
+
```
|
53
|
+
|
54
|
+
|
55
|
+
# Base Ruby2Soap Doc
|
9
56
|
I started this project when I needed to call a WCF method which required cookies on init. Unfortunalty, I could not find any gem that will help me so, so I implemented it myself.
|
10
57
|
|
11
58
|
While working I noticed that I need more features - authentication, for example.
|
@@ -16,47 +63,47 @@ Thank you,
|
|
16
63
|
Eric
|
17
64
|
|
18
65
|
|
19
|
-
##Examples
|
66
|
+
## Examples
|
20
67
|
|
21
|
-
###Initialize the handler
|
68
|
+
### Initialize the handler
|
22
69
|
|
23
70
|
```ruby
|
24
71
|
handler = WcfHandler.new('http://www.webservicex.net/CurrencyConvertor.asmx')
|
25
72
|
```
|
26
73
|
|
27
|
-
###Simple objects
|
74
|
+
### Simple objects
|
28
75
|
```ruby
|
29
76
|
handler.ConversionRate(:FromCurrency => 'ILS', :ToCurrency => 'GBP')
|
30
77
|
```
|
31
78
|
|
32
|
-
###Statefull
|
79
|
+
### Statefull
|
33
80
|
```ruby
|
34
81
|
handler.Init(:userName => 'ericman93')
|
35
82
|
handler.IncreaseScore() #the cookies saved automaticly
|
36
83
|
```
|
37
84
|
|
38
|
-
###Complex type
|
85
|
+
### Complex type
|
39
86
|
```ruby
|
40
87
|
handler = WcfHandler.new('http://localhost:1659/Service1.svc')
|
41
88
|
res = handler.GetDataUsingDataContract(:composite => {:BoolValue => true,:StringValue => "ruby2soap"})
|
42
89
|
```
|
43
90
|
|
44
|
-
##Result
|
91
|
+
## Result
|
45
92
|
The object that the soap service function returns is actually a HTTP response with 'result' function that returns the actual value.
|
46
93
|
If the value is a complex object, then it would be represented as a hash
|
47
94
|
|
48
95
|
|
49
|
-
##Authentication
|
96
|
+
## Authentication
|
50
97
|
Available authentications
|
51
98
|
1. NTLM
|
52
99
|
2. Basic
|
53
100
|
3. Digest
|
54
101
|
|
55
|
-
###NTLM Auth
|
102
|
+
### NTLM Auth
|
56
103
|
```ruby
|
57
104
|
handler.ConversionRate({:FromCurrency => 'ILS', :ToCurrency => 'GBP'},SecutryProtocol::NTLM,'user','password')
|
58
105
|
```
|
59
|
-
###With domain
|
106
|
+
### With domain
|
60
107
|
```ruby
|
61
108
|
handler.ConversionRate({:FromCurrency => 'ILS', :ToCurrency => 'GBP'},SecutryProtocol::NTLM,'user','password','domain')
|
62
109
|
```
|
data/lib/canned_soap/client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
include CannedSoap::Wsdl
|
1
2
|
# Handle the requests to the service
|
2
3
|
module CannedSoap
|
3
4
|
class Client
|
@@ -19,8 +20,6 @@ module CannedSoap
|
|
19
20
|
wsdl.actions.each do |action|
|
20
21
|
define_wcf_action(action)
|
21
22
|
end
|
22
|
-
|
23
|
-
# maybe create class for each service and the function will be there
|
24
23
|
end
|
25
24
|
|
26
25
|
# Return the the current cookie set
|
@@ -43,15 +42,8 @@ module CannedSoap
|
|
43
42
|
res.singleton_class.send(:define_method,:result) do
|
44
43
|
result
|
45
44
|
end
|
46
|
-
|
47
|
-
#if(res.code == '401') # not autorized
|
48
|
-
# (raise "Please use ntlm") if res['WWW-Authenticate'].include?('NTLM')
|
49
|
-
#end
|
50
|
-
|
51
45
|
res
|
52
46
|
end
|
53
|
-
|
54
|
-
#create new method that takes the data and user and password and user ntlm
|
55
47
|
end
|
56
48
|
|
57
49
|
# Call to wcf method
|
@@ -60,24 +52,14 @@ module CannedSoap
|
|
60
52
|
# +body+:: the body of the HTTP request
|
61
53
|
# +args+:: metadata that indicate wich autountication to use
|
62
54
|
def send_wcf_action(soap_action,body,*args)
|
63
|
-
#req = Net::HTTP::Post.new(@uri.path)
|
64
|
-
#req = Net::HTTP::Post.new(@service_address)
|
65
|
-
|
66
|
-
#req["SOAPAction"] = soap_action
|
67
|
-
#req["Content-Type"] = "text/xml; charset=utf-8"
|
68
|
-
#req["Cookie"] = @cookies.join(',') unless @cookies.empty?
|
69
|
-
#req.body = body
|
70
|
-
|
71
55
|
yield(req) if block_given?
|
72
|
-
|
73
|
-
#get_web_response(req,@uri,*args)
|
74
|
-
# "Cookie" => (@cookies.join(',') unless @cookies.empty?)
|
75
56
|
cookies = @cookies.empty? ? "" : @cookies.join(',')
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
57
|
+
header = {
|
58
|
+
"SOAPAction" => soap_action,
|
59
|
+
"Content-Type" => "text/xml; charset=utf-8",
|
60
|
+
"Cookie" => cookies
|
61
|
+
}
|
62
|
+
send_message_to_wcf(@service_address, header, body, *args)
|
81
63
|
end
|
82
64
|
end
|
83
65
|
end
|
data/lib/canned_soap/version.rb
CHANGED
data/lib/canned_soap.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canned_soap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gustavo Canedo
|
@@ -105,7 +105,6 @@ files:
|
|
105
105
|
- lib/canned_soap/soap/soap_action.rb
|
106
106
|
- lib/canned_soap/soap/soap_parameter.rb
|
107
107
|
- lib/canned_soap/version.rb
|
108
|
-
- lib/canned_soap/wcf_handler.rb
|
109
108
|
- lib/canned_soap/web/security_protocol.rb
|
110
109
|
- lib/canned_soap/web/web_request_handler.rb
|
111
110
|
- lib/canned_soap/wsdl/wsdl.rb
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'xmlsimple'
|
3
|
-
require 'canned_soap/wsdl/wsdl'
|
4
|
-
include Wsdl
|
5
|
-
#require 'soap/soap'
|
6
|
-
#include Soap
|
7
|
-
#include WebRequestHandler
|
8
|
-
#require_relative 'wsdl.rb'
|
9
|
-
#require_relative 'wsdl_parser.rb'
|
10
|
-
#require_relative 'soap.rb'
|
11
|
-
#include WsdlParser
|
12
|
-
#include Soap
|
13
|
-
|
14
|
-
#Dir["lib/*.rb"].each {|file|
|
15
|
-
# require file
|
16
|
-
# #require_relative file# if file != 'wcf_handler'
|
17
|
-
# #include file.gsub('.rb','')
|
18
|
-
#}
|
19
|
-
|
20
|
-
# Handle the requests to the service
|
21
|
-
module CannedSoap
|
22
|
-
class WcfHandler
|
23
|
-
# C'tor.
|
24
|
-
# Parse the wsdl and create a method to each WCF/WebService method
|
25
|
-
# Params:
|
26
|
-
# +service_url+:: the url of your service
|
27
|
-
# +save_cookeis+:: should save cookies of the result
|
28
|
-
def initialize(service_url,save_cookeis = true)
|
29
|
-
HTTPI.log = false
|
30
|
-
@cookies = []
|
31
|
-
@save_cookeis = save_cookeis
|
32
|
-
|
33
|
-
@uri = URI("#{service_url}")
|
34
|
-
|
35
|
-
wsdl = Wsdl::WsdlParser.parse(service_url)
|
36
|
-
@service_address = wsdl.location_address
|
37
|
-
|
38
|
-
wsdl.actions.each do |action|
|
39
|
-
define_wcf_action(action)
|
40
|
-
end
|
41
|
-
|
42
|
-
# maybe create class for each service and the function will be there
|
43
|
-
end
|
44
|
-
|
45
|
-
# Return the the current cookie set
|
46
|
-
def cookies
|
47
|
-
@cookies
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
# Define a method to the +WcfHandler+ object base on the method from the WSDL
|
52
|
-
# Params:
|
53
|
-
# +action+:: +SoapAction+ that have all the info about the method from the WSDL
|
54
|
-
def define_wcf_action(action)
|
55
|
-
self.class.send(:define_method ,action.name) do |data=nil,*args|
|
56
|
-
body = build_body(action, data)
|
57
|
-
|
58
|
-
res = send_wcf_action(action.soap_action,body,*args)
|
59
|
-
(@cookies << res.headers["Set-Cookie"]) if @save_cookeis
|
60
|
-
|
61
|
-
result = get_wcf_response(res,action.name)
|
62
|
-
res.singleton_class.send(:define_method,:result) do
|
63
|
-
result
|
64
|
-
end
|
65
|
-
|
66
|
-
#if(res.code == '401') # not autorized
|
67
|
-
# (raise "Please use ntlm") if res['WWW-Authenticate'].include?('NTLM')
|
68
|
-
#end
|
69
|
-
|
70
|
-
res
|
71
|
-
end
|
72
|
-
|
73
|
-
#create new method that takes the data and user and password and user ntlm
|
74
|
-
end
|
75
|
-
|
76
|
-
# Call to wcf method
|
77
|
-
# Params:
|
78
|
-
# +soap_action+:: the value of the SOAPAction header
|
79
|
-
# +body+:: the body of the HTTP request
|
80
|
-
# +args+:: metadata that indicate wich autountication to use
|
81
|
-
def send_wcf_action(soap_action,body,*args)
|
82
|
-
#req = Net::HTTP::Post.new(@uri.path)
|
83
|
-
#req = Net::HTTP::Post.new(@service_address)
|
84
|
-
|
85
|
-
#req["SOAPAction"] = soap_action
|
86
|
-
#req["Content-Type"] = "text/xml; charset=utf-8"
|
87
|
-
#req["Cookie"] = @cookies.join(',') unless @cookies.empty?
|
88
|
-
#req.body = body
|
89
|
-
|
90
|
-
yield(req) if block_given?
|
91
|
-
|
92
|
-
#get_web_response(req,@uri,*args)
|
93
|
-
# "Cookie" => (@cookies.join(',') unless @cookies.empty?)
|
94
|
-
cookies = @cookies.empty? ? "" : @cookies.join(',')
|
95
|
-
send_message_to_wcf(@service_address,
|
96
|
-
{"SOAPAction" => soap_action,
|
97
|
-
"Content-Type" => "text/xml; charset=utf-8",
|
98
|
-
"Cookie" => cookies},
|
99
|
-
body, *args)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|