smacks-savon 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/lib/savon/mash.rb +61 -0
- data/lib/savon/response.rb +8 -7
- data/lib/savon/service.rb +34 -21
- data/lib/savon/wsdl.rb +5 -2
- data/{tests → test}/factories/wsdl.rb +0 -0
- data/{tests → test}/fixtures/soap_response.rb +0 -0
- data/{tests → test}/helper.rb +0 -0
- data/{tests → test}/savon/mash_test.rb +0 -0
- data/{tests → test}/savon/response_test.rb +0 -0
- data/{tests → test}/savon/service_test.rb +0 -0
- data/{tests → test}/savon/wsdl_test.rb +8 -0
- data/{tests → test}/savon_test.rb +0 -0
- metadata +11 -10
data/README.rdoc
CHANGED
@@ -9,12 +9,12 @@ service method to receive.
|
|
9
9
|
|
10
10
|
== Install
|
11
11
|
|
12
|
-
$ gem install smacks-savon
|
12
|
+
$ gem install smacks-savon -s http://gems.github.com
|
13
13
|
|
14
14
|
== Dependencies
|
15
15
|
|
16
16
|
hpricot 0.6.164 (also available for JRuby)
|
17
|
-
smacks-apricoteatsgorilla >= 0.3.
|
17
|
+
smacks-apricoteatsgorilla >= 0.3.5
|
18
18
|
|
19
19
|
== How to use
|
20
20
|
|
data/lib/savon/mash.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module Savon
|
2
|
+
|
3
|
+
# Savon::Mash converts a given Hash into an Object.
|
4
|
+
class Mash
|
5
|
+
|
6
|
+
# Loops through a given +hash+, stores each value in an instance variable
|
7
|
+
# and creates getter and setter methods.
|
8
|
+
#
|
9
|
+
# === Parameters
|
10
|
+
#
|
11
|
+
# * +hash+ - The Hash to convert.
|
12
|
+
def initialize(hash)
|
13
|
+
hash.each do |key,value|
|
14
|
+
value = Savon::Mash.new(value) if value.is_a? Hash
|
15
|
+
|
16
|
+
if value.is_a? Array
|
17
|
+
value = value.map do |item|
|
18
|
+
if item.is_a?(Hash) then Savon::Mash.new(item) else item end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
set_instance_variable key, value
|
23
|
+
define_reader key
|
24
|
+
define_writer key
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# Sets and instance variable with a given +name+ and +value+.
|
31
|
+
#
|
32
|
+
# === Parameters
|
33
|
+
#
|
34
|
+
# * +name+ - Name of the instance variable.
|
35
|
+
# * +value+ - Value of the instance variable.
|
36
|
+
def set_instance_variable(name, value)
|
37
|
+
self.instance_variable_set("@#{name}", value)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Defines a reader method for a given instance +variable+.
|
41
|
+
#
|
42
|
+
# === Parameters
|
43
|
+
#
|
44
|
+
# * +variable+ - Name of the instance variable.
|
45
|
+
def define_reader(variable)
|
46
|
+
method = proc { self.instance_variable_get("@#{variable}") }
|
47
|
+
self.class.send(:define_method, variable, method)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Defines a writer method for a given instance +variable+.
|
51
|
+
#
|
52
|
+
# === Parameters
|
53
|
+
#
|
54
|
+
# * +variable+ - Name of the instance variable.
|
55
|
+
def define_writer(variable)
|
56
|
+
method = proc { |value| self.instance_variable_set("@#{variable}", value) }
|
57
|
+
self.class.send(:define_method, "#{variable}=", method)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
data/lib/savon/response.rb
CHANGED
@@ -32,11 +32,13 @@ module Savon
|
|
32
32
|
#
|
33
33
|
# # response as a Mash starting at a custom root node (via XPath)
|
34
34
|
# response.to_mash("//user/email")
|
35
|
-
#
|
36
|
-
# ===
|
37
35
|
class Response
|
38
36
|
|
39
|
-
|
37
|
+
# The HTTP/SOAP fault.
|
38
|
+
attr_reader :fault
|
39
|
+
|
40
|
+
# The HTTP/SOAP fault code.
|
41
|
+
attr_reader :fault_code
|
40
42
|
|
41
43
|
# Initializer to set the SOAP response.
|
42
44
|
#
|
@@ -55,7 +57,7 @@ module Savon
|
|
55
57
|
|
56
58
|
# Returns true if the request was not successful, false otherwise.
|
57
59
|
def fault?
|
58
|
-
!@
|
60
|
+
!@fault_code.nil?
|
59
61
|
end
|
60
62
|
|
61
63
|
# Returns the SOAP response message as a Hash. Call with XPath expession
|
@@ -90,11 +92,10 @@ module Savon
|
|
90
92
|
|
91
93
|
private
|
92
94
|
|
93
|
-
# Checks for and stores HTTP and SOAP
|
95
|
+
# Checks for and stores HTTP and SOAP fault errors.
|
94
96
|
def validate
|
95
97
|
if @response.code.to_i >= 300
|
96
|
-
@fault = @response.message
|
97
|
-
@fault_code = @response.code
|
98
|
+
@fault, @fault_code = @response.message, @response.code
|
98
99
|
else
|
99
100
|
fault = to_hash("//soap:Fault")
|
100
101
|
@fault = fault[:faultstring] unless fault.nil?
|
data/lib/savon/service.rb
CHANGED
@@ -40,6 +40,9 @@ module Savon
|
|
40
40
|
# response.to_mash("//user/email")
|
41
41
|
class Service
|
42
42
|
|
43
|
+
# The logger to use.
|
44
|
+
@@logger = nil
|
45
|
+
|
43
46
|
# The Net::HTTP connection instance to use.
|
44
47
|
attr_writer :http
|
45
48
|
|
@@ -58,15 +61,35 @@ module Savon
|
|
58
61
|
@wsdl
|
59
62
|
end
|
60
63
|
|
64
|
+
# Sets the logger to use.
|
65
|
+
def self.logger=(logger)
|
66
|
+
@@logger = logger
|
67
|
+
end
|
68
|
+
|
61
69
|
private
|
62
70
|
|
63
71
|
# Prepares and processes the SOAP request. Returns a Savon::Response object.
|
64
72
|
def call_service
|
65
73
|
headers = { "Content-Type" => "text/xml; charset=utf-8", "SOAPAction" => @action }
|
74
|
+
|
75
|
+
ApricotEatsGorilla.setup do |s|
|
76
|
+
s.nodes_to_namespace = wsdl.choice_elements
|
77
|
+
s.node_namespace = "wsdl"
|
78
|
+
end
|
66
79
|
body = ApricotEatsGorilla.soap_envelope("wsdl" => wsdl.namespace_uri) do
|
67
|
-
ApricotEatsGorilla["wsdl:#{@action}" =>
|
80
|
+
ApricotEatsGorilla["wsdl:#{@action}" => @options]
|
81
|
+
end
|
82
|
+
|
83
|
+
debug do |logger|
|
84
|
+
logger.info "Request; #{@uri}"
|
85
|
+
logger.info headers.map { |key, value| "#{key}: #{value}" }.join("\n")
|
86
|
+
logger.info body
|
68
87
|
end
|
69
88
|
response = @http.request_post(@uri.path, body, headers)
|
89
|
+
debug do |logger|
|
90
|
+
logger.info "Response (Status #{response.code}):"
|
91
|
+
logger.info response.body
|
92
|
+
end
|
70
93
|
Savon::Response.new(response)
|
71
94
|
end
|
72
95
|
|
@@ -87,26 +110,17 @@ module Savon
|
|
87
110
|
end
|
88
111
|
end
|
89
112
|
|
90
|
-
#
|
91
|
-
# the
|
92
|
-
def
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
current = options[key]
|
100
|
-
case current
|
101
|
-
when Array
|
102
|
-
options[key] << value
|
103
|
-
when nil
|
104
|
-
options[key] = value
|
105
|
-
else
|
106
|
-
options[key] = [current.dup, value]
|
113
|
+
# Debug method. Outputs a given +message+ to the defined @@logger or
|
114
|
+
# yields the @@logger to a +block+ in case one was given.
|
115
|
+
def debug(message = nil)
|
116
|
+
if @@logger
|
117
|
+
if message
|
118
|
+
@@logger.info(message)
|
119
|
+
end
|
120
|
+
if block_given?
|
121
|
+
yield @@logger
|
107
122
|
end
|
108
123
|
end
|
109
|
-
options
|
110
124
|
end
|
111
125
|
|
112
126
|
# Intercepts calls to SOAP service methods.
|
@@ -116,8 +130,7 @@ module Savon
|
|
116
130
|
# * +method+ - The SOAP service method to call.
|
117
131
|
# * +options+ - Hash of options for the service method to receive.
|
118
132
|
def method_missing(method, options = {})
|
119
|
-
@action = method.to_s
|
120
|
-
@options = options
|
133
|
+
@action, @options = method.to_s, options
|
121
134
|
validate_action
|
122
135
|
call_service
|
123
136
|
end
|
data/lib/savon/wsdl.rb
CHANGED
@@ -24,8 +24,7 @@ module Savon
|
|
24
24
|
# * +uri+ - The URI to access.
|
25
25
|
# * +http+ - The Net::HTTP connection instance to use.
|
26
26
|
def initialize(uri, http)
|
27
|
-
@uri = uri
|
28
|
-
@http = http
|
27
|
+
@uri, @http = uri, http
|
29
28
|
get_wsdl
|
30
29
|
|
31
30
|
parse_namespace_uri
|
@@ -44,6 +43,10 @@ module Savon
|
|
44
43
|
def get_wsdl
|
45
44
|
@response = @http.get("#{@uri.path}?#{@uri.query}")
|
46
45
|
@doc = Hpricot.XML(@response.body)
|
46
|
+
|
47
|
+
if !@doc.at("//wsdl:definitions")
|
48
|
+
raise ArgumentError, "Unable to find WSDL at given endpoint URI."
|
49
|
+
end
|
47
50
|
end
|
48
51
|
|
49
52
|
# Parses the WSDL to find and store the namespace URI.
|
File without changes
|
File without changes
|
data/{tests → test}/helper.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -41,4 +41,12 @@ class SavonWsdlTest < Test::Unit::TestCase
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
context "Savon::Wsdl with an invalid (non-WSDL) response" do
|
45
|
+
should "raise an ArgumentError" do
|
46
|
+
assert_raise ArgumentError do
|
47
|
+
Savon::Wsdl.new(some_uri, http_mock("Non-WSDL response"))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
44
52
|
end
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smacks-savon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Harrington
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.3.
|
33
|
+
version: 0.3.8
|
34
34
|
version:
|
35
35
|
description: Savon is a lightweight SOAP client.
|
36
36
|
email:
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- lib/savon/service.rb
|
47
47
|
- lib/savon/wsdl.rb
|
48
48
|
- lib/savon/response.rb
|
49
|
+
- lib/savon/mash.rb
|
49
50
|
has_rdoc: true
|
50
51
|
homepage: http://github.com/smacks/savon
|
51
52
|
post_install_message:
|
@@ -74,11 +75,11 @@ signing_key:
|
|
74
75
|
specification_version: 2
|
75
76
|
summary: Savon is a lightweight SOAP client.
|
76
77
|
test_files:
|
77
|
-
-
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
81
|
-
-
|
82
|
-
-
|
83
|
-
-
|
84
|
-
-
|
78
|
+
- test/savon_test.rb
|
79
|
+
- test/helper.rb
|
80
|
+
- test/factories/wsdl.rb
|
81
|
+
- test/fixtures/soap_response.rb
|
82
|
+
- test/savon/service_test.rb
|
83
|
+
- test/savon/response_test.rb
|
84
|
+
- test/savon/wsdl_test.rb
|
85
|
+
- test/savon/mash_test.rb
|