shapewear 0.1.5 → 0.1.7
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.md +4 -0
- data/lib/shapewear.rb +10 -10
- data/lib/shapewear/request.rb +25 -4
- data/lib/shapewear/version.rb +1 -1
- data/lib/shapewear/wsdl.rb +1 -1
- metadata +3 -3
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.1.7
|
4
|
+
* Better key lookup on hashes.
|
5
|
+
* Changed #camelize to work the same way as in Rails.
|
6
|
+
|
3
7
|
## 0.1.5
|
4
8
|
* #camelize in parameters and complex types is only called if they are declared as symbols.
|
5
9
|
This allows usage of custom character casing when writing the SOAP services.
|
data/lib/shapewear.rb
CHANGED
@@ -27,18 +27,18 @@ end
|
|
27
27
|
# defines String.camelize and String.underscore, if it is not defined by, e.g. Rails
|
28
28
|
class String
|
29
29
|
unless ''.respond_to? :camelize
|
30
|
-
def camelize(
|
31
|
-
if
|
32
|
-
self.
|
30
|
+
def camelize(first_letter = :upper)
|
31
|
+
if first_letter == :upper
|
32
|
+
self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
33
33
|
else
|
34
|
-
self
|
34
|
+
self[0].chr.downcase + self.camelize[1..-1]
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
unless ''.respond_to? :underscore
|
40
40
|
def underscore
|
41
|
-
word = self.
|
41
|
+
word = self.dup
|
42
42
|
word.gsub!(/::/, '/')
|
43
43
|
word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
44
44
|
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
@@ -50,11 +50,11 @@ class String
|
|
50
50
|
end
|
51
51
|
|
52
52
|
class Object
|
53
|
-
def camelize_if_symbol(
|
54
|
-
if is_a?(Symbol)
|
55
|
-
to_s.camelize(
|
53
|
+
def camelize_if_symbol(first_letter = :upper)
|
54
|
+
if self.is_a?(Symbol)
|
55
|
+
self.to_s.camelize(first_letter)
|
56
56
|
else
|
57
|
-
to_s
|
57
|
+
self.to_s
|
58
58
|
end
|
59
59
|
end
|
60
|
-
end
|
60
|
+
end
|
data/lib/shapewear/request.rb
CHANGED
@@ -67,12 +67,17 @@ module Shapewear::Request
|
|
67
67
|
raise "Operation not found: #{@op_node.name}"
|
68
68
|
end
|
69
69
|
|
70
|
+
# Extracts all parameters from the operation node, and return as an array.
|
71
|
+
#
|
72
|
+
# @param op_options [Hash] The operation options.
|
73
|
+
# @param node [Nokogiri::XML] The operation node.
|
74
|
+
# @return [Array] The parsed parameters.
|
70
75
|
def extract_parameters(op_options, node)
|
71
76
|
logger.debug "Operation node: #{node.inspect}"
|
72
77
|
r = []
|
73
78
|
op_options[:parameters].each do |p|
|
74
|
-
logger.debug " Looking for: tns:#{p.first.camelize_if_symbol(
|
75
|
-
v = node.xpath("tns:#{p.first.camelize_if_symbol(
|
79
|
+
logger.debug " Looking for: tns:#{p.first.camelize_if_symbol(:lower)}"
|
80
|
+
v = node.xpath("tns:#{p.first.camelize_if_symbol(:lower)}", namespaces).first
|
76
81
|
if v.nil?
|
77
82
|
# does nothing
|
78
83
|
elsif p.last == Fixnum
|
@@ -88,6 +93,10 @@ module Shapewear::Request
|
|
88
93
|
r
|
89
94
|
end
|
90
95
|
|
96
|
+
# Serializes the result of an operation as a SOAP Envelope.
|
97
|
+
#
|
98
|
+
# @param op_options [Hash] The operation options.
|
99
|
+
# @param r [Hash,Object] The operation result.
|
91
100
|
#noinspection RubyArgCount
|
92
101
|
def serialize_soap_result(op_options, r)
|
93
102
|
xb = Builder::XmlMarkup.new
|
@@ -96,7 +105,6 @@ module Shapewear::Request
|
|
96
105
|
xb.Envelope :xmlns => soap_env_ns, 'xmlns:xsi' => namespaces['xsi'] do |xenv|
|
97
106
|
xenv.Body do |xbody|
|
98
107
|
xbody.tag! "#{op_options[:public_name]}Response", :xmlns => namespaces['tns'] do |xresp|
|
99
|
-
|
100
108
|
if r.nil?
|
101
109
|
xresp.tag! "#{op_options[:public_name]}Result", 'xsi:nil' => 'true'
|
102
110
|
else
|
@@ -119,9 +127,15 @@ module Shapewear::Request
|
|
119
127
|
end
|
120
128
|
end
|
121
129
|
|
130
|
+
# Extracts a field from an object, casts it to the appropriate type, and serializes as XML.
|
131
|
+
#
|
132
|
+
# @param builder [Builder::XmlMarkup] The XML builder.
|
133
|
+
# @param obj [Hash,Object] The resulting object.
|
134
|
+
# @param field [Symbol,String] The field to extract.
|
135
|
+
# @param type [Class] The type to convert.
|
122
136
|
def extract_and_serialize_value(builder, obj, field, type)
|
123
137
|
v = if obj.is_a?(Hash)
|
124
|
-
obj[field]
|
138
|
+
obj[field] or obj[field.underscore]
|
125
139
|
elsif obj.respond_to?(field)
|
126
140
|
obj.send(field)
|
127
141
|
elsif obj.respond_to?(field.underscore)
|
@@ -137,6 +151,10 @@ module Shapewear::Request
|
|
137
151
|
end
|
138
152
|
end
|
139
153
|
|
154
|
+
# Serializes an exception as a SOAP Envelope containing a SOAP Fault.
|
155
|
+
#
|
156
|
+
# @param ex [Exception] The Exception to serialize.
|
157
|
+
# @return [String] The SOAP Envelope containing the Fault.
|
140
158
|
#noinspection RubyArgCount
|
141
159
|
def serialize_soap_fault(ex)
|
142
160
|
logger.debug "Serializing SOAP Fault: #{ex.inspect}"
|
@@ -167,6 +185,9 @@ module Shapewear::Request
|
|
167
185
|
end
|
168
186
|
end
|
169
187
|
|
188
|
+
# Returns the correct SOAP Envelope namespace.
|
189
|
+
#
|
190
|
+
# @return [String] The correct SOAP Envelope namespace.
|
170
191
|
def soap_env_ns
|
171
192
|
case soap_version
|
172
193
|
when :soap11
|
data/lib/shapewear/version.rb
CHANGED
data/lib/shapewear/wsdl.rb
CHANGED
@@ -92,7 +92,7 @@ module Shapewear::WSDL
|
|
92
92
|
params.each do |p|
|
93
93
|
t = p.last
|
94
94
|
param_name = p.first
|
95
|
-
param_name = param_name.camelize_if_symbol(
|
95
|
+
param_name = param_name.camelize_if_symbol(:lower)
|
96
96
|
if t.nil?
|
97
97
|
xseq.element :name => param_name, :minOccurs => 0, :maxOccurs => 1, :type => 'xsd:any'
|
98
98
|
elsif t.is_a?(Class)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shapewear
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 7
|
10
|
+
version: 0.1.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "F\xC3\xA1bio Batista"
|