Skip to content

Commit

Permalink
Have the make_bd_request method run thrpugh the CULBorrowDirect model.
Browse files Browse the repository at this point in the history
  • Loading branch information
tworrall committed Jul 2, 2021
1 parent 41a2125 commit 306b993
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions app/models/blacklight_cornell_requests/cul_borrow_direct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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: [*<variable>] 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
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight_cornell_requests/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module BlacklightCornellRequests
VERSION = "4.0.1"
VERSION = "4.0.2"
end
3 changes: 3 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 306b993

Please sign in to comment.