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



72
73
74
75
76
77
78
# File 'lib/alma/user.rb', line 72

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



28
29
30
31
32
33
34
35
36
37
# File 'lib/alma/user.rb', line 28

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



39
40
41
42
43
# File 'lib/alma/user.rb', line 39

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



45
46
47
48
49
50
51
52
# File 'lib/alma/user.rb', line 45

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



54
55
56
57
58
59
60
61
# File 'lib/alma/user.rb', line 54

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



63
64
65
66
67
68
69
70
# File 'lib/alma/user.rb', line 63

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

.set_wadl_filenameObject



81
82
83
# File 'lib/alma/user.rb', line 81

def set_wadl_filename
  'user.wadl'
end

Instance Method Details

#finesObject



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

def fines
  Alma::User.get_fines({:user_id => self.id.to_s})
end

#loansObject



17
18
19
# File 'lib/alma/user.rb', line 17

def loans
  Alma::User.get_loans({:user_id => self.id.to_s})
end

#post_initializeObject



9
10
11
# File 'lib/alma/user.rb', line 9

def post_initialize
  @id = response['primary_id']
end

#requestsObject



21
22
23
# File 'lib/alma/user.rb', line 21

def requests
  Alma::User.get_requests({:user_id => self.id.to_s})
end