Sha256: 343f0ca8b27af719e424392332375fb4a411e2551a52bac5fab603018b84b64c
Contents?: true
Size: 1.86 KB
Versions: 3
Compression:
Stored size: 1.86 KB
Contents
# frozen_string_literal: true module Alma class RequestOptions class ResponseError < Alma::StandardError end extend Forwardable extend Alma::ApiDefaults attr_accessor :request_options, :raw_response def_delegators :raw_response, :response, :request REQUEST_OPTIONS_PERMITTED_ARGS = [:user_id] def initialize(response) @raw_response = response validate(response) @request_options = response.parsed_response["request_option"] end def self.get(mms_id, options = {}) url = "#{bibs_base_path}/#{mms_id}/request-options" options.select! { |k, _| REQUEST_OPTIONS_PERMITTED_ARGS.include? k } response = HTTParty.get(url, headers: headers, query: options, timeout: timeout) new(response) end def loggable { uri: @raw_response&.request&.uri.to_s }.select { |k, v| !(v.nil? || v.empty?) } end def validate(response) if response.code != 200 raise ResponseError.new("Could not get request options.", loggable.merge(response.parsed_response)) end end def hold_allowed? !request_options.nil? && !request_options.select { |option| option["type"]["value"] == "HOLD" }.empty? end def digitization_allowed? !request_options.nil? && !request_options.select { |option| option["type"]["value"] == "DIGITIZATION" }.empty? end def booking_allowed? !request_options.nil? && !request_options.select { |option| option["type"]["value"] == "BOOKING" }.empty? end def resource_sharing_broker_allowed? !request_options.nil? && !request_options.select { |option| option["type"]["value"] == "RS_BROKER" }.empty? end def ez_borrow_link broker = request_options.select { |option| option["type"]["value"] == "RS_BROKER" } broker.collect { |opt| opt["request_url"] }.first end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
alma-0.4.0 | lib/alma/request_options.rb |
alma-0.3.3 | lib/alma/request_options.rb |
alma-0.3.2 | lib/alma/request_options.rb |