Class: Agms::Response
- Inherits:
-
Object
show all
- Defined in:
- lib/agms/response/response.rb
Instance Method Summary
collapse
Constructor Details
#initialize(response, op) ⇒ Response
A class representing AGMS Response objects.
5
6
7
8
9
|
# File 'lib/agms/response/response.rb', line 5
def initialize(response, op)
@response = response
@op = op
@mapping = nil
end
|
Instance Method Details
#doMap(arr) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/agms/response/response.rb', line 24
def doMap(arr)
response = Hash.new
mapping = @mapping
if mapping
arr.each do |key, value|
if value.class == Hash
response << doMap(value)
else
if not mapping.has_key?(key)
raise UnexpectedError, "Unmapped field #{key} in response."
else
response[mapping[key]] = value
end
end
end
end
return response
end
|
#mapResponse(arr) ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/agms/response/response.rb', line 15
def mapResponse(arr)
if @mapping
response = doMap(arr)
return response
else
raise UnexpectedError, 'Response mapping not defined for this API.'
end
end
|
#toArray ⇒ Object
11
12
13
|
# File 'lib/agms/response/response.rb', line 11
def toArray
return mapResponse(@response)
end
|