Class: BorrowDirect::FindItem

Inherits:
Request
  • Object
show all
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(patron_barcode).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

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

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.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/borrow_direct/find_item.rb', line 22

def initialize(patron_barcode = Defaults.find_item_patron_barcode, 
               patron_library_symbol = Defaults.library_symbol)
  super(@@api_path)

  @patron_barcode        = patron_barcode
  @patron_library_symbol = patron_library_symbol

  # BD sometimes unpredictably returns one of these errors 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_barcodeObject (readonly)

Returns the value of attribute patron_barcode.



16
17
18
# File 'lib/borrow_direct/find_item.rb', line 16

def patron_barcode
  @patron_barcode
end

#patron_library_symbolObject (readonly)

Returns the value of attribute patron_library_symbol.



16
17
18
# File 'lib/borrow_direct/find_item.rb', line 16

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.



69
70
71
# File 'lib/borrow_direct/find_item.rb', line 69

def find(options)
  BorrowDirect::FindItem::Response.new find_item_request(options), self.auth_id
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"])


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/borrow_direct/find_item.rb', line 46

def find_item_request(options)
  search_type, search_value = nil, nil
  options.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: '#{options}'")
      end

      search_type, search_value = key, value
    end
  end
  unless search_type && search_value
    raise ArgumentError.new("Missing valid search type and value: '#{options}'")
  end

  request exact_search_request_hash(search_type, search_value), need_auth_id(self.patron_barcode, self.patron_library_symbol)
end