Class: BorrowDirect::FindItem::Response
- Inherits:
-
Object
- Object
- BorrowDirect::FindItem::Response
- Includes:
- Util
- Defined in:
- lib/borrow_direct/find_item.rb
Instance Attribute Summary collapse
-
#response_hash ⇒ Object
readonly
Returns the value of attribute response_hash.
Instance Method Summary collapse
-
#auth_id ⇒ Object
Returns the AuthorizationID returned by FindItem API call, or nil if none is available.
-
#initialize(hash) ⇒ Response
constructor
A new instance of Response.
-
#locally_available? ⇒ Boolean
BD thinks the item is locally available at patron’s home library, and it is not requestable for that reason.
-
#pickup_locations ⇒ Object
Can be nil in some cases if not requestable? if requestable?, should be an array of Strings.
-
#requestable? ⇒ Boolean
Returns true or false – can the item actually be requested via BorrowDirect.
Methods included from Util
Constructor Details
#initialize(hash) ⇒ Response
Returns a new instance of Response.
104 105 106 |
# File 'lib/borrow_direct/find_item.rb', line 104 def initialize(hash) @response_hash = hash end |
Instance Attribute Details
#response_hash ⇒ Object (readonly)
Returns the value of attribute response_hash.
102 103 104 |
# File 'lib/borrow_direct/find_item.rb', line 102 def response_hash @response_hash end |
Instance Method Details
#auth_id ⇒ Object
Returns the AuthorizationID returned by FindItem API call, or nil if none is available. Nil can be returned, for instance when BD returns a NotFound error instead of a good response.
142 143 144 |
# File 'lib/borrow_direct/find_item.rb', line 142 def auth_id hash_key_path response_hash, "Item", "AuthorizationId" end |
#locally_available? ⇒ Boolean
BD thinks the item is locally available at patron’s home library, and it is not requestable for that reason. Items that are available locally, and thus not requestable via BD, can only be found by looking at the RequestMessage, bah
133 134 135 136 |
# File 'lib/borrow_direct/find_item.rb', line 133 def locally_available? h = response_hash["Item"]["RequestLink"] return !! (h && h["RequestMessage"] == "This item is available locally") end |
#pickup_locations ⇒ Object
Can be nil in some cases if not requestable? if requestable?, should be an array of Strings.
148 149 150 |
# File 'lib/borrow_direct/find_item.rb', line 148 def pickup_locations hash_key_path response_hash, "Item", "PickupLocations", "PickupLocation" end |
#requestable? ⇒ Boolean
Returns true or false – can the item actually be requested via BorrowDirect.
finder.find(:isbn => "12345545456").requestable?
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/borrow_direct/find_item.rb', line 113 def requestable? # Sometimes a PUBFI002 error code isn't really an error, # but just means not available. if response_hash && response_hash["Error"] && (response_hash["Error"]["ErrorNumber"] == "PUBFI002") return false end # Items that are available locally, and thus not requestable via BD, can # only be found by looking at the RequestMessage, bah if locally_available? return false end return response_hash["Item"]["Available"].to_s == "true" end |