Class: Alma::User

Inherits:
AlmaRecord show all
Extended by:
Api
Defined in:
lib/alma/user.rb

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

Constructor Details

This class inherits a constructor from Alma::AlmaRecord

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Alma::AlmaRecord

Instance Attribute Details

#idObject

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)
  # Authenticates a Alma user with their Alma Password
  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 = {})
  #TODO Handle Search Queries
  #TODO Handle Pagination
  #TODO Handle looping through all results

  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)
  #TODO Handle Additional Parameters
  #TODO Handle Pagination
  #TODO Handle looping through all results
  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)
  #TODO Handle Additional Parameters
  #TODO Handle Pagination
  #TODO Handle looping through all results
  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)
  #TODO Handle Additional Parameters
  #TODO Handle Pagination
  #TODO Handle looping through all results
  params = query_merge args
  response = resources.almaws_v1_users.user_id_requests.get(params)
  Alma::RequestSet.new(response)
end

.renew_loan(args) ⇒ RenewalResponse

Attempts to renew a single item for a user

Parameters:

  • args (Hash)

Options Hash (args):

  • :user_id (String)

    The unique id of the user

  • :loan_id (String)

    The unique id of the loan - optional (either :loan_id or :loan must be present)

  • :loan_id (String)

    A loan object - optional (either :loan_id or :loan must be present)

  • :user_id_type (String)

    Type of identifier being used to search

Returns:



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'})

  # If a loan object is passed in args, us its id as loan_id
  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_filenameObject



116
117
118
# File 'lib/alma/user.rb', line 116

def set_wadl_filename
  'user.wadl'
end

Instance Method Details

#finesObject



14
15
16
# File 'lib/alma/user.rb', line 14

def fines
  self.class.get_fines({user_id: self.id})
end

#loansObject



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_initializeObject



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

Returns:

  • (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

#requestsObject



36
37
38
# File 'lib/alma/user.rb', line 36

def requests
  self.class.get_requests({user_id:self.id})
end