From 306b993e687d60354ada795c27c62557f817b1a4 Mon Sep 17 00:00:00 2001 From: tworrall Date: Fri, 2 Jul 2021 15:14:05 -0400 Subject: [PATCH] Have the make_bd_request method run thrpugh the CULBorrowDirect model. --- .../blacklight_cornell_requests/request_controller.rb | 11 ++++++++--- .../blacklight_cornell_requests/cul_borrow_direct.rb | 9 +++++---- lib/blacklight_cornell_requests/version.rb | 2 +- release_notes.md | 3 +++ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/controllers/blacklight_cornell_requests/request_controller.rb b/app/controllers/blacklight_cornell_requests/request_controller.rb index 46bc604..ad2457c 100755 --- a/app/controllers/blacklight_cornell_requests/request_controller.rb +++ b/app/controllers/blacklight_cornell_requests/request_controller.rb @@ -478,13 +478,19 @@ def make_purchase_request end def make_bd_request - if params[:library_id].blank? flash[:error] = "Please select a library pickup location" else resp, document = search_service.fetch params[:bibid] isbn = document[:isbn_display] - req = BlacklightCornellRequests::Request.new(params[:bibid]) + title = document[:title_display] + requester = Patron.new(user) + work = { :isbn => isbn, :title => title } + # Following FOLIO updates, using CULBorrowDirect for now as it has both the request_from_bd method + #and an authenticate method, which is called on initialization. Passing the boolean provides a way + # of distinguishing between the availability check and the call that actually makes the request. + make_request = true + req = BlacklightCornellRequests::CULBorrowDirect.new(requester, work, make_request) resp = req.request_from_bd({ :isbn => isbn, :netid => user, :pickup_location => params[:library_id], :notes => params[:reqcomments] }) if resp status = 'success' @@ -500,7 +506,6 @@ def make_bd_request else render :partial => '/shared/flash_msg', :layout => false end - end # AJAX responder used with requests.js.coffee to set the volume diff --git a/app/models/blacklight_cornell_requests/cul_borrow_direct.rb b/app/models/blacklight_cornell_requests/cul_borrow_direct.rb index 003a701..851204d 100755 --- a/app/models/blacklight_cornell_requests/cul_borrow_direct.rb +++ b/app/models/blacklight_cornell_requests/cul_borrow_direct.rb @@ -29,8 +29,9 @@ class CULBorrowDirect # patron should be a Patron instance # work = { :isbn, :title } + # make_request: this boolean is "true" when calling request_from_bd from the request controller # ISBN is best, but title will work if ISBN isn't available. - def initialize(patron, work) + def initialize(patron, work, make_request=false) @patron = patron @work = work @credentials = nil @@ -49,7 +50,7 @@ def initialize(patron, work) # AID is the AuthenticationId needed to use the Borrow Direct APIs @aid = authenticate - @available = available_in_bd? + @available = available_in_bd? if !make_request end # Switch between test and production configuration @@ -261,10 +262,10 @@ def request_from_bd(params) response = nil # This block can throw timeout errors if BD takes to long to respond begin - if @work.isbn.present? + if params[:isbn].present? # Note: [*] gives us an array if we don't already have one, # which we need for the map. - response = BorrowDirect::RequestItem.new(@patron.barcode).make_request(params[:pickup_location], {:isbn => [*@work.isbn.map!{|i| i = i.clean_isbn}[0]]}, params[:notes]) + response = BorrowDirect::RequestItem.new(@patron.barcode).make_request(params[:pickup_location], {:isbn => [*params[:isbn]].map!{|i| i = i.clean_isbn}[0]}, params[:notes]) end return response # response should be the BD request tracking number diff --git a/lib/blacklight_cornell_requests/version.rb b/lib/blacklight_cornell_requests/version.rb index 3ca122e..804e4a4 100755 --- a/lib/blacklight_cornell_requests/version.rb +++ b/lib/blacklight_cornell_requests/version.rb @@ -1,3 +1,3 @@ module BlacklightCornellRequests - VERSION = "4.0.1" + VERSION = "4.0.2" end diff --git a/release_notes.md b/release_notes.md index 4058b3b..01f9d15 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,5 +1,8 @@ # Release Notes - blacklight-cornell-requests +## v4.0.2 +- Have the make_bd_request method run thrpugh the CULBorrowDirect model. + ## v4.0.1 - Bug fixes for requestable libraries list and BD/ILL patron groups list - Make request error messages more user-friendly