smacks-savon 0.0.75 → 0.0.91

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -9,7 +9,7 @@ service method to receive.
9
9
 
10
10
  == Install
11
11
 
12
- $ gem install smacks-savon --s http://gems.github.com
12
+ $ gem install smacks-savon -s http://gems.github.com
13
13
 
14
14
  == Dependencies
15
15
 
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/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}" => namespaced_options]
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
- # Checks if there were any choice elements found in the WSDL and namespaces
91
- # the corresponding keys from the passed in Hash of options.
92
- def namespaced_options
93
- return @options if wsdl.choice_elements.empty?
94
-
95
- options = {}
96
- @options.each do |key, value|
97
- key = "wsdl:#{key}" if wsdl.choice_elements.include? key.to_s
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.
@@ -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
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.75
4
+ version: 0.0.91
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.5
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: