savon-multipart 1.2.0 → 2.0.0
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 +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +6 -5
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -2
- data/README.md +15 -2
- data/lib/savon-multipart.rb +3 -5
- data/lib/savon/multipart/response.rb +50 -0
- data/lib/savon/multipart/version.rb +1 -1
- data/savon-multipart.gemspec +4 -4
- data/spec/fixtures/response/not_multipart.txt +1 -0
- data/spec/fixtures/response/simple_multipart.txt +25 -0
- data/spec/savon/soap/response_spec.rb +44 -5
- metadata +31 -45
- data/lib/savon/multipart/soap/part.rb +0 -14
- data/lib/savon/multipart/soap/request.rb +0 -29
- data/lib/savon/multipart/soap/response.rb +0 -68
- data/lib/savon/multipart/soap/xml.rb +0 -50
- data/spec/spec_helper.rb +0 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0082bc59877c68ea84cb396252ae675e75249747
|
4
|
+
data.tar.gz: 5ca53baa0cee4653660c3c9d15955ec27ad2be77
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8bc0eac605b09715e3acb66254d74c9b4a574d166551143bac3f272fcfa8c8a7483cde26720ab82575a913140d41c2eda0a4c907d3de324bd8fc93a539616f31
|
7
|
+
data.tar.gz: 916d06c7b645e4e243787ee7419464f4155633de7e59344227efb7fe94d5effaff27786654afc41c3b7a2f8e4f494e9b297ac58d00d68441e526a9d5a2654445
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,3 +2,8 @@
|
|
2
2
|
|
3
3
|
* Initial version. Adds multipart support (SOAP with Attachments) to Savon v0.9.7.
|
4
4
|
Please test and provide feedback so we can merge this into Savon proper.
|
5
|
+
|
6
|
+
## 2.0.0 (UNRELEASED)
|
7
|
+
* Rewrite of savon-multipart to work with Savon 2.0+
|
8
|
+
This includes all of the existing functionality in savon-multipart
|
9
|
+
for savon1, but in a way that will be easier to maintain.
|
data/Gemfile
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
gemspec
|
3
3
|
|
4
|
-
|
4
|
+
group :development do
|
5
|
+
gem 'pry'
|
6
|
+
gem 'pry-debugger'
|
7
|
+
end
|
8
|
+
|
9
|
+
platform :rbx do
|
10
|
+
gem 'json'
|
11
|
+
gem 'racc'
|
12
|
+
gem 'rubysl'
|
13
|
+
gem 'rubinius-coverage'
|
14
|
+
end
|
data/README.md
CHANGED
@@ -1,8 +1,21 @@
|
|
1
|
-
Savon Multipart [](http://travis-ci.org/savonrb/savon-multipart)
|
2
2
|
===============
|
3
3
|
|
4
4
|
Adds multipart support (SOAP with Attachments) to [Savon](https://github.com/savonrb/savon).
|
5
|
-
Please test and provide feedback so we can
|
5
|
+
Please test and provide feedback so we can support as many multipart-soap messages as possible.
|
6
|
+
|
7
|
+
|
8
|
+
Savon2
|
9
|
+
------
|
10
|
+
|
11
|
+
Recently Savon launched a rewrite that broke compatibility with savon-multipart. If you're using savon
|
12
|
+
version 1, this should just work, but if you'd like to use Savon2, you will probably want to specify
|
13
|
+
something like this in your Gemfile
|
14
|
+
|
15
|
+
|
16
|
+
```
|
17
|
+
gem 'savon-multipart', :git => 'https://github.com/tjarratt/savon-multipart.git', :branch => 'savon2'
|
18
|
+
```
|
6
19
|
|
7
20
|
|
8
21
|
Installation
|
data/lib/savon-multipart.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'mail'
|
2
|
+
|
3
|
+
module Savon
|
4
|
+
module Multipart
|
5
|
+
class Response < Savon::Response
|
6
|
+
attr_reader :parts
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
@parts = []
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def attachments
|
14
|
+
if multipart?
|
15
|
+
parse_body unless @has_parsed_body
|
16
|
+
@parts.attachments
|
17
|
+
else
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def xml
|
23
|
+
if multipart?
|
24
|
+
parse_body unless @has_parsed_body
|
25
|
+
@parts.first.body.to_s
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def multipart?
|
33
|
+
!(http.headers['content-type'] =~ /^multipart/).nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
def boundary
|
37
|
+
return unless multipart?
|
38
|
+
@boundary ||= Mail::Field.new('content-type', http.headers['content-type']).parameters['boundary']
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_body
|
42
|
+
@parts = Mail::Part.new(
|
43
|
+
:headers => http.headers,
|
44
|
+
:body => http.body
|
45
|
+
).body.split!(boundary).parts
|
46
|
+
@has_parsed_body = true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/savon-multipart.gemspec
CHANGED
@@ -14,11 +14,11 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.rubyforge_project = s.name
|
16
16
|
|
17
|
-
s.add_dependency "savon", "
|
18
|
-
s.add_dependency "mail"
|
17
|
+
s.add_dependency "savon", "~> 2.3.0"
|
18
|
+
s.add_dependency "mail", "2.5.3"
|
19
19
|
|
20
|
-
s.add_development_dependency "rake"
|
21
|
-
s.add_development_dependency "rspec"
|
20
|
+
s.add_development_dependency "rake"
|
21
|
+
s.add_development_dependency "rspec"
|
22
22
|
s.add_development_dependency "autotest"
|
23
23
|
|
24
24
|
s.files = `git ls-files`.split("\n")
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:wsdl="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><ns1:TransactionID soapenv:actor="" soapenv:mustUnderstand="1" xsi:type="xsd:string" xmlns:ns1="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2">2011012713535811111111111</ns1:TransactionID></soapenv:Header><soapenv:Body><SubmitReq xmlns="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2"><MM7Version>5.3.0</MM7Version><SenderIdentification><VASPID>messaging</VASPID><VASID>ADM</VASID><SenderAddress><ShortCode>1111</ShortCode></SenderAddress></SenderIdentification><Recipients><To><Number>11111111111</Number></To></Recipients><ServiceCode>1</ServiceCode><MessageClass>Personal</MessageClass><ExpiryDate>2011-01-28T13:53:58Z</ExpiryDate><DeliveryReport>false</DeliveryReport><ReadReply>false</ReadReply><Priority>Normal</Priority><Subject>Test MMS via Savon</Subject><ChargedParty>Sender</ChargedParty><Content href="cid:attachment_1" allowAdaptations="true"/></SubmitReq></soapenv:Body></soapenv:Envelope>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
----==_mimepart_4d416ae62fd32_201a8043814c4724
|
2
|
+
Date: Thu, 27 Jan 2011 13:53:58 +0100
|
3
|
+
Message-ID: <4d416ae631391_201a8043814c482c@Martin-iMac.local.mail>
|
4
|
+
Mime-Version: 1.0
|
5
|
+
Content-Type: text/xml;
|
6
|
+
charset=utf-8
|
7
|
+
Content-Transfer-Encoding: 7bit
|
8
|
+
content-id: soap_xml_part
|
9
|
+
|
10
|
+
<?xml version="1.0" encoding="UTF-8"?><envelope ><header></header><body><SubmitReq>true</SubmitReq></body></envelope>
|
11
|
+
|
12
|
+
----==_mimepart_4d416ae628621_201a8043814c46ea
|
13
|
+
Date: Thu, 27 Jan 2011 13:53:58 +0100
|
14
|
+
Message-ID: <4d416ae633ce8_201a8043814c49c7@Martin-iMac.local.mail>
|
15
|
+
Mime-Version: 1.0
|
16
|
+
Content-Type: text/plain;
|
17
|
+
charset=UTF-8
|
18
|
+
Content-Transfer-Encoding: 7bit
|
19
|
+
content-id: text_0.txt
|
20
|
+
|
21
|
+
This is a test message from Github
|
22
|
+
|
23
|
+
----==_mimepart_4d416ae628621_201a8043814c46ea--
|
24
|
+
|
25
|
+
----==_mimepart_4d416ae62fd32_201a8043814c4724--
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require 'savon-multipart'
|
2
2
|
|
3
|
-
describe Savon::
|
3
|
+
describe Savon::Multipart::Response do
|
4
4
|
|
5
5
|
before do
|
6
6
|
@header = { "Content-Type" => 'multipart/related; boundary="--==_mimepart_4d416ae62fd32_201a8043814c4724"; charset=UTF-8; type="text/xml"' }
|
@@ -11,22 +11,61 @@ describe Savon::SOAP::Response do
|
|
11
11
|
|
12
12
|
it "parses without Exception" do
|
13
13
|
response = soap_response :headers => @header, :body => @body
|
14
|
-
response.
|
14
|
+
response.xml.should == '<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:wsdl="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><ns1:TransactionID soapenv:actor="" soapenv:mustUnderstand="1" xsi:type="xsd:string" xmlns:ns1="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2">2011012713535811111111111</ns1:TransactionID></soapenv:Header><soapenv:Body><SubmitReq xmlns="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2"><MM7Version>5.3.0</MM7Version><SenderIdentification><VASPID>messaging</VASPID><VASID>ADM</VASID><SenderAddress><ShortCode>1111</ShortCode></SenderAddress></SenderIdentification><Recipients><To><Number>11111111111</Number></To></Recipients><ServiceCode>1</ServiceCode><MessageClass>Personal</MessageClass><ExpiryDate>2011-01-28T13:53:58Z</ExpiryDate><DeliveryReport>false</DeliveryReport><ReadReply>false</ReadReply><Priority>Normal</Priority><Subject>Test MMS via Savon</Subject><ChargedParty>Sender</ChargedParty><Content href="cid:attachment_1" allowAdaptations="true"/></SubmitReq></soapenv:Body></soapenv:Envelope>'
|
15
15
|
response.parts.length.should == 2
|
16
16
|
response.parts[1].parts.length.should == 3
|
17
17
|
response.parts[1].parts[2].body.should == "This is a test message from Github"
|
18
18
|
end
|
19
19
|
|
20
|
+
it "returns a String from the #xml method" do
|
21
|
+
body = File.read(File.expand_path('../../../fixtures/response/simple_multipart.txt', __FILE__))
|
22
|
+
response = soap_response :headers => @header, :body => body
|
23
|
+
response.xml.class.should == String
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns a Hash from the #body method" do
|
27
|
+
body = File.read(File.expand_path('../../../fixtures/response/simple_multipart.txt', __FILE__))
|
28
|
+
response = soap_response :headers => @header, :body => body
|
29
|
+
response.body.class.should == Hash
|
30
|
+
response.body.should == {:submit_req => true}
|
31
|
+
end
|
32
|
+
|
20
33
|
it "returns the attachments" do
|
21
34
|
response = soap_response :headers => @header, :body => @body
|
22
35
|
response.attachments.size.should == 1
|
23
36
|
end
|
24
37
|
|
38
|
+
it "parses soap messages without attachments too" do
|
39
|
+
header = { 'Content-Type' => 'text/html; charset=utf-8'}
|
40
|
+
body = File.read(File.expand_path('../../../fixtures/response/not_multipart.txt', __FILE__))
|
41
|
+
response = soap_response :headers => header, :body => body
|
42
|
+
|
43
|
+
response.xml.chomp.should == '<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:wsdl="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><ns1:TransactionID soapenv:actor="" soapenv:mustUnderstand="1" xsi:type="xsd:string" xmlns:ns1="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2">2011012713535811111111111</ns1:TransactionID></soapenv:Header><soapenv:Body><SubmitReq xmlns="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2"><MM7Version>5.3.0</MM7Version><SenderIdentification><VASPID>messaging</VASPID><VASID>ADM</VASID><SenderAddress><ShortCode>1111</ShortCode></SenderAddress></SenderIdentification><Recipients><To><Number>11111111111</Number></To></Recipients><ServiceCode>1</ServiceCode><MessageClass>Personal</MessageClass><ExpiryDate>2011-01-28T13:53:58Z</ExpiryDate><DeliveryReport>false</DeliveryReport><ReadReply>false</ReadReply><Priority>Normal</Priority><Subject>Test MMS via Savon</Subject><ChargedParty>Sender</ChargedParty><Content href="cid:attachment_1" allowAdaptations="true"/></SubmitReq></soapenv:Body></soapenv:Envelope>'
|
44
|
+
response.parts.size.should == 0
|
45
|
+
response.attachments.size.should == 0
|
46
|
+
end
|
47
|
+
|
48
|
+
it "only parses the SOAP body once" do
|
49
|
+
response = soap_response :headers => @header, :body => @body
|
50
|
+
response.xml
|
51
|
+
|
52
|
+
counter = 0
|
53
|
+
subbed_parse_body = lambda { counter += 1 }
|
54
|
+
response.class.send(:define_method, :parse_body, subbed_parse_body)
|
55
|
+
5.times { response.attachments }
|
56
|
+
|
57
|
+
counter.should == 0
|
58
|
+
end
|
59
|
+
|
25
60
|
def soap_response(options = {})
|
26
61
|
defaults = { :code => 200, :headers => {}, :body => "" }
|
27
62
|
response = defaults.merge options
|
63
|
+
globals = {
|
64
|
+
:multipart => true,
|
65
|
+
:convert_response_tags_to => lambda { |tag| tag.snakecase.to_sym}
|
66
|
+
}
|
67
|
+
http = HTTPI::Response.new(response[:code], response[:headers], response[:body])
|
28
68
|
|
29
|
-
Savon::
|
69
|
+
Savon::Multipart::Response.new(http, globals, {})
|
30
70
|
end
|
31
|
-
|
32
71
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: savon-multipart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Martin Westin
|
@@ -10,86 +9,76 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2014-05-13 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: savon
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- -
|
18
|
+
- - "~>"
|
21
19
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
20
|
+
version: 2.3.0
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- -
|
25
|
+
- - "~>"
|
29
26
|
- !ruby/object:Gem::Version
|
30
|
-
version:
|
27
|
+
version: 2.3.0
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: mail
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
|
-
- -
|
32
|
+
- - '='
|
37
33
|
- !ruby/object:Gem::Version
|
38
|
-
version:
|
34
|
+
version: 2.5.3
|
39
35
|
type: :runtime
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
|
-
- -
|
39
|
+
- - '='
|
45
40
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
41
|
+
version: 2.5.3
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: rake
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
|
-
- -
|
46
|
+
- - ">="
|
53
47
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0
|
48
|
+
version: '0'
|
55
49
|
type: :development
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
|
-
- -
|
53
|
+
- - ">="
|
61
54
|
- !ruby/object:Gem::Version
|
62
|
-
version: 0
|
55
|
+
version: '0'
|
63
56
|
- !ruby/object:Gem::Dependency
|
64
57
|
name: rspec
|
65
58
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
59
|
requirements:
|
68
|
-
- -
|
60
|
+
- - ">="
|
69
61
|
- !ruby/object:Gem::Version
|
70
|
-
version:
|
62
|
+
version: '0'
|
71
63
|
type: :development
|
72
64
|
prerelease: false
|
73
65
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
66
|
requirements:
|
76
|
-
- -
|
67
|
+
- - ">="
|
77
68
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
69
|
+
version: '0'
|
79
70
|
- !ruby/object:Gem::Dependency
|
80
71
|
name: autotest
|
81
72
|
requirement: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
73
|
requirements:
|
84
|
-
- -
|
74
|
+
- - ">="
|
85
75
|
- !ruby/object:Gem::Version
|
86
76
|
version: '0'
|
87
77
|
type: :development
|
88
78
|
prerelease: false
|
89
79
|
version_requirements: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
80
|
requirements:
|
92
|
-
- -
|
81
|
+
- - ">="
|
93
82
|
- !ruby/object:Gem::Version
|
94
83
|
version: '0'
|
95
84
|
description: Adds multipart support (SOAP with Attachments) to Savon
|
@@ -100,46 +89,43 @@ executables: []
|
|
100
89
|
extensions: []
|
101
90
|
extra_rdoc_files: []
|
102
91
|
files:
|
103
|
-
- .gitignore
|
104
|
-
- .rspec
|
105
|
-
- .travis.yml
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
106
95
|
- CHANGELOG.md
|
107
96
|
- Gemfile
|
108
97
|
- LICENSE
|
109
98
|
- README.md
|
110
99
|
- Rakefile
|
111
100
|
- lib/savon-multipart.rb
|
112
|
-
- lib/savon/multipart/
|
113
|
-
- lib/savon/multipart/soap/request.rb
|
114
|
-
- lib/savon/multipart/soap/response.rb
|
115
|
-
- lib/savon/multipart/soap/xml.rb
|
101
|
+
- lib/savon/multipart/response.rb
|
116
102
|
- lib/savon/multipart/version.rb
|
117
103
|
- savon-multipart.gemspec
|
118
104
|
- spec/fixtures/response/multipart.txt
|
105
|
+
- spec/fixtures/response/not_multipart.txt
|
106
|
+
- spec/fixtures/response/simple_multipart.txt
|
119
107
|
- spec/savon/soap/response_spec.rb
|
120
|
-
- spec/spec_helper.rb
|
121
108
|
homepage: http://savonrb.com
|
122
109
|
licenses: []
|
110
|
+
metadata: {}
|
123
111
|
post_install_message:
|
124
112
|
rdoc_options: []
|
125
113
|
require_paths:
|
126
114
|
- lib
|
127
115
|
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
-
none: false
|
129
116
|
requirements:
|
130
|
-
- -
|
117
|
+
- - ">="
|
131
118
|
- !ruby/object:Gem::Version
|
132
119
|
version: '0'
|
133
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
-
none: false
|
135
121
|
requirements:
|
136
|
-
- -
|
122
|
+
- - ">="
|
137
123
|
- !ruby/object:Gem::Version
|
138
124
|
version: '0'
|
139
125
|
requirements: []
|
140
126
|
rubyforge_project: savon-multipart
|
141
|
-
rubygems_version:
|
127
|
+
rubygems_version: 2.2.2
|
142
128
|
signing_key:
|
143
|
-
specification_version:
|
129
|
+
specification_version: 4
|
144
130
|
summary: Heavy metal Ruby SOAP client with multipart support
|
145
131
|
test_files: []
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Savon
|
2
|
-
module SOAP
|
3
|
-
class Request
|
4
|
-
|
5
|
-
private
|
6
|
-
|
7
|
-
def configure(http)
|
8
|
-
http.url = soap.endpoint
|
9
|
-
if soap.has_parts? # do multipart stuff if soap has parts
|
10
|
-
request_message = soap.request_message
|
11
|
-
# takes relevant http headers from the "Mail" message and makes
|
12
|
-
# them Net::HTTP compatible
|
13
|
-
request_message.header.fields.each do |field|
|
14
|
-
http.headers[field.name] = field.to_s
|
15
|
-
end
|
16
|
-
#request.headers["Content-Type"] << %|; start="<savon_soap_xml_part>"|
|
17
|
-
request_message.body.set_sort_order soap.parts_sort_order if soap.parts_sort_order && soap.parts_sort_order.any?
|
18
|
-
http.body = request_message.body.encoded
|
19
|
-
else
|
20
|
-
http.body = soap.to_xml
|
21
|
-
end
|
22
|
-
http.headers["Content-Type"] ||= CONTENT_TYPE[soap.version]
|
23
|
-
http.headers["Content-Length"] = http.body.bytesize.to_s
|
24
|
-
http
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require "savon/multipart/soap/part"
|
2
|
-
|
3
|
-
module Savon
|
4
|
-
module SOAP
|
5
|
-
class Response
|
6
|
-
|
7
|
-
# Overwrite to +decode_multipart+.
|
8
|
-
def initialize(config, response)
|
9
|
-
self.http = response
|
10
|
-
decode_multipart
|
11
|
-
raise_errors if config.raise_errors
|
12
|
-
end
|
13
|
-
|
14
|
-
def parts
|
15
|
-
@parts || []
|
16
|
-
end
|
17
|
-
|
18
|
-
attr_writer :parts
|
19
|
-
|
20
|
-
# Returns +true+ if this is a multipart response.
|
21
|
-
def multipart?
|
22
|
-
http.headers["Content-Type"] =~ /^multipart/
|
23
|
-
end
|
24
|
-
|
25
|
-
# Returns the boundary declaration of the multipart response.
|
26
|
-
def boundary
|
27
|
-
return unless multipart?
|
28
|
-
@boundary ||= Mail::Field.new("Content-Type", http.headers["Content-Type"]).parameters['boundary']
|
29
|
-
end
|
30
|
-
|
31
|
-
# Returns the Array of attachments if it was a multipart response.
|
32
|
-
def attachments
|
33
|
-
parts.attachments
|
34
|
-
end
|
35
|
-
|
36
|
-
# Overwrite to work with multipart response.
|
37
|
-
def to_xml
|
38
|
-
if multipart?
|
39
|
-
parts.first.body.decoded # we just assume the first part is the XML
|
40
|
-
else
|
41
|
-
http.body
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
# Decoding multipart responses.
|
48
|
-
#
|
49
|
-
# <tt>response.to_xml</tt> will point to the first part, hopefully the SOAP part of the multipart.
|
50
|
-
# All attachments are available in the <tt>response.parts</tt> Array. Each is a Part from the mail gem.
|
51
|
-
# See the docs there for details but:
|
52
|
-
#
|
53
|
-
# * response.parts[0].body is the contents
|
54
|
-
# * response.parts[0].headers are the mime headers
|
55
|
-
#
|
56
|
-
# And you can do nesting:
|
57
|
-
#
|
58
|
-
# * response.parts[0].parts[2].body
|
59
|
-
def decode_multipart
|
60
|
-
return unless multipart?
|
61
|
-
part_of_parts = Part.new(:headers => http.headers, :body => http.body)
|
62
|
-
part_of_parts.body.split!(boundary)
|
63
|
-
self.parts = part_of_parts.parts
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require "savon/multipart/soap/part"
|
2
|
-
|
3
|
-
module Savon
|
4
|
-
module SOAP
|
5
|
-
class XML
|
6
|
-
|
7
|
-
# Use sort functionality in Mail::Body.sort!() to order parts.
|
8
|
-
# An array of mime types is expected.
|
9
|
-
# E.g. this makes the xml appear before an attached image: ["text/xml", "image/jpeg"]
|
10
|
-
attr_accessor :parts_sort_order
|
11
|
-
|
12
|
-
# Adds a Part object to the current SOAP "message".
|
13
|
-
# Parts are really attachments.
|
14
|
-
def add_part(part)
|
15
|
-
@parts ||= Array.new
|
16
|
-
@parts << part
|
17
|
-
end
|
18
|
-
|
19
|
-
# Check if any parts have been added.
|
20
|
-
def has_parts?
|
21
|
-
@parts ||= Array.new
|
22
|
-
!@parts.empty?
|
23
|
-
end
|
24
|
-
|
25
|
-
# Returns the mime message for a multipart request.
|
26
|
-
def request_message
|
27
|
-
return if @parts.empty?
|
28
|
-
|
29
|
-
@request_message = Part.new do
|
30
|
-
content_type 'multipart/related; type="text/xml"'
|
31
|
-
end
|
32
|
-
|
33
|
-
soap_body = self.to_xml
|
34
|
-
soap_message = Part.new do
|
35
|
-
content_type 'text/xml; charset=utf-8'
|
36
|
-
add_content_transfer_encoding
|
37
|
-
body soap_body
|
38
|
-
end
|
39
|
-
soap_message.add_content_id "<savon_soap_xml_part>"
|
40
|
-
@request_message.add_part(soap_message)
|
41
|
-
@parts.each do |part|
|
42
|
-
@request_message.add_part(part)
|
43
|
-
end
|
44
|
-
#puts @request_message
|
45
|
-
@request_message
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|