Class: BorrowDirect::FindItem
- Defined in:
- lib/borrow_direct/find_item.rb
Overview
The BorrowDirect FindItem service, for discovering item availability borrowdirect.pbworks.com/w/file/83346676/Find%20Item%20Service.docx
BorrowDirect::FindItem.new().bd_requestability?(:isbn => isbn)
# or set BorrowDirect::Defaults.find_item_patron_barcode to make patron barcode
# optional and use a default patron barcode
You can also use #find_item_request to get the raw BD response as a ruby hash
Defined Under Namespace
Classes: Response
Constant Summary collapse
- @@api_path =
"/dws/item/available"
- @@valid_search_types =
%w{ISBN ISSN LCCN OCLC PHRASE}
Instance Attribute Summary collapse
-
#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
-
#find(options) ⇒ Object
need to send a key and value for a valid exact_search type type can be string or symbol, lowercase or uppercase.
-
#find_item_request(options) ⇒ Object
need to send a key and value for a valid exact_search type type can be string or symbol, lowercase or uppercase.
-
#initialize(patron_barcode = Defaults.find_item_patron_barcode, patron_library_symbol = Defaults.library_symbol) ⇒ FindItem
constructor
A new instance of FindItem.
Methods inherited from Request
#fetch_auth_id!, #need_auth_id, #request, #request_headers, #with_auth_id
Constructor Details
#initialize(patron_barcode = Defaults.find_item_patron_barcode, patron_library_symbol = Defaults.library_symbol) ⇒ FindItem
Returns a new instance of FindItem.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/borrow_direct/find_item.rb', line 20 def initialize( = Defaults., 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 << "PUBFI002" end |
Instance Attribute Details
#patron_barcode ⇒ Object (readonly)
Returns the value of attribute patron_barcode.
14 15 16 |
# File 'lib/borrow_direct/find_item.rb', line 14 def @patron_barcode end |
#patron_library_symbol ⇒ Object (readonly)
Returns the value of attribute patron_library_symbol.
14 15 16 |
# File 'lib/borrow_direct/find_item.rb', line 14 def patron_library_symbol @patron_library_symbol end |
Instance Method Details
#find(options) ⇒ Object
need to send a key and value for a valid exact_search type type can be string or symbol, lowercase or uppercase.
Returns a BorrowDirect::FindItem::Response object, from which you can find out requestability, list of pickup locations, etc.
67 68 69 |
# File 'lib/borrow_direct/find_item.rb', line 67 def find() BorrowDirect::FindItem::Response.new find_item_request() end |
#find_item_request(options) ⇒ Object
need to send a key and value for a valid exact_search type type can be string or symbol, lowercase or uppercase.
Returns the actual complete BD response hash. You may want #bd_requestable? instead
finder.find_item_request(:isbn => "12345545456")
You can request multiple values which BD will treat as an βORβ/union β sort of. BD does unpredictable things here, be careful.
finder.find_item_request(:isbn => ["12345545456", "99999999"])
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/borrow_direct/find_item.rb', line 44 def find_item_request() 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(search_type, search_value) end |