class Alma::Electronic
Alma::Electronic
APIs wrapper.
Constants
- REGISTERED_APIs
Order matters because parameters can repeat.
Public Class Methods
get(params = {})
click to toggle source
# 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()
click to toggle source
# 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: 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()
click to toggle source
# File lib/alma/electronic.rb, line 34 def self.get_totals @totals ||= get(limit: "0").data["total_record_count"] end
http_retries()
click to toggle source
# File lib/alma/electronic.rb, line 59 def self.http_retries Alma.configuration.http_retries end
log()
click to toggle source
# File lib/alma/electronic.rb, line 38 def self.log Alma.configuration.logger end
Private Class Methods
get_api(params)
click to toggle source
# File lib/alma/electronic.rb, line 161 def self.get_api(params) REGISTERED_APIs .find { |m| m.can_process? params } .new(params) end