Class: BorrowDirect::FindItem::Response

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/borrow_direct/find_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

hash_key_path

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_hashObject (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_idObject

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.



134
135
136
# File 'lib/borrow_direct/find_item.rb', line 134

def auth_id
  hash_key_path response_hash, "Item", "AuthorizationId"
end

#pickup_locationsObject

Can be nil in some cases if not requestable? if requestable?, should be an array of Strings.



140
141
142
# File 'lib/borrow_direct/find_item.rb', line 140

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?

Returns:

  • (Boolean)


113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# 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
 h = response_hash["Item"]["RequestLink"]
 if h && h["RequestMessage"] == "This item is available locally"
   return false
 end

 return response_hash["Item"]["Available"].to_s == "true"
end