Class: Alma::RequestOptions

Inherits:
Object
  • Object
show all
Extended by:
ApiDefaults, Forwardable
Defined in:
lib/alma/request_options.rb

Direct Known Subclasses

ItemRequestOptions

Defined Under Namespace

Classes: ResponseError

Constant Summary collapse

REQUEST_OPTIONS_PERMITTED_ARGS =
[:user_id]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApiDefaults

apikey, bibs_base_path, configuration_base_path, headers, items_base_path, region, timeout, users_base_path

Constructor Details

#initialize(response) ⇒ RequestOptions

Returns a new instance of RequestOptions.



16
17
18
19
20
# File 'lib/alma/request_options.rb', line 16

def initialize(response)
  @raw_response = response
  validate(response)
  @request_options = response.parsed_response["request_option"]
end

Instance Attribute Details

#raw_responseObject

Returns the value of attribute raw_response.



11
12
13
# File 'lib/alma/request_options.rb', line 11

def raw_response
  @raw_response
end

#request_optionsObject

Returns the value of attribute request_options.



11
12
13
# File 'lib/alma/request_options.rb', line 11

def request_options
  @request_options
end

Class Method Details

.get(mms_id, options = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/alma/request_options.rb', line 23

def self.get(mms_id, options = {})
  url = "#{bibs_base_path}/#{mms_id}/request-options"
  options.select! { |k, _|  REQUEST_OPTIONS_PERMITTED_ARGS.include? k }
  response = Net.get(url, headers:, query: options, timeout:)
  new(response)
end

Instance Method Details

#booking_allowed?Boolean

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/alma/request_options.rb', line 51

def booking_allowed?
  !request_options.nil? &&
    !request_options.select { |option| option["type"]["value"] == "BOOKING" }.empty?
end

#digitization_allowed?Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/alma/request_options.rb', line 46

def digitization_allowed?
  !request_options.nil? &&
    !request_options.select { |option| option["type"]["value"] == "DIGITIZATION" }.empty?
end


61
62
63
64
# File 'lib/alma/request_options.rb', line 61

def ez_borrow_link
  broker = request_options.select { |option| option["type"]["value"] == "RS_BROKER" }
  broker.collect { |opt| opt["request_url"] }.first
end

#hold_allowed?Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/alma/request_options.rb', line 41

def hold_allowed?
  !request_options.nil? &&
    !request_options.select { |option| option["type"]["value"] == "HOLD" }.empty?
end

#loggableObject



30
31
32
33
# File 'lib/alma/request_options.rb', line 30

def loggable
  { uri: @raw_response&.request&.uri.to_s
  }.select { |k, v| !(v.nil? || v.empty?) }
end

#resource_sharing_broker_allowed?Boolean

Returns:

  • (Boolean)


56
57
58
59
# File 'lib/alma/request_options.rb', line 56

def resource_sharing_broker_allowed?
  !request_options.nil? &&
    !request_options.select { |option| option["type"]["value"] == "RS_BROKER" }.empty?
end

#validate(response) ⇒ Object



35
36
37
38
39
# File 'lib/alma/request_options.rb', line 35

def validate(response)
  if response.code != 200
    raise ResponseError.new("Could not get request options.", loggable.merge(response.parsed_response))
  end
end