Class: Alma::FineSet
Defined Under Namespace
Classes: ResponseError
Instance Attribute Summary collapse
Attributes inherited from ResultSet
#response
Instance Method Summary
collapse
Methods inherited from ResultSet
#total_record_count
Methods included from Error
#error, #error_message, #has_error?
Constructor Details
#initialize(raw_response) ⇒ FineSet
Returns a new instance of FineSet.
11
12
13
14
15
16
17
|
# File 'lib/alma/fine_set.rb', line 11
def initialize(raw_response)
@raw_response = raw_response
@response = raw_response.parsed_response
validate(raw_response)
@results = (@response.fetch(key, []) || [])
.map { |item| single_record_class.new(item) }
end
|
Instance Attribute Details
#raw_response ⇒ Object
Returns the value of attribute raw_response.
8
9
10
|
# File 'lib/alma/fine_set.rb', line 8
def raw_response
@raw_response
end
|
#results ⇒ Object
Returns the value of attribute results.
8
9
10
|
# File 'lib/alma/fine_set.rb', line 8
def results
@results
end
|
Instance Method Details
#currency ⇒ Object
50
51
52
|
# File 'lib/alma/fine_set.rb', line 50
def currency
fetch("currency", nil)
end
|
#each(&block) ⇒ Object
32
33
34
|
# File 'lib/alma/fine_set.rb', line 32
def each(&block)
@results.each(&block)
end
|
#key ⇒ Object
40
41
42
|
# File 'lib/alma/fine_set.rb', line 40
def key
"fee"
end
|
#loggable ⇒ Object
19
20
21
22
|
# File 'lib/alma/fine_set.rb', line 19
def loggable
{ uri: @raw_response&.request&.uri.to_s
}.select { |k, v| !(v.nil? || v.empty?) }
end
|
#success? ⇒ Boolean
36
37
38
|
# File 'lib/alma/fine_set.rb', line 36
def success?
raw_response.response.code.to_s == "200"
end
|
#sum ⇒ Object
Also known as:
total_sum
44
45
46
|
# File 'lib/alma/fine_set.rb', line 44
def sum
fetch("total_sum", 0)
end
|
#validate(response) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/alma/fine_set.rb', line 24
def validate(response)
if response.code != 200
message = "Could not find fines."
log = loggable.merge(response.parsed_response)
raise ResponseError.new(message, log)
end
end
|