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
-
#initialize(hash, auth_id) ⇒ 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_location_data ⇒ Object
Can be nil if not requestable, otherwise an array of BorrowDirect::PickupLocation.
-
#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, auth_id) ⇒ Response
Returns a new instance of Response.
102 103 104 105 |
# File 'lib/borrow_direct/find_item.rb', line 102 def initialize(hash, auth_id) @response_hash = hash @auth_id = auth_id end |
Instance Attribute Details
#response_hash ⇒ Object (readonly)
Returns the value of attribute response_hash.
100 101 102 |
# File 'lib/borrow_direct/find_item.rb', line 100 def response_hash @response_hash end |
Instance Method Details
#auth_id ⇒ Object
138 139 140 |
# File 'lib/borrow_direct/find_item.rb', line 138 def auth_id @auth_id 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
132 133 134 135 136 |
# File 'lib/borrow_direct/find_item.rb', line 132 def locally_available? h = response_hash["RequestLink"] # Message seems to sometimes have period sometimes not. return !! (h && h["RequestMessage"] =~ /\AThis item is available locally\.?\Z/) end |
#pickup_location_data ⇒ Object
Can be nil if not requestable, otherwise an array of BorrowDirect::PickupLocation
See also #pickup_locations to return simply string location descriptions. It’s perhaps more careful code to use the codes too, as in this method, although Relais says just using labels and submitting them to RequestItem as a pickup location should work too.
157 158 159 160 161 162 163 164 |
# File 'lib/borrow_direct/find_item.rb', line 157 def pickup_location_data unless defined? @pickup_location_data @pickup_location_data = response_hash["PickupLocation"] && response_hash["PickupLocation"].collect do |hash| BorrowDirect::PickupLocation.new(hash) end end return @pickup_location_data end |
#pickup_locations ⇒ Object
Can be nil in some cases if not requestable? if requestable?, should be an array of Strings.
This just returns BD location labels, see also #pickup_location_data to return labels and codes.
147 148 149 |
# File 'lib/borrow_direct/find_item.rb', line 147 def pickup_locations response_hash["PickupLocation"] && response_hash["PickupLocation"].collect {|h| h["PickupLocationDescription"] } end |
#requestable? ⇒ Boolean
Returns true or false – can the item actually be requested via BorrowDirect.
finder.find(:isbn => "12345545456").requestable?
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/borrow_direct/find_item.rb', line 112 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["Available"].to_s == "true" end |