Class: Alma::Electronic
- Inherits:
-
Object
show all
- Defined in:
- lib/alma/electronic.rb
Overview
Alma::Electronic APIs wrapper.
Defined Under Namespace
Classes: BatchUtils, Business, Collection, Collections, ElectronicAPI, ElectronicError, Portfolio, Service, Services
Class Method Summary
collapse
Class Method Details
.get(params = {}) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/alma/electronic.rb', line 14
def self.get(params = {})
retries_count = 0
response = nil
while retries_count < http_retries do
begin
response = get_api(params)
break;
rescue Net::ReadTimeout
retries_count += 1
log.error("Retrying http after timeout with : #{params}")
no_more_retries_left = retries_count == http_retries
raise Net::ReadTimeout.new("Failed due to net timeout after #{http_retries}: #{params}") if no_more_retries_left
end
end
return response
end
|
.get_ids ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/alma/electronic.rb', line 42
def self.get_ids
total = get_totals()
limit = 100
offset = 0
log.info("Retrieving #{total} collection ids.")
groups = Array.new(total / limit + 1, limit)
@ids ||= groups.map { |limit|
prev_offset = offset
offset += limit
{ offset: prev_offset, limit: }
}
.map { |params| Thread.new { self.get(params) } }
.map(&:value).map(&:data)
.map { |data| data["electronic_collection"].map { |coll| coll["id"] } }
.flatten.uniq
end
|
.get_totals ⇒ Object
34
35
36
|
# File 'lib/alma/electronic.rb', line 34
def self.get_totals
@totals ||= get(limit: "0").data["total_record_count"]
end
|
.http_retries ⇒ Object
59
60
61
|
# File 'lib/alma/electronic.rb', line 59
def self.http_retries
Alma.configuration.http_retries
end
|
.log ⇒ Object
38
39
40
|
# File 'lib/alma/electronic.rb', line 38
def self.log
Alma.configuration.logger
end
|