Class: BorrowDirect::RequestItem
- Defined in:
- lib/borrow_direct/request_item.rb
Overview
The BorrowDirect RequestItem service, for placing a request borrowdirect.pbworks.com/w/file/86126056/RequestItem.docx
You can also use #find_item_request to get the raw BD response as a ruby hash
Constant Summary collapse
- @@api_path =
"/dws/item/add"
- @@valid_search_types =
%w{ISBN ISSN LCCN OCLC Control }
Instance Attribute Summary collapse
-
#authorization_id ⇒ Object
readonly
Returns the value of attribute authorization_id.
-
#patron_barcode ⇒ Object
readonly
Returns the value of attribute patron_barcode.
-
#patron_library_symbol ⇒ Object
readonly
Returns the value of attribute patron_library_symbol.
Attributes inherited from Request
#auth_id, #expected_error_codes, #http_client, #http_method, #last_request_json, #last_request_response, #last_request_time, #last_request_uri, #timeout
Instance Method Summary collapse
-
#initialize(patron_barcode, patron_library_symbol = Defaults.library_symbol) ⇒ RequestItem
constructor
A new instance of RequestItem.
-
#make_request(pickup_location, options) ⇒ Object
Pass in a BD exact search and pickup location eg make_request(pickup_location, :isbn => isbn).
-
#make_request!(pickup_location, options) ⇒ Object
Like make_request, but will raise a BorrowDirect::Error if item can’t be requested.
-
#request_item_request(pickup_location, options) ⇒ Object
need to send a key and value for a valid exact_search type type can be string or symbol, lowercase or uppercase.
Methods inherited from Request
#fetch_auth_id!, #need_auth_id, #request, #request_headers, #with_auth_id
Constructor Details
#initialize(patron_barcode, patron_library_symbol = Defaults.library_symbol) ⇒ RequestItem
Returns a new instance of RequestItem.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/borrow_direct/request_item.rb', line 18 def initialize(, patron_library_symbol = Defaults.library_symbol) super(@@api_path) @patron_barcode = @patron_library_symbol = patron_library_symbol # BD sometimes unpredictably returns this error when it means # "no results", other times it doens't. We don't want to raise on it. self.expected_error_codes << "PUBRI004" end |
Instance Attribute Details
#authorization_id ⇒ Object (readonly)
Returns the value of attribute authorization_id.
11 12 13 |
# File 'lib/borrow_direct/request_item.rb', line 11 def @authorization_id end |
#patron_barcode ⇒ Object (readonly)
Returns the value of attribute patron_barcode.
10 11 12 |
# File 'lib/borrow_direct/request_item.rb', line 10 def @patron_barcode end |
#patron_library_symbol ⇒ Object (readonly)
Returns the value of attribute patron_library_symbol.
10 11 12 |
# File 'lib/borrow_direct/request_item.rb', line 10 def patron_library_symbol @patron_library_symbol end |
Instance Method Details
#make_request(pickup_location, options) ⇒ Object
Pass in a BD exact search and pickup location eg
make_request(pickup_location, :isbn => isbn)
Pass in nil for pickup_location if… not sure exactly what BD will do, but it does allow it.
Returns the BD RequestNumber, or nil if a request could not be made
See also make_request! to raise if request can not be made
71 72 73 74 75 |
# File 'lib/borrow_direct/request_item.rb', line 71 def make_request(pickup_location, ) resp = request_item_request(pickup_location, ) return extract_request_number(resp) end |
#make_request!(pickup_location, options) ⇒ Object
Like make_request, but will raise a BorrowDirect::Error if item can’t be requested.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/borrow_direct/request_item.rb', line 79 def make_request!(pickup_location, ) resp = request_item_request(pickup_location, ) number = extract_request_number(resp) if number.nil? raise BorrowDirect::Error.new("Can not request for: #{.inspect}: #{resp.inspect}") end return number end |
#request_item_request(pickup_location, options) ⇒ Object
need to send a key and value for a valid exact_search type type can be string or symbol, lowercase or uppercase.
Also a pickup_location – can pass in nil, and we’ll send no PickupLocation to BD, which it seems to accept, not sure what it does with it.
Returns the actual complete BD response hash. You may want #make_request instead
finder.request_item_request(pickup_location, :isbn => "12345545456")
finder.request_item_request(pickup_location, :lccn => "12345545456")
finder.request_item_request(pickup_location, :oclc => "12345545456")
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/borrow_direct/request_item.rb', line 43 def request_item_request(pickup_location, ) search_type, search_value = nil, nil .each_pair do |key, value| if @@valid_search_types.include? key.to_s.upcase if search_type || search_value raise ArgumentError.new("Only one search criteria at a time is allowed: '#{}'") end search_type, search_value = key, value end end unless search_type && search_value raise ArgumentError.new("Missing valid search type and value: '#{}'") end request exact_search_request_hash(pickup_location, search_type, search_value) end |