lib/alma/user.rb in alma-0.2.3 vs lib/alma/user.rb in alma-0.2.4
- old
+ new
@@ -1,7 +1,5 @@
-
-
module Alma
class User < AlmaRecord
extend Alma::Api
attr_accessor :id
@@ -23,14 +21,24 @@
@loans
end
def renew_loan(loan_id)
response = self.class.renew_loan({user_id: self.id, loan_id: loan_id})
- @recheck_loans = true if response.renewed?
+ if response.renewed?
+ @recheck_loans ||= true
+ end
response
end
+ def renew_multiple_loans(loan_ids)
+ loan_ids.map { |id| renew_loan(id) }
+ end
+
+ def renew_all_loans
+ renew_multiple_loans(loans.map(&:loan_id))
+ end
+
def recheck_loans?
@recheck_loans
end
def requests
@@ -102,9 +110,28 @@
args.merge!({op: 'renew'})
params = query_merge args
response = resources.almaws_v1_users.user_id_loans_loan_id.post(params)
RenewalResponse.new(response)
end
+
+ # Attempts to renew a multiple items for a user
+ # @param [Hash] args
+ # @option args [String] :user_id The unique id of the user
+ # @option args [Array<String>] :loan_ids Array of loan ids
+ # @option args [String] :user_id_type Type of identifier being used to search. OPTIONAL
+ # @return [Array<RenewalResponse>] Object indicating the renewal message
+ def renew_multiple_loans(args)
+
+ if args.fetch(:loans_ids, nil).respond_to? :map
+ args.delete(:loan_ids).map do |loan_id|
+ renew_loan(args.merge(loan_id: loan_id))
+ end
+ else
+ []
+ end
+ end
+
+
def set_wadl_filename
'user.wadl'
end
\ No newline at end of file