shapewear 0.1.4 → 0.1.5
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
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.1.5
|
4
|
+
* #camelize in parameters and complex types is only called if they are declared as symbols.
|
5
|
+
This allows usage of custom character casing when writing the SOAP services.
|
6
|
+
* Parameters are now camelized with first letter as lowercase.
|
7
|
+
|
3
8
|
## 0.1.4
|
4
9
|
* Parameters are now read in the correct order, as specified in the metadata;
|
5
10
|
* Complex return types are now working correctly;
|
data/lib/shapewear.rb
CHANGED
@@ -24,11 +24,37 @@ module Shapewear
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
# defines String.camelize if it is not defined by, e.g. Rails
|
28
|
-
|
29
|
-
|
30
|
-
def camelize
|
31
|
-
|
27
|
+
# defines String.camelize and String.underscore, if it is not defined by, e.g. Rails
|
28
|
+
class String
|
29
|
+
unless ''.respond_to? :camelize
|
30
|
+
def camelize(first_letter_in_uppercase = true)
|
31
|
+
if first_letter_in_uppercase
|
32
|
+
self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
33
|
+
else
|
34
|
+
self.to_s[0].chr.downcase + self.camelize[1..-1]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
unless ''.respond_to? :underscore
|
40
|
+
def underscore
|
41
|
+
word = self.to_s.dup
|
42
|
+
word.gsub!(/::/, '/')
|
43
|
+
word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
44
|
+
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
45
|
+
word.tr!("-", "_")
|
46
|
+
word.downcase!
|
47
|
+
word
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Object
|
53
|
+
def camelize_if_symbol(first_letter_in_uppercase = true)
|
54
|
+
if is_a?(Symbol) then
|
55
|
+
to_s.camelize(first_letter_in_uppercase)
|
56
|
+
else
|
57
|
+
to_s
|
32
58
|
end
|
33
59
|
end
|
34
60
|
end
|
data/lib/shapewear/request.rb
CHANGED
@@ -71,8 +71,8 @@ module Shapewear::Request
|
|
71
71
|
logger.debug "Operation node: #{node.inspect}"
|
72
72
|
r = []
|
73
73
|
op_options[:parameters].each do |p|
|
74
|
-
logger.debug " Looking for: tns:#{p.first.
|
75
|
-
v = node.xpath("tns:#{p.first.
|
74
|
+
logger.debug " Looking for: tns:#{p.first.camelize_if_symbol(false)}"
|
75
|
+
v = node.xpath("tns:#{p.first.camelize_if_symbol(false)}", namespaces).first
|
76
76
|
if v.nil?
|
77
77
|
# does nothing
|
78
78
|
elsif p.last == Fixnum
|
@@ -124,14 +124,16 @@ module Shapewear::Request
|
|
124
124
|
obj[field]
|
125
125
|
elsif obj.respond_to?(field)
|
126
126
|
obj.send(field)
|
127
|
+
elsif obj.respond_to?(field.underscore)
|
128
|
+
obj.send(field.underscore)
|
127
129
|
else
|
128
130
|
raise "Could not extract #{field.inspect} from object: #{obj.inspect}"
|
129
131
|
end
|
130
132
|
|
131
133
|
if v.nil?
|
132
|
-
builder.tag! field.
|
134
|
+
builder.tag! field.camelize_if_symbol, 'xsi:nil' => 'true'
|
133
135
|
else
|
134
|
-
builder.tag! field.
|
136
|
+
builder.tag! field.camelize_if_symbol, v
|
135
137
|
end
|
136
138
|
end
|
137
139
|
|
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.
|
95
|
+
param_name = param_name.camelize_if_symbol(false)
|
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)
|
@@ -135,7 +135,7 @@ module Shapewear::WSDL
|
|
135
135
|
xschema.complexType :name => "#{op_options[:public_name]}Struct" do |xctr|
|
136
136
|
xctr.sequence do |xseqr|
|
137
137
|
ret.each do |name, type|
|
138
|
-
name = name.
|
138
|
+
name = name.camelize_if_symbol
|
139
139
|
xseqr.element :name => name, :minOccurs => 0, :maxOccurs => 1, :type => to_xsd_type(type)
|
140
140
|
end
|
141
141
|
end
|
@@ -16,7 +16,7 @@ describe Shapewear do
|
|
16
16
|
it "should work for simple requests" do
|
17
17
|
client = Savon::Client.new 'http://services.example.com/complete/soap/wsdl'
|
18
18
|
response = client.request :echo_in_uppercase, :xmlns => 'http://services.example.com/v1' do
|
19
|
-
soap.body = {
|
19
|
+
soap.body = { :text => 'uppercase text' }
|
20
20
|
end
|
21
21
|
|
22
22
|
puts response.inspect
|
@@ -28,7 +28,7 @@ describe Shapewear do
|
|
28
28
|
it "should work for structured responses from objects" do
|
29
29
|
client = Savon::Client.new 'http://services.example.com/complete/soap/wsdl'
|
30
30
|
response = client.request :get_structured_data, :xmlns => 'http://services.example.com/v1' do
|
31
|
-
soap.body = { '
|
31
|
+
soap.body = { 'ID' => 0 }
|
32
32
|
end
|
33
33
|
|
34
34
|
r = response.body[:get_structured_data_response][:get_structured_data_result]
|
@@ -39,7 +39,7 @@ describe Shapewear do
|
|
39
39
|
it "should work for structured responses from hashes" do
|
40
40
|
client = Savon::Client.new 'http://services.example.com/complete/soap/wsdl'
|
41
41
|
response = client.request :get_structured_data, :xmlns => 'http://services.example.com/v1' do
|
42
|
-
soap.body = { '
|
42
|
+
soap.body = { 'ID' => 1 }
|
43
43
|
end
|
44
44
|
|
45
45
|
r = response.body[:get_structured_data_response][:get_structured_data_result]
|
@@ -52,7 +52,7 @@ describe Shapewear do
|
|
52
52
|
|
53
53
|
expect {
|
54
54
|
client.request :get_structured_data, :xmlns => 'http://services.example.com/v1' do
|
55
|
-
soap.body = { '
|
55
|
+
soap.body = { 'ID' => 55 }
|
56
56
|
end
|
57
57
|
}.to raise_error Savon::SOAP::Fault, "(e:Server.RuntimeError) ID must be 0 or 1"
|
58
58
|
end
|
@@ -63,7 +63,7 @@ describe Shapewear do
|
|
63
63
|
expect {
|
64
64
|
client.request :get_structured_data, :xmlns => 'http://services.example.com/v1' do
|
65
65
|
soap.version = 2
|
66
|
-
soap.body = { '
|
66
|
+
soap.body = { 'ID' => 55 }
|
67
67
|
end
|
68
68
|
}.to raise_error Savon::SOAP::Fault, "(e:Server.RuntimeError) ID must be 0 or 1"
|
69
69
|
end
|
@@ -17,8 +17,8 @@ class CompleteService
|
|
17
17
|
:returns => Fixnum
|
18
18
|
|
19
19
|
operation :get_structured_data, :documentation => 'Returns structured data. 0 uses a Hash, 1 uses a struct, any other value raises a fault',
|
20
|
-
:parameters => [[
|
21
|
-
:returns => {:text => String, :random_value => Fixnum, :created_at => DateTime}
|
20
|
+
:parameters => [['ID', Fixnum]],
|
21
|
+
:returns => { :text => String, :random_value => Fixnum, :created_at => DateTime, 'XYZ' => String }
|
22
22
|
|
23
23
|
def echo_in_uppercase(text)
|
24
24
|
text.upcase unless text.nil?
|
@@ -33,19 +33,20 @@ class CompleteService
|
|
33
33
|
when 0 then
|
34
34
|
Structured.new('text from the struct')
|
35
35
|
when 1 then
|
36
|
-
{:text => 'text from a hash', :random_value => rand(999),
|
36
|
+
{ :text => 'text from a hash', :random_value => rand(999), :created_at => DateTime.now }
|
37
37
|
else
|
38
38
|
raise "ID must be 0 or 1"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
class Structured
|
43
|
-
attr_reader :text, :random_value, :created_at
|
43
|
+
attr_reader :text, :random_value, :created_at, :xyz
|
44
44
|
|
45
45
|
def initialize(text)
|
46
46
|
@text = text
|
47
47
|
@random_value = rand(999)
|
48
48
|
@created_at = DateTime.now
|
49
|
+
@xyz = 'xyz'
|
49
50
|
end
|
50
51
|
end
|
51
52
|
end
|
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: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "F\xC3\xA1bio Batista"
|