smacks-apricoteatsgorilla 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.5.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{apricoteatsgorilla}
8
- s.version = "0.5.1"
8
+ s.version = "0.5.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Harrington"]
12
- s.date = %q{2009-08-29}
12
+ s.date = %q{2009-08-30}
13
13
  s.description = %q{SOAP communication helper.}
14
14
  s.email = %q{me@d-harrington.com}
15
15
  s.extra_rdoc_files = [
@@ -22,7 +22,8 @@ class ApricotEatsGorilla
22
22
  # Flag to disable conversion of Hash keys to Symbols.
23
23
  attr_accessor :disable_hash_keys_to_symbols
24
24
 
25
- # Hash of namespaces and XML nodes to apply these namespaces to.
25
+ # Hash of namespaces (keys) and XML nodes (values) to apply these
26
+ # namespaces to.
26
27
  attr_accessor :nodes_to_namespace
27
28
 
28
29
  # Shortcut method for translating between XML Strings and Ruby Hashes.
@@ -39,7 +40,8 @@ class ApricotEatsGorilla
39
40
  end
40
41
  end
41
42
 
42
- # Yields this class in case a +block+ was given.
43
+ # Yields this class to a given +block+ for wrapping the setup of multiple
44
+ # flags at once.
43
45
  def setup
44
46
  yield self if block_given?
45
47
  end
@@ -50,9 +52,10 @@ class ApricotEatsGorilla
50
52
  # +root_node+ parameter for defining a custom root node to start parsing
51
53
  # at using an XPath-Expression (Hpricot search).
52
54
  #
53
- # Notice that the root node itself won't be included in the Hash.
55
+ # Notice that both namespaces and attributes get removed and the root node
56
+ # itself won't be included in the Hash.
54
57
  #
55
- # ==== Example
58
+ # ==== Examples
56
59
  #
57
60
  # xml = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
58
61
  # <soap:Body>
@@ -66,13 +69,16 @@ class ApricotEatsGorilla
66
69
  # </soap:Body>
67
70
  # </soap:Envelope>'
68
71
  #
72
+ # ApricotEatsGorilla.xml_to_hash(xml)
73
+ # # => { :body => { :authenticate_response => { :return => { :apricot => { :eats => "Gorilla" } } } } }
74
+ #
69
75
  # ApricotEatsGorilla.xml_to_hash(xml, "//return")
70
76
  # # => { :apricot => { :eats => "Gorilla" } }
71
77
  def xml_to_hash(xml, root_node = nil)
72
78
  doc = Hpricot.XML remove_whitespace(xml)
73
79
  root = root_node ? doc.search(root_node) : doc.root
74
80
 
75
- return nil if root.nil?
81
+ return nil if root.nil? || (root.respond_to?(:size) && root.size == 0)
76
82
  if !root.respond_to? :each
77
83
  xml_node_to_hash(root)
78
84
  elsif root.size == 1
@@ -84,20 +90,26 @@ class ApricotEatsGorilla
84
90
 
85
91
  # Translates a given Ruby +hash+ into an XML String.
86
92
  #
87
- # ==== Example
93
+ # ==== Examples
88
94
  #
89
95
  # hash = { :apricot => { :eats => "Gorilla" } }
90
- #
91
96
  # ApricotEatsGorilla.hash_to_xml(hash)
97
+ #
92
98
  # # => "<apricot><eats>Gorilla</eats></apricot>"
99
+ #
100
+ # hash = { :apricot => { :eats => ["Gorillas", "Snakes"] } }
101
+ # ApricotEatsGorilla.hash_to_xml(hash)
102
+ #
103
+ # # => "<apricot><eats>Gorillas</eats><eats>Snakes</eats></apricot>"
93
104
  def hash_to_xml(hash)
94
105
  nested_data_to_xml(hash.keys.first, hash.values.first)
95
106
  end
96
107
 
97
- # Builds a SOAP request envelope and includes the content from a given
98
- # +block+ into the envelope body. Accepts a Hash of +namespaces+ to set.
108
+ # Builds a SOAP request envelope and includes the content of a given
109
+ # +block+ into the envelope body. Accepts a Hash of additional +namespaces+
110
+ # to set.
99
111
  #
100
- # ==== Example
112
+ # ==== Examples
101
113
  #
102
114
  # ApricotEatsGorilla.soap_envelope do
103
115
  # "<apricot><eats>Gorilla</eats></apricot>"
@@ -108,6 +120,14 @@ class ApricotEatsGorilla
108
120
  # # => <apricot><eats>Gorilla</eats></apricot>
109
121
  # # => </env:Body>
110
122
  # # => </env:Envelope>'
123
+ #
124
+ # ApricotEatsGorilla.soap_envelope(:wsdl => "http://example.com") { "pureText" }
125
+ #
126
+ # # => '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://example.com">
127
+ # # => <env:Body>
128
+ # # => pureText
129
+ # # => </env:Body>
130
+ # # => </env:Envelope>'
111
131
  def soap_envelope(namespaces = {})
112
132
  namespaces[:env] = "http://schemas.xmlsoap.org/soap/envelope/"
113
133
 
@@ -1,13 +1,13 @@
1
1
  # == XMLNode
2
2
  #
3
3
  # Representation of an XML node. Inherits from String and includes some
4
- # useful methods for namespaces, attributes, body content etc.
4
+ # useful XML-specific methods for namespaces, attributes, node content etc.
5
5
  class XMLNode < String
6
6
 
7
7
  # Hash of attributes.
8
8
  attr_writer :attributes
9
9
 
10
- # Body content.
10
+ # Node body content.
11
11
  attr_writer :body
12
12
 
13
13
  # Strips the namespace from this node.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smacks-apricoteatsgorilla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
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-08-29 00:00:00 -07:00
12
+ date: 2009-08-30 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency