-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatron.rb
61 lines (49 loc) · 1.01 KB
/
patron.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class Patron
def initialize(data:)
@data = data
end
def self.for(uniqname, options = {})
client = options[:alma_client] || AlmaRestClient.client
alma_response = client.get("/users/#{uniqname}")
if alma_response.status == 200
Patron.new(data: alma_response.body)
else
NotInAlma.new
end
end
def user_group
@data.dig("user_group", "value")
end
def statistic_categories
@data.dig("user_statistic")&.map do |stat|
stat.dig("statistic_category", "value")
end
end
def can_book?
faculty? || staff? || temporary_staff? # || faculty_proxy?
end
class NotInAlma < self
def user_group
""
end
def statistic_categories
[]
end
end
private
def has_category(category)
statistic_categories&.any? { |stat| stat == category }
end
def staff?
user_group == "02"
end
def faculty?
user_group == "01"
end
def temporary_staff?
user_group == "14"
end
# def faculty_proxy?
# has_category('PR')
# end
end