class Alma::BibRequest

Constants

REQUEST_TYPES

Attributes

body[R]
mms_id[R]
request_type[R]
user_id[R]

Public Class Methods

new(args) click to toggle source
# File lib/alma/request.rb, line 24
def initialize(args)
  @mms_id = args.delete(:mms_id) { raise ArgumentError.new(":mms_id option must be specified to create request") }
  @user_id = args.delete(:user_id) { raise ArgumentError.new(":user_id option must be specified to create request") }
  @request_type = args.fetch(:request_type, "NOT_SPECIFIED")
  validate!(args)
  normalize!(args)
  @body = args
end
submit(args) click to toggle source
# File lib/alma/request.rb, line 12
def self.submit(args)
  request = new(args)
  response = HTTParty.post(
    "#{bibs_base_path}/#{request.mms_id}/requests",
    query: { user_id: request.user_id },
    headers: headers,
    body: request.body.to_json
    )
  Alma::Response.new(response)
end

Public Instance Methods

additional_normalization!(args) click to toggle source

Intended to be overridden by subclasses, allowing extra normalization logic to be provided

# File lib/alma/request.rb, line 45
def additional_normalization!(args)
end
additional_validation!(args) click to toggle source

Intended to be overridden by subclasses, allowing extra validation logic to be provided

# File lib/alma/request.rb, line 62
def additional_validation!(args)
end
booking_normalization(args) click to toggle source
# File lib/alma/request.rb, line 91
def booking_normalization(args)
  if args[:material_type].is_a? String
    args[:material_type] = { value: args[:material_type] }
  end
end
booking_validation(args) click to toggle source
# File lib/alma/request.rb, line 97
def booking_validation(args)
  args.fetch(:booking_start_date) do
    raise ArgumentError.new(
      ":booking_start_date option must be specified when request_type is BOOKING"
    )
  end
  args.fetch(:booking_end_date) do
    raise ArgumentError.new(
      ":booking_end_date option must be specified when request_type is BOOKING"
    )
  end
  args.fetch(:pickup_location_type) do
    raise ArgumentError.new(
      ":pickup_location_type option must be specified when request_type is BOOKING"
    )
  end
  args.fetch(:pickup_location_library) do
    raise ArgumentError.new(
      ":pickup_location_library option must be specified when request_type is BOOKING"
    )
  end
end
digitization_normalization(args) click to toggle source
# File lib/alma/request.rb, line 65
def digitization_normalization(args)
  if args[:target_destination].is_a? String
    args[:target_destination] = { value: args[:target_destination] }
  end
end
digitization_validation(args) click to toggle source
# File lib/alma/request.rb, line 71
def digitization_validation(args)
  args.fetch(:target_destination) do
    raise ArgumentError.new(
      ":target_destination option must be specified when request_type is DIGITIZATION"
    )
  end
  pd = args.fetch(:partial_digitization) do
    raise ArgumentError.new(
      ":partial_digitization option must be specified when request_type is DIGITIZATION"
    )
  end
  if pd == true
    args.fetch(:comment) do
      raise ArgumentError.new(
        ":comment option must be specified when :request_type is DIGITIZATION and :partial_digitization is true"
      )
    end
  end
end
hold_normalization(args) click to toggle source
# File lib/alma/request.rb, line 120
def hold_normalization(args)
  # if args[:material_type].is_a? String
  #   args[:material_type] = { value: args[:material_type] }
  # end
end
hold_validation(args) click to toggle source
# File lib/alma/request.rb, line 126
def hold_validation(args)
  args.fetch(:pickup_location_type) do
    raise ArgumentError.new(
      ":pickup_location_type option must be specified when request_type is HOLD"
    )
  end
  args.fetch(:pickup_location_library) do
    raise ArgumentError.new(
      ":pickup_location_library option must be specified when request_type is HOLD"
    )
  end
end
normalize!(args) click to toggle source
# File lib/alma/request.rb, line 34
def normalize!(args)
  request_type_normalization!(args)
  additional_normalization!(args)
end
request_type_normalization!(args) click to toggle source
# File lib/alma/request.rb, line 39
def request_type_normalization!(args)
  method = "#{@request_type.downcase}_normalization".to_sym
  send(method, args) if respond_to? method
end
request_type_validation!(args) click to toggle source
# File lib/alma/request.rb, line 56
def request_type_validation!(args)
  method = "#{@request_type.downcase}_validation".to_sym
  send(method, args) if respond_to? method
end
validate!(args) click to toggle source
# File lib/alma/request.rb, line 48
def validate!(args)
  unless REQUEST_TYPES.include?(request_type)
    raise ArgumentError.new(":request_type option must be specified and one of #{REQUEST_TYPES.join(", ")} to submit a request")
  end
  request_type_validation!(args)
  additional_validation!(args)
end