wasabi 2.3.0 → 2.4.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,9 @@
1
+ ## 2.4.0 (2012-06-08)
2
+
3
+ * Feature: `Wasabi::Document` now accepts either a URL of a remote document,
4
+ a path to a local file or raw XML. The code for this was moved from Savon over
5
+ here as a first step towards supporting WSDL imports.
6
+
1
7
  ## 2.3.0 (2012-06-07)
2
8
 
3
9
  * Improvement: [#3](https://github.com/rubiii/wasabi/pull/3) adds object inheritance.
data/lib/wasabi.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "wasabi/version"
2
2
  require "wasabi/document"
3
+ require "wasabi/resolver"
3
4
 
4
5
  module Wasabi
5
6
 
@@ -1,4 +1,5 @@
1
1
  require "nokogiri"
2
+ require "wasabi/resolver"
2
3
  require "wasabi/parser"
3
4
 
4
5
  module Wasabi
@@ -24,12 +25,9 @@ module Wasabi
24
25
  self.document = document
25
26
  end
26
27
 
27
- attr_accessor :document
28
+ attr_accessor :document, :request, :xml
28
29
 
29
- # Returns whether a +document+ was set.
30
- def document?
31
- !!document
32
- end
30
+ alias_method :document?, :document
33
31
 
34
32
  # Returns the SOAP endpoint.
35
33
  def endpoint
@@ -49,7 +47,7 @@ module Wasabi
49
47
 
50
48
  # Returns the value of elementFormDefault.
51
49
  def element_form_default
52
- @element_form_default ||= xml? ? parser.element_form_default : :unqualified
50
+ @element_form_default ||= document ? parser.element_form_default : :unqualified
53
51
  end
54
52
 
55
53
  # Sets the elementFormDefault value.
@@ -84,7 +82,7 @@ module Wasabi
84
82
  parser.types.each do |type, info|
85
83
  namespaces << [[type], info[:namespace]]
86
84
  (info.keys - [:namespace]).each { |field| namespaces << [[type, field], info[:namespace]] }
87
- end if document?
85
+ end if document
88
86
  namespaces
89
87
  end
90
88
  end
@@ -98,7 +96,7 @@ module Wasabi
98
96
  tag, namespace = field_type.split(":").reverse
99
97
  result << [[type, field], tag] if user_defined(namespace)
100
98
  end
101
- end if document?
99
+ end if document
102
100
  result
103
101
  end
104
102
  end
@@ -112,12 +110,7 @@ module Wasabi
112
110
  # Returns the raw WSDL document.
113
111
  # Can be used as a hook to extend the library.
114
112
  def xml
115
- @xml ||= document
116
- end
117
-
118
- # Returns whether there is a WSDL document to parse.
119
- def xml?
120
- xml.kind_of?(String)
113
+ @xml ||= Resolver.new(document, request).xml
121
114
  end
122
115
 
123
116
  # Parses the WSDL document and returns the <tt>Wasabi::Parser</tt>.
@@ -129,7 +122,7 @@ module Wasabi
129
122
 
130
123
  # Raises an error if the WSDL document is missing.
131
124
  def guard_parse
132
- return true if xml?
125
+ return true if document
133
126
  raise ArgumentError, "Wasabi needs a WSDL document"
134
127
  end
135
128
 
@@ -0,0 +1,46 @@
1
+ require "httpi"
2
+
3
+ module Wasabi
4
+
5
+ # = Wasabi::Resolver
6
+ #
7
+ # Resolves local and remote WSDL documents.
8
+ class Resolver
9
+
10
+ class HTTPError < StandardError; end
11
+
12
+ def initialize(document, request = nil)
13
+ @document = document
14
+ @request = request
15
+ end
16
+
17
+ def xml
18
+ raise ArgumentError, "Wasabi is missing a document to resolve" unless @document
19
+
20
+ case @document
21
+ when /^http[s]?:/ then from_remote
22
+ when /^</ then @document
23
+ else from_fs
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def from_remote
30
+ response = HTTPI.get(request)
31
+ raise HTTPError.new(response) if response.error?
32
+ response.body
33
+ end
34
+
35
+ def request
36
+ @request ||= HTTPI::Request.new
37
+ @request.url = @document
38
+ @request
39
+ end
40
+
41
+ def from_fs
42
+ File.read(@document)
43
+ end
44
+
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  module Wasabi
2
2
 
3
- VERSION = "2.3.0"
3
+ VERSION = "2.4.0"
4
4
 
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -5,5 +5,5 @@ support_files = File.expand_path("spec/support/**/*.rb")
5
5
  Dir[support_files].each { |file| require file }
6
6
 
7
7
  RSpec.configure do |config|
8
- config.include Fixture
8
+ config.include SpecSupport::Methods
9
9
  end
@@ -1,20 +1,42 @@
1
- module Fixture
1
+ module SpecSupport
2
2
 
3
- def self.[](name)
4
- fixtures[name]
5
- end
3
+ class Fixture
4
+ def self.[](name)
5
+ fixtures[name]
6
+ end
6
7
 
7
- def self.[]=(name, value)
8
- fixtures[name] = value
9
- end
8
+ def self.[]=(name, value)
9
+ fixtures[name] = value
10
+ end
11
+
12
+ def self.fixtures
13
+ @fixtures ||= {}
14
+ end
15
+
16
+ def initialize(file, ext = :wsdl)
17
+ self.file = file
18
+ self.ext = ext
19
+ end
20
+
21
+ attr_accessor :file, :ext
22
+
23
+ def filename
24
+ "#{file}.#{ext}"
25
+ end
26
+
27
+ def path
28
+ File.expand_path("spec/fixtures/#{filename}")
29
+ end
10
30
 
11
- def self.fixtures
12
- @fixtures ||= {}
31
+ def read
32
+ Fixture[filename] ||= File.read(path)
33
+ end
13
34
  end
14
35
 
15
- def fixture(file, ext = :wsdl)
16
- filename = "#{file}.#{ext}"
17
- Fixture[filename] ||= File.read File.expand_path("spec/fixtures/#{filename}")
36
+ module Methods
37
+ def fixture(*args)
38
+ Fixture.new(*args)
39
+ end
18
40
  end
19
41
 
20
42
  end
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe Wasabi::Document do
4
4
  context "with: authentication.wsdl" do
5
5
 
6
- subject { Wasabi::Document.new fixture(:authentication) }
6
+ subject { Wasabi::Document.new fixture(:authentication).read }
7
7
 
8
8
  its(:namespace) { should == "http://v1_0.ws.auth.order.example.com/" }
9
9
 
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe Wasabi::Document do
4
4
  context "with: geotrust.wsdl" do
5
5
 
6
- subject { Wasabi::Document.new fixture(:geotrust) }
6
+ subject { Wasabi::Document.new fixture(:geotrust).read }
7
7
 
8
8
  its(:namespace) { should == "http://api.geotrust.com/webtrust/query" }
9
9
 
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe Wasabi::Document do
4
4
  context "with: inherited.xml" do
5
5
 
6
- subject { Wasabi::Document.new fixture(:inherited) }
6
+ subject { Wasabi::Document.new fixture(:inherited).read }
7
7
 
8
8
  its(:type_definitions) do
9
9
  should include([["Account", "Id"], "ID"])
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe Wasabi::Document do
4
4
  context "with: multiple_namespaces.wsdl" do
5
5
 
6
- subject { Wasabi::Document.new fixture(:multiple_namespaces) }
6
+ subject { Wasabi::Document.new fixture(:multiple_namespaces).read }
7
7
 
8
8
  its(:namespace) { should == "http://example.com/actions" }
9
9
 
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe Wasabi::Document do
4
4
  context "with: namespaced_actions.wsdl" do
5
5
 
6
- subject { Wasabi::Document.new fixture(:namespaced_actions) }
6
+ subject { Wasabi::Document.new fixture(:namespaced_actions).read }
7
7
 
8
8
  its(:namespace) { should == "http://api.example.com/api/" }
9
9
 
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe Wasabi::Document do
4
4
  context "with: no_namespace.wsdl" do
5
5
 
6
- subject { Wasabi::Document.new fixture(:no_namespace) }
6
+ subject { Wasabi::Document.new fixture(:no_namespace).read }
7
7
 
8
8
  its(:namespace) { should == "urn:ActionWebService" }
9
9
 
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe Wasabi::Document do
4
4
  context "with: soap12.wsdl" do
5
5
 
6
- subject { Wasabi::Document.new fixture(:soap12) }
6
+ subject { Wasabi::Document.new fixture(:soap12).read }
7
7
 
8
8
  its(:endpoint) { should == URI("http://blogsite.example.com/endpoint12") }
9
9
 
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe Wasabi::Document do
4
4
  context "with: two_bindings.wsdl" do
5
5
 
6
- subject { Wasabi::Document.new fixture(:two_bindings) }
6
+ subject { Wasabi::Document.new fixture(:two_bindings).read }
7
7
 
8
8
  its(:element_form_default) { should == :unqualified }
9
9
 
@@ -2,7 +2,26 @@ require "spec_helper"
2
2
 
3
3
  describe Wasabi::Document do
4
4
 
5
- subject { Wasabi::Document.new }
5
+ subject { Wasabi::Document.new fixture(:authentication).read }
6
+
7
+ describe ".new" do
8
+ it "accepts a URL" do
9
+ HTTPI.expects(:get).returns(HTTPI::Response.new(200, {}, "wsdl"))
10
+
11
+ document = Wasabi::Document.new("http://example.com?wsdl")
12
+ document.xml.should == "wsdl"
13
+ end
14
+
15
+ it "accepts a path" do
16
+ document = Wasabi::Document.new fixture(:authentication).path
17
+ document.xml.should == fixture(:authentication).read
18
+ end
19
+
20
+ it "accepts raw XML" do
21
+ document = Wasabi::Document.new fixture(:authentication).read
22
+ document.xml.should == fixture(:authentication).read
23
+ end
24
+ end
6
25
 
7
26
  describe ".validate_element_form_default!" do
8
27
  [:unqualified, :qualified].each do |value|
@@ -9,7 +9,7 @@ describe Wasabi::Parser do
9
9
  parser
10
10
  end
11
11
 
12
- let(:xml) { fixture(:multiple_namespaces) }
12
+ let(:xml) { fixture(:multiple_namespaces).read }
13
13
 
14
14
  it "lists the types" do
15
15
  subject.types.keys.sort.should == ["Article", "Save"]
@@ -9,7 +9,7 @@ describe Wasabi::Parser do
9
9
  parser
10
10
  end
11
11
 
12
- let(:xml) { fixture(:no_namespace) }
12
+ let(:xml) { fixture(:no_namespace).read }
13
13
 
14
14
  it "lists the types" do
15
15
  subject.types.keys.sort.should == ["McContact", "McContactArray", "MpUser", "MpUserArray"]
@@ -9,7 +9,7 @@ describe Wasabi::Parser do
9
9
  parser
10
10
  end
11
11
 
12
- let(:xml) { fixture(:symbolic_endpoint) }
12
+ let(:xml) { fixture(:symbolic_endpoint).read }
13
13
 
14
14
  it "allows symbolic endpoints" do
15
15
  subject.endpoint.should be_nil
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe Wasabi::Resolver do
4
+
5
+ describe "#xml" do
6
+ it "resolves remote documents" do
7
+ HTTPI.expects(:get).returns(HTTPI::Response.new(200, {}, "wsdl"))
8
+ xml = Wasabi::Resolver.new("http://example.com?wsdl").xml
9
+ xml.should == "wsdl"
10
+ end
11
+
12
+ it "resolves remote documents" do
13
+ xml = Wasabi::Resolver.new(fixture(:authentication).path).xml
14
+ xml.should == fixture(:authentication).read
15
+ end
16
+
17
+ it "simply returns raw XML" do
18
+ xml = Wasabi::Resolver.new("<xml/>").xml
19
+ xml.should == "<xml/>"
20
+ end
21
+ end
22
+
23
+ end
@@ -4,7 +4,7 @@ describe Wasabi do
4
4
 
5
5
  describe ".document" do
6
6
  it "should return a new Wasabi::Document" do
7
- document = Wasabi.document fixture(:authentication)
7
+ document = Wasabi.document fixture(:authentication).read
8
8
  document.should be_a(Wasabi::Document)
9
9
  end
10
10
  end
data/wasabi.gemspec CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.rubyforge_project = s.name
15
15
 
16
+ s.add_dependency "httpi", "~> 1.0"
16
17
  s.add_dependency "nokogiri", ">= 1.4.0"
17
18
 
18
19
  s.add_development_dependency "rake", "~> 0.9"
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: 3
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 2.3.0
10
+ version: 2.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Harrington
@@ -15,10 +15,25 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-07 00:00:00 Z
18
+ date: 2012-06-08 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ hash: 15
27
+ segments:
28
+ - 1
29
+ - 0
30
+ version: "1.0"
31
+ name: httpi
32
+ type: :runtime
33
+ prerelease: false
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
22
37
  none: false
23
38
  requirements:
24
39
  - - ">="
@@ -32,9 +47,9 @@ dependencies:
32
47
  name: nokogiri
33
48
  type: :runtime
34
49
  prerelease: false
35
- requirement: *id001
50
+ requirement: *id002
36
51
  - !ruby/object:Gem::Dependency
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
38
53
  none: false
39
54
  requirements:
40
55
  - - ~>
@@ -47,9 +62,9 @@ dependencies:
47
62
  name: rake
48
63
  type: :development
49
64
  prerelease: false
50
- requirement: *id002
65
+ requirement: *id003
51
66
  - !ruby/object:Gem::Dependency
52
- version_requirements: &id003 !ruby/object:Gem::Requirement
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
53
68
  none: false
54
69
  requirements:
55
70
  - - ~>
@@ -62,9 +77,9 @@ dependencies:
62
77
  name: rspec
63
78
  type: :development
64
79
  prerelease: false
65
- requirement: *id003
80
+ requirement: *id004
66
81
  - !ruby/object:Gem::Dependency
67
- version_requirements: &id004 !ruby/object:Gem::Requirement
82
+ version_requirements: &id005 !ruby/object:Gem::Requirement
68
83
  none: false
69
84
  requirements:
70
85
  - - ~>
@@ -77,7 +92,7 @@ dependencies:
77
92
  name: mocha
78
93
  type: :development
79
94
  prerelease: false
80
- requirement: *id004
95
+ requirement: *id005
81
96
  description: A simple WSDL parser
82
97
  email:
83
98
  - me@rubiii.com
@@ -101,6 +116,7 @@ files:
101
116
  - lib/wasabi/core_ext/string.rb
102
117
  - lib/wasabi/document.rb
103
118
  - lib/wasabi/parser.rb
119
+ - lib/wasabi/resolver.rb
104
120
  - lib/wasabi/version.rb
105
121
  - lib/wasabi/xpath_helper.rb
106
122
  - spec/fixtures/authentication.wsdl
@@ -131,6 +147,7 @@ files:
131
147
  - spec/wasabi/parser/no_namespace_spec.rb
132
148
  - spec/wasabi/parser/no_target_namespace_spec.rb
133
149
  - spec/wasabi/parser/symbolic_endpoint_spec.rb
150
+ - spec/wasabi/resolver_spec.rb
134
151
  - spec/wasabi/wasabi_spec.rb
135
152
  - wasabi.gemspec
136
153
  homepage: https://github.com/rubiii/wasabi
@@ -195,4 +212,5 @@ test_files:
195
212
  - spec/wasabi/parser/no_namespace_spec.rb
196
213
  - spec/wasabi/parser/no_target_namespace_spec.rb
197
214
  - spec/wasabi/parser/symbolic_endpoint_spec.rb
215
+ - spec/wasabi/resolver_spec.rb
198
216
  - spec/wasabi/wasabi_spec.rb