Class: Alma::User
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Api
default_params, load_wadl, query_merge, resources, set_wadl_filename
Methods inherited from AlmaRecord
#initialize, #method_missing, #respond_to_missing?, #response
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Alma::AlmaRecord
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
7
8
9
|
# File 'lib/alma/user.rb', line 7
def id
@id
end
|
Class Method Details
.authenticate(args) ⇒ Object
87
88
89
90
91
92
93
|
# File 'lib/alma/user.rb', line 87
def authenticate(args)
args.merge!({op: 'auth'})
params = query_merge args
response = resources.almaws_v1_users.user_id.post(params)
response.code == 204
end
|
.find(args = {}) ⇒ Object
Static methods that do the actual querying
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/alma/user.rb', line 43
def find(args = {})
return find_by_id(user_id: args[:user_id]) if args.fetch(:user_id, nil)
params = query_merge args
response = resources.almaws_v1_users.get(params)
Alma::UserSet.new(response)
end
|
.find_by_id(user_id_hash) ⇒ Object
54
55
56
57
58
|
# File 'lib/alma/user.rb', line 54
def find_by_id(user_id_hash)
params = query_merge user_id_hash
response = resources.almaws_v1_users.user_id.get(params)
User.new(response['user'])
end
|
.get_fines(args) ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'lib/alma/user.rb', line 60
def get_fines(args)
params = query_merge args
response = resources.almaws_v1_users.user_id_fees.get(params)
Alma::FineSet.new(response)
end
|
.get_loans(args) ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'lib/alma/user.rb', line 69
def get_loans(args)
params = query_merge args
response = resources.almaws_v1_users.user_id_loans.get(params)
Alma::LoanSet.new(response)
end
|
.get_requests(args) ⇒ Object
78
79
80
81
82
83
84
85
|
# File 'lib/alma/user.rb', line 78
def get_requests(args)
params = query_merge args
response = resources.almaws_v1_users.user_id_requests.get(params)
Alma::RequestSet.new(response)
end
|
Attempts to renew a single item for a user
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/alma/user.rb', line 102
def renew_loan(args)
args.merge!({op: 'renew'})
loan = args.delete(:loan)
if loan
args[:loan_id] = loan.loan_id
end
params = query_merge args
response = resources.almaws_v1_users.user_id_loans_loan_id.post(params)
RenewalResponse.new(response, loan)
end
|
.set_wadl_filename ⇒ Object
116
117
118
|
# File 'lib/alma/user.rb', line 116
def set_wadl_filename
'user.wadl'
end
|
Instance Method Details
#fines ⇒ Object
14
15
16
|
# File 'lib/alma/user.rb', line 14
def fines
self.class.get_fines({user_id: self.id})
end
|
#loans ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/alma/user.rb', line 18
def loans
unless @loans && !recheck_loans?
@loans = self.class.get_loans({user_id: self.id})
@recheck_loans = false
end
@loans
end
|
#post_initialize ⇒ Object
9
10
11
12
|
# File 'lib/alma/user.rb', line 9
def post_initialize
@id = response['primary_id'].to_s
@recheck_loans = true
end
|
#recheck_loans? ⇒ Boolean
32
33
34
|
# File 'lib/alma/user.rb', line 32
def recheck_loans?
@recheck_loans
end
|
#renew_loan(loan) ⇒ Object
26
27
28
29
30
|
# File 'lib/alma/user.rb', line 26
def renew_loan(loan)
response = self.class.renew_loan({user_id: self.id, loan: loan})
@recheck_loans = true if response.renewed?
response
end
|
#requests ⇒ Object
36
37
38
|
# File 'lib/alma/user.rb', line 36
def requests
self.class.get_requests({user_id:self.id})
end
|