require "alma_api/collection" require "alma_api/object" require "json" require_relative "../client" class AlmaApi::Client::Users require_relative "./users/fees" require_relative "./users/loans" require_relative "./users/requests" def initialize(client, user_id = nil) @client = client @user_id = user_id end def get(options = {}) if @user_id (options = options.deep_dup).symbolize_keys!.reverse_merge!({ user_id_type: :all_unique, view: :full }) @client.http(:get, "/v1/users/#{@user_id}", options).try do |_response| if _response.status == 200 AlmaApi::Object.new(JSON.parse(_response.body)) end end else (options = options.deep_dup).symbolize_keys!.reverse_merge!({ limit: 10, offset: 0, order_by: [ :last_name, :first_name, :primary_id ] }) @client.http(:get, "/v1/users", options).try do |_response| if _response.status == 200 AlmaApi::Collection.new(JSON.parse(_response.body), "user") end end end end def fees(fee_id = nil) Fees.new(@client, @user_id, fee_id) end def loans(loan_id = nil) Loans.new(@client, @user_id, loan_id) end def requests(request_id = nil) Requests.new(@client, @user_id, request_id) end end