Class: Alma::BibRequest
Defined Under Namespace
Classes: ItemAlreadyExists
Constant Summary
collapse
- REQUEST_TYPES =
%w[HOLD DIGITIZATION BOOKING]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
apikey, bibs_base_path, configuration_base_path, headers, items_base_path, region, timeout, users_base_path
Constructor Details
Returns a new instance of BibRequest.
24
25
26
27
28
29
30
31
|
# 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
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
23
24
25
|
# File 'lib/alma/request.rb', line 23
def body
@body
end
|
#mms_id ⇒ Object
Returns the value of attribute mms_id.
23
24
25
|
# File 'lib/alma/request.rb', line 23
def mms_id
@mms_id
end
|
#request_type ⇒ Object
Returns the value of attribute request_type.
23
24
25
|
# File 'lib/alma/request.rb', line 23
def request_type
@request_type
end
|
#user_id ⇒ Object
Returns the value of attribute user_id.
23
24
25
|
# File 'lib/alma/request.rb', line 23
def user_id
@user_id
end
|
Class Method Details
.submit(args) ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/alma/request.rb', line 12
def self.submit(args)
request = new(args)
response = Net.post(
"#{bibs_base_path}/#{request.mms_id}/requests",
query: { user_id: request.user_id },
headers:,
body: request.body.to_json
)
Alma::Response.new(response)
end
|
Instance Method Details
#additional_normalization!(args) ⇒ Object
Intended to be overridden by subclasses, allowing extra normalization logic to be provided
45
46
|
# File 'lib/alma/request.rb', line 45
def additional_normalization!(args)
end
|
#additional_validation!(args) ⇒ Object
Intended to be overridden by subclasses, allowing extra validation logic to be provided
62
63
|
# File 'lib/alma/request.rb', line 62
def additional_validation!(args)
end
|
#booking_normalization(args) ⇒ Object
91
92
93
94
95
|
# 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) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# 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) ⇒ Object
65
66
67
68
69
|
# 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) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# 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) ⇒ Object
120
121
122
123
124
|
# File 'lib/alma/request.rb', line 120
def hold_normalization(args)
end
|
#hold_validation(args) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
|
# 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) ⇒ Object
34
35
36
37
|
# File 'lib/alma/request.rb', line 34
def normalize!(args)
request_type_normalization!(args)
additional_normalization!(args)
end
|
#request_type_normalization!(args) ⇒ Object
39
40
41
42
|
# 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) ⇒ Object
56
57
58
59
|
# 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) ⇒ Object
48
49
50
51
52
53
54
|
# 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
|