LVS-JSONService 0.2.6 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.specification +1 -1
- data/JSONService.gemspec +1 -1
- data/VERSION +1 -1
- data/lib/lvs/json_service/base.rb +38 -46
- data/lib/lvs/json_service/request.rb +1 -1
- data/spec/lvs/json_service/base_spec.rb +11 -0
- metadata +1 -1
data/.specification
CHANGED
data/JSONService.gemspec
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.8
|
@@ -142,55 +142,47 @@ module LVS
|
|
142
142
|
end
|
143
143
|
|
144
144
|
def initialize(values = {})
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
if value.is_a?(Hash)
|
170
|
-
|
171
|
-
elsif value.is_a?(Array)
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
value = Time.at(value/1000)
|
176
|
-
elsif key =~ /^has_/
|
177
|
-
self.instance_variable_set("@#{key}", value)
|
178
|
-
!(value == 0 || value.blank?)
|
179
|
-
elsif key =~ /\?$/
|
180
|
-
key = "has_#{key.chop}"
|
181
|
-
!(value == 0 || value.blank?)
|
182
|
-
end
|
183
|
-
|
184
|
-
self.instance_variable_set("@#{key}", value)
|
145
|
+
@data = values
|
146
|
+
end
|
147
|
+
|
148
|
+
def id
|
149
|
+
@data["id"]
|
150
|
+
end
|
151
|
+
|
152
|
+
def name_to_key(name)
|
153
|
+
key = name.gsub(/[=?]/, '')
|
154
|
+
key.camelize(:lower)
|
155
|
+
end
|
156
|
+
|
157
|
+
def method_missing(name, *args)
|
158
|
+
name = name.to_s
|
159
|
+
key = name_to_key(name)
|
160
|
+
value = @data[key]
|
161
|
+
if name =~ /=$/
|
162
|
+
@data[key] = args[0]
|
163
|
+
elsif name =~ /\?$/
|
164
|
+
value = @data[name_to_key("has_#{key}")]
|
165
|
+
!(value == 0 || value.blank?)
|
166
|
+
elsif name =~ /^has_/
|
167
|
+
!(value == 0 || value.blank?)
|
168
|
+
else
|
169
|
+
if (value.is_a?(Hash))
|
170
|
+
value = self.class.new(value)
|
171
|
+
elsif (value.is_a?(Array))
|
172
|
+
value = value.collect {|v| if v.is_a?(Hash) or v.is_a?(Array) then self.class.new(v) else v end }
|
173
|
+
elsif name =~ /date$/
|
174
|
+
value = Time.at(value/1000)
|
185
175
|
end
|
186
176
|
end
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
177
|
+
if value.nil?
|
178
|
+
if self.class.ignore_missing
|
179
|
+
self.class.debug("Method #{name} called on #{self.class} but is non-existant, returned nil")
|
180
|
+
return nil
|
181
|
+
else
|
182
|
+
raise NoMethodError.new("Method #{name} called on #{self.class} but is non-existant, returned nil")
|
183
|
+
end
|
193
184
|
end
|
185
|
+
value
|
194
186
|
end
|
195
187
|
end
|
196
188
|
|
@@ -97,7 +97,7 @@ module LVS
|
|
97
97
|
if response.body.size < 1024 || options[:debug]
|
98
98
|
LVS::JsonService::Logger.debug "Response (#{timing}): #{response.body.gsub(/\n/, '')}"
|
99
99
|
else
|
100
|
-
LVS::JsonService::Logger.debug "Response Snippet (#{timing}): #{response.body.gsub(/\n/, '')[0..1024]}"
|
100
|
+
LVS::JsonService::Logger.debug "Response Snippet (#{timing} to return #{"%.1f" % (response.body.size/1024)}kB): #{response.body.gsub(/\n/, '')[0..1024]}"
|
101
101
|
end
|
102
102
|
if result.is_a?(Hash) && result.has_key?("PCode")
|
103
103
|
raise LVS::JsonService::Error.new(result["message"], result["PCode"], service, args, result)
|
@@ -18,4 +18,15 @@ describe LVS::JsonService::Base do
|
|
18
18
|
obj = RaiseOnMissingExample.new
|
19
19
|
lambda {obj.do_voodoo}.should raise_error(NoMethodError)
|
20
20
|
end
|
21
|
+
|
22
|
+
it "should find camelCase attributes using camelCase or ruby_sytax" do
|
23
|
+
class AttributeNames < LVS::JsonService::Base
|
24
|
+
self.ignore_missing = true
|
25
|
+
fake_service :call, '{"longMethodName":1}'
|
26
|
+
end
|
27
|
+
obj = AttributeNames.call
|
28
|
+
obj.longMethodName.should eql(1)
|
29
|
+
obj.long_method_name.should eql(1)
|
30
|
+
end
|
31
|
+
|
21
32
|
end
|