Class: BorrowDirect::RequestQuery

Inherits:
Request
  • Object
show all
Defined in:
lib/borrow_direct/request_query.rb

Overview

Info from Relais/BD on type and status:

valid ‘type’ values for requests:

xdays: Retrieve requests submitted within the last xdays (for example, one would include two parameters: type=xdays&xdays=7 to retrieve requests submitted within the last 7 days)
all: Retrieve all request submitted by the user
open: Retrieve all open requests i.e. requests which haven't been fulfilled yet.
allposttoweb: BD doesn't use the post-to-web application; you can ignore this.
unopenedposttoweb: You can safely ignore this.
onloan: Retrieve requests which are on loan

possible RequestStatus values in results:

ENTERED: Request has been entered and yet to be processed.
IN_PROCESS: Request is being processed.
CANCELLED: Request has been cancelled.
UNFILLED: Request can't be filled.
SHIPPED: Item has been shipped.
ARTICLE_SENT: A scanned document or an electronic document has been sent (It doesn't apply to BD)
ON_LOAN: Request is on loan.
OVERDUE: Item is over due.
COMPLETE: Item has been returned and request is completed.
UNKNOWN: You should never see this; this indicates there is probably an inconsistency with the record somewhere. You probably want to flag and report this.

Defined Under Namespace

Classes: Item

Constant Summary collapse

@@api_path =
"/portal-service/request/query/my"
@@query_types =

I’m not exactly sure what these mean either.

%w{xdays all open allposttoweb unopenedposttoweb onloan}

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, patron_library_symbol = Defaults.library_symbol) ⇒ RequestQuery

Returns a new instance of RequestQuery.



37
38
39
40
41
42
43
44
# File 'lib/borrow_direct/request_query.rb', line 37

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

  @patron_barcode        = patron_barcode
  @patron_library_symbol = patron_library_symbol
  self.http_method = :get
end

Instance Attribute Details

#patron_barcodeObject (readonly)

Returns the value of attribute patron_barcode.



29
30
31
# File 'lib/borrow_direct/request_query.rb', line 29

def patron_barcode
  @patron_barcode
end

#patron_library_symbolObject (readonly)

Returns the value of attribute patron_library_symbol.



29
30
31
# File 'lib/borrow_direct/request_query.rb', line 29

def patron_library_symbol
  @patron_library_symbol
end

Instance Method Details

#request_query_request(type = "all", full_record = false) ⇒ Object

Returns raw BD response as a hash.

  • type defaults to ‘all’, but can be BD values of xdays, all open, allposttoweb, unopenedposttoweb, onloan. xdays not really supported yet, cause no way to pass an xdays param yet

  • full_record can be true or false, defaults to false.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/borrow_direct/request_query.rb', line 51

def request_query_request(type = "all", full_record = false)
  query_params = {
    "aid"         => need_auth_id(patron_barcode, patron_library_symbol),
    "type"        => type.to_s,
    "fullRecord"  => (full_record ? "1" : "0")
  }

  response = request query_params

  # RequestQuery sometimes returns odd 200 OK response with
  # AuthFailed, at least as of 29 Sep 2015. Catch it and
  # raise it properly. 
  if response["AuthorizationState"] && response["AuthorizationState"]["State"] == false
    raise BorrowDirect::InvalidAidError.new("API returned AuthorizationState.State == false", nil, response["AuthorizationState"]["AuthorizationId"])
  end

  return response
end

#requests(*args) ⇒ Object

Returns an array of BorrowDirect::RequestQuery::Item

  • type defaults to ‘all’, but can be BD values of xdays, all open, allposttoweb, unopenedposttoweb, onloan. xdays not really supported yet, cause no way to pass an xdays param yet

  • full_record can be true or false, defaults to false.



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/borrow_direct/request_query.rb', line 75

def requests(*args)
  response = request_query_request(*args)

  results = []

  response["MyRequestRecords"].each do |item_hash|        
    results << BorrowDirect::RequestQuery::Item.new(item_hash)
  end

  return results
end