savon 0.6.0 → 0.6.3

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.
data/CHANGELOG ADDED
@@ -0,0 +1,32 @@
1
+ == 0.6.3 (2009-12-11)
2
+ * Removing 2 ruby deprecation warnings for parenthesized arguments. (Dave Woodward <dave@futuremint.com>)
3
+ * Much faster XPath expressions for parsing the WSDL document.
4
+ * Added global and per request options for disabling Savon::WSDL.
5
+
6
+ == 0.6.2 (2009-12-06)
7
+ * Support for changing the name of the SOAP input node.
8
+ * Added a CHANGELOG.
9
+
10
+ == 0.6.1 (2009-12-06)
11
+ * Fixed a problem with WSSE credentials, where every request contained a WSSE authentication header.
12
+
13
+ == 0.6.0 (2009-12-06)
14
+ * method_missing now yields the SOAP and WSSE objects to a given block.
15
+ * The response_process (which previously was a block passed to method_missing) was replaced by the Savon::Response object.
16
+ * Improved SOAP action handling (another problem that came up with Issue #1).
17
+
18
+ == 0.5.3 (2009-11-30)
19
+ * Fix for Issue #2 (NoMethodError: undefined method `invalid!' for Savon::WSDL)
20
+
21
+ == 0.5.2 (2009-11-30)
22
+ * Patch for Issue #1 (Calls fail if api methods have periods in them)
23
+
24
+ == 0.5.1 (2009-11-29)
25
+ * Optimized default response process.
26
+ * Added WSSE settings via defaults.
27
+ * Added SOAP fault and HTTP error handling.
28
+ * Improved documentation
29
+ * Added specs
30
+
31
+ == 0.5.0 (2009-11-29)
32
+ * Complete rewrite.
data/README.textile CHANGED
@@ -1,68 +1,70 @@
1
- h2. Savon
1
+ h1. Savon
2
2
 
3
- p. Savon can be installed as a gem via:
3
+ h4. Heavy metal Ruby SOAP client library
4
4
 
5
5
  bc. $ gem install savon
6
6
 
7
- h4. Dependencies
7
+ p. Savon expects you to be familiar with SOAP, WSDL and tools like soapUI.
8
8
 
9
- bc. builder >= 2.1.2
10
- crack >= 0.1.4
9
+ h3. Instantiate a client
11
10
 
12
- h2. Warning
11
+ p. Instantiate Savon::Client, passing in the WSDL of your service.
13
12
 
14
- p. To use this heavy metal library, you should be familiar with SOAP, WSDL and tools like soapUI.
13
+ bc. client = Savon::Client.new "http://example.com/UserService?wsdl"
15
14
 
16
- h2. Instantiate Savon::Client
15
+ h3. Calling a SOAP action
17
16
 
18
- p. Instantiate a new instance of Savon::Client, passing in the WSDL of your service.
17
+ p. Assuming your service applies to the "Defaults":http://wiki.github.com/rubiii/savon/defaults, you can now call any available SOAP action.
19
18
 
20
- bc. proxy = Savon::Client.new "http://example.com/UserService?wsdl"
19
+ bc. response = client.get_all_users
21
20
 
22
- h2. The WSDL
23
-
24
- p. You can find out about the SOAP actions available on the webservice by using the WSDL object.
25
-
26
- bc. proxy.wsdl.soap_actions
27
- => [:get_all_users, :get_user_by_id, :user_magic]
21
+ p. Savon lets you call SOAP actions using snake_case, because even though they will propably be written in lowerCamelCase or CamelCase, it just feels much more natural.
28
22
 
29
- p. Find out more about the "WSDL":http://wiki.github.com/rubiii/savon/wsdl object.
23
+ h3. The WSDL object
30
24
 
31
- h2. Calling a SOAP action
25
+ p. Savon::WSDL represents the WSDL of your service, including information like the namespace URI and available SOAP actions.
32
26
 
33
- p. Now, assuming your service applies to the default "Options":http://wiki.github.com/rubiii/savon/options, you can just call any available SOAP action.
27
+ bc. client.wsdl.soap_actions.keys
28
+ => [:get_all_users, :get_user_by_id, :user_magic]
34
29
 
35
- bc. response = proxy.get_all_users
30
+ p. More information: "WSDL":http://wiki.github.com/rubiii/savon/wsdl
36
31
 
37
- p. Savon lets you call SOAP actions using snake_case, because even though they will propably be written in lowerCamelCase or CamelCase, it just feels much more natural.
32
+ h3. The SOAP object
38
33
 
39
- h2. Parameters
34
+ p. Savon::SOAP represents the SOAP request. Pass a block to your SOAP call and the SOAP object is passed to it as the first argument. The object allows setting the SOAP version, header, body and namespaces per request.
40
35
 
41
- p. Specifying parameters for the SOAP service, can be done by simply passing a Hash to the SOAP action.
36
+ bc. response = client.get_user_by_id { |soap| soap.body = { :id => 666 } }
42
37
 
43
- bc. response = proxy.get_user_by_id :id => 666
38
+ p. More information: "SOAP":http://wiki.github.com/rubiii/savon/soap
44
39
 
45
- p. Learn more about [[Parameters]].
40
+ h3. The WSSE object
46
41
 
47
- h2. The response
42
+ p. Savon::WSSE represents WSSE authentication. Pass a block to your SOAP call and the WSSE object is passed to it as the second argument. The object allows setting the WSSE username, password and whether to use digest authentication.
48
43
 
49
- p. By default, the SOAP response is translated into a Hash. Take a look at the "Options":http://wiki.github.com/rubiii/savon/options for more information.
44
+ bc. response = client.get_user_by_id do |soap, wsse|
45
+ wsse.username = "gorilla"
46
+ wsse.password = "secret"
47
+ soap.body = { :id => 666 }
48
+ end
50
49
 
51
- bc. proxy.get_user_by_id :id => 666
52
- => { :user_response => { :id => "666", :username => "gorilla" } }
50
+ p. More information: "WSSE":http://wiki.github.com/rubiii/savon/wsse
53
51
 
54
- h2. HTTP errors and SOAP faults
52
+ h3. The Response object
55
53
 
56
- p. Savon raises a Savon::SOAPFault in case of a SOAP fault and a Savon::HTTPError in case of an HTTP error. More information about "Errors":http://wiki.github.com/rubiii/savon/errors.
54
+ p. Savon::Response represents the HTTP and SOAP response. It contains and raises errors in case of an HTTP error or SOAP fault (unless disabled). Also you can get the response as XML (for parsing it with an XML library) or translated into a Hash.
55
+ More information: "Response":http://wiki.github.com/rubiii/savon/response
57
56
 
58
- h2. Logging
57
+ h3. HTTP errors and SOAP faults
59
58
 
60
- p. By default Savon logs each request and response to STDOUT. Specifying your own logger is as easy as it gets:
59
+ p. Savon raises a Savon::SOAPFault in case of a SOAP fault and a Savon::HTTPError in case of an HTTP error.
60
+ More information: "Errors":http://wiki.github.com/rubiii/savon/errors
61
61
 
62
- bc. Savon::Request.logger = RAILS_DEFAULT_LOGGER
62
+ h3. Logging
63
63
 
64
- Read more about "Logging":http://wiki.github.com/rubiii/savon/logging.
64
+ p. Savon logs each request and response to STDOUT. But there are a couple of options to change the default behaviour.
65
+ More information: "Logging":http://wiki.github.com/rubiii/savon/logging
65
66
 
66
- h2. RDoc and Wiki
67
+ h3. Documentation
67
68
 
68
- p. Further information: "Wiki":http://wiki.github.com/rubiii/savon and "RDoc":http://rdoc.info/projects/rubiii/savon
69
+ p. Wiki: "wiki.github.com/rubiii/savon":http://wiki.github.com/rubiii/savon
70
+ RDoc: "rdoc.info/projects/rubiii/savon":http://rdoc.info/projects/rubiii/savon
data/Rakefile CHANGED
File without changes
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.3
data/lib/savon/client.rb CHANGED
@@ -6,14 +6,27 @@ module Savon
6
6
  # with SOAP services and XML.
7
7
  class Client
8
8
 
9
+ # Defines whether to use Savon::WSDL.
10
+ @wsdl = true
11
+
12
+ class << self
13
+ # Accessor for whether to use Savon::WSDL.
14
+ attr_accessor :wsdl
15
+ end
16
+
9
17
  # Expects a SOAP +endpoint+ String.
10
18
  def initialize(endpoint)
11
19
  @request = Request.new endpoint
12
20
  @wsdl = WSDL.new @request
13
21
  end
14
22
 
15
- # Returns the Savon::WSDL.
16
- attr_reader :wsdl
23
+ # Accessor for Savon::WSDL.
24
+ attr_accessor :wsdl
25
+
26
+ # Returns whether to use Savon::WSDL.
27
+ def wsdl?
28
+ self.class.wsdl && @wsdl
29
+ end
17
30
 
18
31
  # Returns +true+ for available methods and SOAP actions.
19
32
  def respond_to?(method)
@@ -25,7 +38,7 @@ module Savon
25
38
 
26
39
  # Dispatches requests to SOAP actions matching a given +method+ name.
27
40
  def method_missing(method, *args, &block) #:doc:
28
- super unless @wsdl.respond_to? method
41
+ super if wsdl? && !@wsdl.respond_to?(method)
29
42
 
30
43
  setup method, &block
31
44
  dispatch method
@@ -34,12 +47,12 @@ module Savon
34
47
  # Expects a SOAP action and sets up Savon::SOAP and Savon::WSSE.
35
48
  # Yields them to a given +block+ in case one was given.
36
49
  def setup(soap_action, &block)
37
- @soap = SOAP.new @wsdl.soap_actions[soap_action]
50
+ @soap = SOAP.new(wsdl? ? @wsdl.soap_actions[soap_action] : nil)
38
51
  @wsse = WSSE.new
39
52
 
40
53
  yield_parameters &block if block
41
54
 
42
- @soap.namespaces["xmlns:wsdl"] = @wsdl.namespace_uri
55
+ @soap.namespaces["xmlns:wsdl"] ||= @wsdl.namespace_uri if wsdl?
43
56
  @soap.wsse = @wsse
44
57
  end
45
58
 
File without changes
File without changes
File without changes
@@ -33,7 +33,7 @@ class String
33
33
 
34
34
  # Translates SOAP response values to more convenient Ruby Objects.
35
35
  def map_soap_response
36
- return DateTime.parse self if Savon::SOAPDateTimeRegexp === self
36
+ return DateTime.parse( self ) if Savon::SOAPDateTimeRegexp === self
37
37
  return true if self.strip.downcase == "true"
38
38
  return false if self.strip.downcase == "false"
39
39
  self
File without changes
File without changes
File without changes
data/lib/savon/request.rb CHANGED
@@ -67,7 +67,7 @@ module Savon
67
67
  # Logs the SOAP request.
68
68
  def log_request
69
69
  log "SOAP request: #{@endpoint}"
70
- log http_header.map { |key, value| "#{key}: #{value}" }.join ", "
70
+ log http_header.map { |key, value| "#{key}: #{value}" }.join( ", " )
71
71
  log @soap.to_xml
72
72
  end
73
73
 
@@ -100,7 +100,7 @@ module Savon
100
100
  def handle_http_error
101
101
  if @response.code.to_i >= 300
102
102
  @http_error = "#{@response.message} (#{@response.code})"
103
- @http_error += ": #{@response.body}" unless @response.body.empty?
103
+ @http_error << ": #{@response.body}" unless @response.body.empty?
104
104
  raise Savon::HTTPError, http_error if self.class.raise_errors?
105
105
  end
106
106
  end
data/lib/savon/soap.rb CHANGED
@@ -29,10 +29,10 @@ module Savon
29
29
 
30
30
  end
31
31
 
32
- # Expects an +action_map+ containing the name of the SOAP action and input.
33
- def initialize(action_map)
34
- @action = action_map[:name]
35
- @input = action_map[:input]
32
+ # Expects a Hash containing the name of the SOAP action and input.
33
+ def initialize(action = nil)
34
+ @action = action.kind_of?(Hash) ? action[:name] : ""
35
+ @input = action.kind_of?(Hash) ? action[:input] : ""
36
36
  end
37
37
 
38
38
  # Sets the WSSE options.
@@ -41,6 +41,9 @@ module Savon
41
41
  # Accessor for the SOAP action.
42
42
  attr_accessor :action
43
43
 
44
+ # Accessor for the SOAP input.
45
+ attr_writer :input
46
+
44
47
  # Sets the SOAP header. Expected to be a Hash that can be translated
45
48
  # to XML via Hash.to_soap_xml or any other Object responding to to_s.
46
49
  attr_writer :header
@@ -84,7 +87,7 @@ module Savon
84
87
  xml << (header.to_soap_xml rescue header.to_s) + wsse_header
85
88
  end
86
89
  xml.env(:Body) do
87
- xml.wsdl(@input.to_sym) do
90
+ xml.tag!(:wsdl, *input_array) do
88
91
  xml << (@body.to_soap_xml rescue @body.to_s)
89
92
  end
90
93
  end
@@ -95,6 +98,15 @@ module Savon
95
98
 
96
99
  private
97
100
 
101
+ # Returns an Array of SOAP input names to append to the :wsdl namespace.
102
+ # Defaults to use the name of the SOAP action and may be an empty Array
103
+ # in case the specified SOAP input seems invalid.
104
+ def input_array
105
+ return [@input.to_sym] if @input && !@input.empty?
106
+ return [@action.to_sym] if @action && !@action.empty?
107
+ []
108
+ end
109
+
98
110
  # Returns the WSSE header or an empty String in case WSSE was not set.
99
111
  def wsse_header
100
112
  return "" unless @wsse.respond_to? :header
data/lib/savon/wsdl.rb CHANGED
@@ -12,7 +12,7 @@ module Savon
12
12
 
13
13
  # Returns the namespace URI from the WSDL.
14
14
  def namespace_uri
15
- @namespace_uri ||= parse_namespace_uri
15
+ @namespace_uri ||= document.root.attributes["targetNamespace"] || ""
16
16
  end
17
17
 
18
18
  # Returns a Hash of available SOAP actions mapped to snake_case (keys)
@@ -51,19 +51,13 @@ module Savon
51
51
  @document ||= REXML::Document.new wsdl_response.body
52
52
  end
53
53
 
54
- # Parses the WSDL for the namespace URI.
55
- def parse_namespace_uri
56
- definitions = document.elements["//wsdl:definitions"]
57
- definitions.attributes["targetNamespace"] if definitions
58
- end
59
-
60
54
  # Parses the WSDL for available SOAP actions and inputs. Returns a Hash
61
55
  # containing the SOAP action inputs and corresponding SOAP actions.
62
56
  def parse_soap_operations
63
- wsdl_binding = document.elements["//wsdl:binding"]
57
+ wsdl_binding = document.elements["wsdl:definitions/wsdl:binding"]
64
58
  return {} unless wsdl_binding
65
59
 
66
- wsdl_binding.elements.inject("//wsdl:operation", {}) do |hash, operation|
60
+ wsdl_binding.elements.inject("wsdl:operation", {}) do |hash, operation|
67
61
  action = operation.elements["*:operation"].attributes["soapAction"] || ""
68
62
  action = operation.attributes["name"] if action.empty?
69
63
 
data/lib/savon/wsse.rb CHANGED
@@ -12,10 +12,10 @@ module Savon
12
12
  WSUNamespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
13
13
 
14
14
  # Default WSSE username.
15
- @username = ""
15
+ @username = nil
16
16
 
17
17
  # Default WSSE password.
18
- @password = ""
18
+ @password = nil
19
19
 
20
20
  # Default for whether to use WSSE digest.
21
21
  @digest = false
@@ -28,6 +28,7 @@ module Savon
28
28
  # Sets the default WSSE username.
29
29
  def username=(username)
30
30
  @username = username.to_s if username.respond_to? :to_s
31
+ @username = nil if username.nil?
31
32
  end
32
33
 
33
34
  # Returns the default WSSE password.
@@ -36,6 +37,7 @@ module Savon
36
37
  # Sets the default WSSE password.
37
38
  def password=(password)
38
39
  @password = password.to_s if password.respond_to? :to_s
40
+ @password = nil if password.nil?
39
41
  end
40
42
 
41
43
  # Sets whether to use WSSE digest by default.
@@ -51,6 +53,7 @@ module Savon
51
53
  # Sets the WSSE username.
52
54
  def username=(username)
53
55
  @username = username.to_s if username.respond_to? :to_s
56
+ @username = nil if username.nil?
54
57
  end
55
58
 
56
59
  # Returns the WSSE username. Defaults to the global default.
@@ -61,6 +64,7 @@ module Savon
61
64
  # Sets the WSSE password.
62
65
  def password=(password)
63
66
  @password = password.to_s if password.respond_to? :to_s
67
+ @password = nil if password.nil?
64
68
  end
65
69
 
66
70
  # Returns the WSSE password. Defaults to the global default.
data/lib/savon.rb CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/spec/http_stubs.rb CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -60,6 +60,12 @@ describe Savon::SOAP do
60
60
  end
61
61
  end
62
62
 
63
+ describe "input" do
64
+ it "sets the name of the SOAP input node" do
65
+ @soap.input = "FindUserRequest"
66
+ end
67
+ end
68
+
63
69
  describe "header" do
64
70
  it "is an accessor for the SOAP header" do
65
71
  @soap.header.should be_a Hash
@@ -137,4 +143,4 @@ describe Savon::SOAP do
137
143
  end
138
144
  end
139
145
 
140
- end
146
+ end
File without changes
@@ -2,9 +2,12 @@ require "spec_helper"
2
2
 
3
3
  describe Savon::WSSE do
4
4
  before do
5
+ Savon::WSSE.username = nil
6
+ Savon::WSSE.password = nil
7
+ Savon::WSSE.digest = false
8
+
5
9
  @wsse = Savon::WSSE.new
6
- @username = "gorilla"
7
- @password = "secret"
10
+ @username, @password = "gorilla", "secret"
8
11
  end
9
12
 
10
13
  describe "WSENamespace" do
@@ -22,28 +25,24 @@ describe Savon::WSSE do
22
25
  end
23
26
 
24
27
  describe "@username" do
25
- it "defaults to an empty String" do
26
- Savon::WSSE.username.should be_a String
27
- Savon::WSSE.username.should be_empty
28
+ it "defaults to nil" do
29
+ Savon::WSSE.username.should be_nil
28
30
  end
29
31
 
30
32
  it "has accessor methods" do
31
33
  Savon::WSSE.username = "gorilla"
32
34
  Savon::WSSE.username.should == "gorilla"
33
- Savon::WSSE.username = ""
34
35
  end
35
36
  end
36
37
 
37
38
  describe "@password" do
38
- it "defaults to an empty String" do
39
- Savon::WSSE.password.should be_a String
40
- Savon::WSSE.password.should be_empty
39
+ it "defaults to nil" do
40
+ Savon::WSSE.password.should be_nil
41
41
  end
42
42
 
43
43
  it "has accessor methods" do
44
44
  Savon::WSSE.password = "secret"
45
45
  Savon::WSSE.password.should == "secret"
46
- Savon::WSSE.password = ""
47
46
  end
48
47
  end
49
48
 
@@ -55,33 +54,28 @@ describe Savon::WSSE do
55
54
  it "has accessor methods" do
56
55
  Savon::WSSE.digest = true
57
56
  Savon::WSSE.digest?.should == true
58
- Savon::WSSE.digest = false
59
57
  end
60
58
  end
61
59
 
62
60
  describe "username" do
63
- it "defaults to an empty String" do
64
- @wsse.username.should be_a String
65
- @wsse.username.should be_empty
61
+ it "defaults to nil" do
62
+ @wsse.username.should be_nil
66
63
  end
67
64
 
68
65
  it "has accessor methods" do
69
66
  @wsse.username = "gorilla"
70
67
  @wsse.username.should == "gorilla"
71
- @wsse.username = nil
72
68
  end
73
69
  end
74
70
 
75
71
  describe "password" do
76
- it "defaults to an empty String" do
77
- @wsse.password.should be_a String
78
- @wsse.password.should be_empty
72
+ it "defaults to nil" do
73
+ @wsse.password.should be_nil
79
74
  end
80
75
 
81
76
  it "has accessor methods" do
82
77
  @wsse.password = "secret"
83
78
  @wsse.password.should == "secret"
84
- @wsse.password = nil
85
79
  end
86
80
  end
87
81
 
@@ -93,7 +87,6 @@ describe Savon::WSSE do
93
87
  it "has accessor methods" do
94
88
  @wsse.digest = true
95
89
  @wsse.digest?.should == true
96
- @wsse.digest = false
97
90
  end
98
91
  end
99
92
 
@@ -117,9 +110,6 @@ describe Savon::WSSE do
117
110
  header.should include_security_namespaces
118
111
  header.should include @username
119
112
  header.should include @password
120
-
121
- Savon::WSSE.username = ""
122
- Savon::WSSE.password = ""
123
113
  end
124
114
  end
125
115
 
@@ -155,4 +145,4 @@ describe Savon::WSSE do
155
145
  end
156
146
  end
157
147
 
158
- end
148
+ end
data/spec/spec_helper.rb CHANGED
File without changes
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: savon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Harrington
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-06 00:00:00 +01:00
12
+ date: 2009-12-11 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -71,6 +71,7 @@ extensions: []
71
71
  extra_rdoc_files:
72
72
  - README.textile
73
73
  files:
74
+ - CHANGELOG
74
75
  - README.textile
75
76
  - Rakefile
76
77
  - VERSION
@@ -142,20 +143,20 @@ signing_key:
142
143
  specification_version: 3
143
144
  summary: Heavy metal Ruby SOAP client library
144
145
  test_files:
145
- - spec/fixtures/user_fixture.rb
146
- - spec/http_stubs.rb
146
+ - spec/spec_helper.rb
147
+ - spec/savon/response_spec.rb
148
+ - spec/savon/savon_spec.rb
149
+ - spec/savon/wsdl_spec.rb
150
+ - spec/savon/request_spec.rb
147
151
  - spec/savon/client_spec.rb
148
- - spec/savon/core_ext/datetime_spec.rb
152
+ - spec/savon/soap_spec.rb
153
+ - spec/savon/core_ext/symbol_spec.rb
149
154
  - spec/savon/core_ext/hash_spec.rb
150
- - spec/savon/core_ext/object_spec.rb
151
155
  - spec/savon/core_ext/string_spec.rb
152
- - spec/savon/core_ext/symbol_spec.rb
156
+ - spec/savon/core_ext/datetime_spec.rb
157
+ - spec/savon/core_ext/object_spec.rb
153
158
  - spec/savon/core_ext/uri_spec.rb
154
- - spec/savon/request_spec.rb
155
- - spec/savon/response_spec.rb
156
- - spec/savon/savon_spec.rb
157
- - spec/savon/soap_spec.rb
158
- - spec/savon/wsdl_spec.rb
159
159
  - spec/savon/wsse_spec.rb
160
- - spec/spec_helper.rb
161
160
  - spec/spec_helper_methods.rb
161
+ - spec/http_stubs.rb
162
+ - spec/fixtures/user_fixture.rb