wasabi 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 2.2.0 (2012-06-06)
2
+
3
+ * Improvement: [#5](https://github.com/rubiii/wasabi/pull/5) - Get input from message
4
+ element or portType input. See [rubiii/savon#277](https://github.com/rubiii/savon/pull/277)
5
+ to get the full picture on how this all works together, and enables you to pass a single
6
+ symbol into the `Savon::Client#request` method and get automatic namespace mapping, as well
7
+ as the proper operation name -> input message mapping.
8
+
1
9
  ## 2.1.1 (2012-05-18)
2
10
 
3
11
  * Fix: [issue 7](https://github.com/rubiii/wasabi/issues/7) - Performance regression.
data/lib/wasabi/parser.rb CHANGED
@@ -82,8 +82,12 @@ module Wasabi
82
82
  if soap_action
83
83
  soap_action = soap_action.to_s
84
84
  action = soap_action.blank? ? name : soap_action
85
- input = name.blank? ? action.split("/").last : name
86
- @operations[input.snakecase.to_sym] = { :action => action, :input => input }
85
+
86
+ # There should be a matching portType for each binding, so we will lookup the input from there.
87
+ namespace_id, input = input_for(operation)
88
+
89
+ # Store namespace identifier so this operation can be mapped to the proper namespace.
90
+ @operations[name.snakecase.to_sym] = { :action => action, :input => input, :namespace_identifier => namespace_id }
87
91
  elsif !@operations[name.snakecase.to_sym]
88
92
  @operations[name.snakecase.to_sym] = { :action => name, :input => name }
89
93
  end
@@ -111,5 +115,27 @@ module Wasabi
111
115
  schema_namespace ? schema_namespace.to_s : @namespace
112
116
  end
113
117
 
118
+ def input_for(operation)
119
+ operation_name = operation.attribute("name")
120
+
121
+ # Look up the input by walking up to portType, then up to the message.
122
+
123
+ binding_input = at_xpath(operation, ".//wsdl:input/@name")
124
+ binding_type = at_xpath(operation, "../@type").to_s.split(':').last
125
+ port_type_input = at_xpath(operation, "../../wsdl:portType[@name='#{binding_type}']/wsdl:operation[@name='#{operation_name}']/wsdl:input")
126
+
127
+ port_message_ns_id, port_message_type = port_type_input.attribute("message").to_s.split(':')
128
+
129
+ # Kinda hackey maybe? This assumes there is ever only one 'part' element in the message.
130
+ message_ns_id, message_type = at_xpath(port_type_input, "../../../wsdl:message[@name='#{port_message_type}']/wsdl:part[1]").attribute("element").to_s.split(':')
131
+
132
+ # Fall back to message name in portType input if no 'element' attribute in wsdl:message
133
+ if message_type
134
+ [message_ns_id, message_type]
135
+ else
136
+ [port_message_ns_id, port_message_type]
137
+ end
138
+ end
139
+
114
140
  end
115
141
  end
@@ -1,5 +1,5 @@
1
1
  module Wasabi
2
2
 
3
- VERSION = "2.1.1"
3
+ VERSION = "2.2.0"
4
4
 
5
5
  end
File without changes
File without changes
File without changes
@@ -1,13 +1,20 @@
1
1
  module Fixture
2
2
 
3
- def fixture(file)
4
- fixtures[file] ||= File.read File.expand_path("spec/fixtures/#{file}.xml")
3
+ def self.[](name)
4
+ fixtures[name]
5
5
  end
6
6
 
7
- private
7
+ def self.[]=(name, value)
8
+ fixtures[name] = value
9
+ end
8
10
 
9
- def fixtures
11
+ def self.fixtures
10
12
  @fixtures ||= {}
11
13
  end
12
14
 
15
+ def fixture(file, ext = :wsdl)
16
+ filename = "#{file}.#{ext}"
17
+ Fixture[filename] ||= File.read File.expand_path("spec/fixtures/#{filename}")
18
+ end
19
+
13
20
  end
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Wasabi::Document do
4
- context "with: authentication.xml" do
4
+ context "with: authentication.wsdl" do
5
5
 
6
6
  subject { Wasabi::Document.new fixture(:authentication) }
7
7
 
@@ -15,7 +15,7 @@ describe Wasabi::Document do
15
15
 
16
16
  its(:operations) do
17
17
  should == {
18
- :authenticate => { :input => "authenticate", :action => "authenticate" }
18
+ :authenticate => { :input => "authenticate", :action => "authenticate", :namespace_identifier => "tns" }
19
19
  }
20
20
  end
21
21
 
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Wasabi::Document do
4
- context "with: geotrust.xml" do
4
+ context "with: geotrust.wsdl" do
5
5
 
6
6
  subject { Wasabi::Document.new fixture(:geotrust) }
7
7
 
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Wasabi::Document do
4
- context "with: multiple_namespaces.xml" do
4
+ context "with: multiple_namespaces.wsdl" do
5
5
 
6
6
  subject { Wasabi::Document.new fixture(:multiple_namespaces) }
7
7
 
@@ -14,7 +14,7 @@ describe Wasabi::Document do
14
14
  it { should have(1).operations }
15
15
 
16
16
  its(:operations) do
17
- should == { :save => { :input => "Save", :action => "http://example.com/actions.Save" } }
17
+ should == { :save => { :input => "Save", :action => "http://example.com/actions.Save", :namespace_identifier => "actions" } }
18
18
  end
19
19
 
20
20
  its(:type_namespaces) do
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Wasabi::Document do
4
- context "with: namespaced_actions.xml" do
4
+ context "with: namespaced_actions.wsdl" do
5
5
 
6
6
  subject { Wasabi::Document.new fixture(:namespaced_actions) }
7
7
 
@@ -15,9 +15,9 @@ describe Wasabi::Document do
15
15
 
16
16
  its(:operations) do
17
17
  should include(
18
- { :delete_client => { :input => "DeleteClient", :action => "http://api.example.com/api/Client.Delete" } },
19
- { :get_clients => { :input => "GetClients", :action => "http://api.example.com/api/User.GetClients" } },
20
- { :get_api_key => { :input => "GetApiKey", :action => "http://api.example.com/api/User.GetApiKey" } }
18
+ { :delete_client => { :input => "Client.Delete", :action => "http://api.example.com/api/Client.Delete", :namespace_identifier => "tns" } },
19
+ { :get_clients => { :input => "User.GetClients", :action => "http://api.example.com/api/User.GetClients", :namespace_identifier => "tns" } },
20
+ { :get_api_key => { :input => "User.GetApiKey", :action => "http://api.example.com/api/User.GetApiKey", :namespace_identifier => "tns" } }
21
21
  )
22
22
  end
23
23
 
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Wasabi::Document do
4
- context "with: no_namespace.xml" do
4
+ context "with: no_namespace.wsdl" do
5
5
 
6
6
  subject { Wasabi::Document.new fixture(:no_namespace) }
7
7
 
@@ -15,9 +15,9 @@ describe Wasabi::Document do
15
15
 
16
16
  its(:operations) do
17
17
  should include(
18
- { :get_user_login_by_id => { :input => "GetUserLoginById", :action => "/api/api/GetUserLoginById" } },
19
- { :get_all_contacts => { :input => "GetAllContacts", :action => "/api/api/GetAllContacts" } },
20
- { :search_user => { :input => "SearchUser", :action => "/api/api/SearchUser" } }
18
+ { :get_user_login_by_id => { :input => "GetUserLoginById", :action => "/api/api/GetUserLoginById", :namespace_identifier => "typens" } },
19
+ { :get_all_contacts => { :input => "GetAllContacts", :action => "/api/api/GetAllContacts", :namespace_identifier => "typens" } },
20
+ { :search_user => { :input => "SearchUser", :action => "/api/api/SearchUser", :namespace_identifier => "typens" } }
21
21
  )
22
22
  end
23
23
 
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Wasabi::Document do
4
- context "with: soap12.xml" do
4
+ context "with: soap12.wsdl" do
5
5
 
6
6
  subject { Wasabi::Document.new fixture(:soap12) }
7
7
 
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Wasabi::Document do
4
- context "with: two_bindings.xml" do
4
+ context "with: two_bindings.wsdl" do
5
5
 
6
6
  subject { Wasabi::Document.new fixture(:two_bindings) }
7
7
 
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Wasabi::Parser do
4
- context "with: multiple_namespaces.xml" do
4
+ context "with: multiple_namespaces.wsdl" do
5
5
 
6
6
  subject do
7
7
  parser = Wasabi::Parser.new Nokogiri::XML(xml)
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Wasabi::Parser do
4
- context "with: no_namespace.xml" do
4
+ context "with: no_namespace.wsdl" do
5
5
 
6
6
  subject do
7
7
  parser = Wasabi::Parser.new Nokogiri::XML(xml)
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Wasabi::Parser do
4
- context "with: symbolic_endpoint.xml" do
4
+ context "with: symbolic_endpoint.wsdl" do
5
5
 
6
6
  subject do
7
7
  parser = Wasabi::Parser.new Nokogiri::XML(xml)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wasabi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
- - 1
9
- - 1
10
- version: 2.1.1
8
+ - 2
9
+ - 0
10
+ version: 2.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Harrington
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-18 00:00:00 Z
18
+ date: 2012-06-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -103,16 +103,16 @@ files:
103
103
  - lib/wasabi/parser.rb
104
104
  - lib/wasabi/version.rb
105
105
  - lib/wasabi/xpath_helper.rb
106
- - spec/fixtures/authentication.xml
107
- - spec/fixtures/geotrust.xml
108
- - spec/fixtures/lower_camel.xml
109
- - spec/fixtures/multiple_namespaces.xml
110
- - spec/fixtures/multiple_types.xml
111
- - spec/fixtures/namespaced_actions.xml
112
- - spec/fixtures/no_namespace.xml
113
- - spec/fixtures/soap12.xml
114
- - spec/fixtures/symbolic_endpoint.xml
115
- - spec/fixtures/two_bindings.xml
106
+ - spec/fixtures/authentication.wsdl
107
+ - spec/fixtures/geotrust.wsdl
108
+ - spec/fixtures/lower_camel.wsdl
109
+ - spec/fixtures/multiple_namespaces.wsdl
110
+ - spec/fixtures/multiple_types.wsdl
111
+ - spec/fixtures/namespaced_actions.wsdl
112
+ - spec/fixtures/no_namespace.wsdl
113
+ - spec/fixtures/soap12.wsdl
114
+ - spec/fixtures/symbolic_endpoint.wsdl
115
+ - spec/fixtures/two_bindings.wsdl
116
116
  - spec/spec_helper.rb
117
117
  - spec/support/fixture.rb
118
118
  - spec/wasabi/core_ext/object_spec.rb
@@ -165,16 +165,16 @@ signing_key:
165
165
  specification_version: 3
166
166
  summary: A simple WSDL parser
167
167
  test_files:
168
- - spec/fixtures/authentication.xml
169
- - spec/fixtures/geotrust.xml
170
- - spec/fixtures/lower_camel.xml
171
- - spec/fixtures/multiple_namespaces.xml
172
- - spec/fixtures/multiple_types.xml
173
- - spec/fixtures/namespaced_actions.xml
174
- - spec/fixtures/no_namespace.xml
175
- - spec/fixtures/soap12.xml
176
- - spec/fixtures/symbolic_endpoint.xml
177
- - spec/fixtures/two_bindings.xml
168
+ - spec/fixtures/authentication.wsdl
169
+ - spec/fixtures/geotrust.wsdl
170
+ - spec/fixtures/lower_camel.wsdl
171
+ - spec/fixtures/multiple_namespaces.wsdl
172
+ - spec/fixtures/multiple_types.wsdl
173
+ - spec/fixtures/namespaced_actions.wsdl
174
+ - spec/fixtures/no_namespace.wsdl
175
+ - spec/fixtures/soap12.wsdl
176
+ - spec/fixtures/symbolic_endpoint.wsdl
177
+ - spec/fixtures/two_bindings.wsdl
178
178
  - spec/spec_helper.rb
179
179
  - spec/support/fixture.rb
180
180
  - spec/wasabi/core_ext/object_spec.rb