Class: BorrowDirect::Authentication

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

Overview

The BD Authorization API borrowdirect.pbworks.com/w/file/83346673/Authorization%20Service.docx

For now, always calls with ‘patron’ type.

Constant Summary collapse

@@api_path =
"/portal-service/user/authentication/patron"

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) ⇒ Authentication

BorrowDirect::Authentication.new(barcode) BorrowDirect::Authentication.new(barcode, library_symbol)



16
17
18
19
20
21
22
# File 'lib/borrow_direct/authentication.rb', line 16

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

  @patron_barcode = patron_barcode
  @patron_library_symbol = patron_library_symbol
end

Instance Attribute Details

#patron_barcodeObject (readonly)

Returns the value of attribute patron_barcode.



10
11
12
# File 'lib/borrow_direct/authentication.rb', line 10

def patron_barcode
  @patron_barcode
end

#patron_library_symbolObject (readonly)

Returns the value of attribute patron_library_symbol.



10
11
12
# File 'lib/borrow_direct/authentication.rb', line 10

def patron_library_symbol
  @patron_library_symbol
end

Instance Method Details

#authentication_requestObject

Returns raw Hash results of the Authentication request See also #get_auth_id



26
27
28
# File 'lib/borrow_direct/authentication.rb', line 26

def authentication_request
  self.request authentication_request_hash(self.patron_barcode, self.patron_library_symbol)
end

#authentication_request_hash(patron_barcode, library_symbol) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/borrow_direct/authentication.rb', line 44

def authentication_request_hash(patron_barcode, library_symbol)
  {
    "AuthenticationInformation" => {
      "LibrarySymbol" => library_symbol,
      "PatronId" => patron_barcode
    }
  } 
end

#get_auth_idObject

Makes a request and returns the “AId” value which is used as input “AuthorizationId” in other API calls.

If one can’t be obtained for some reason, will raise BorrowDirect::Error



34
35
36
37
38
39
40
41
42
# File 'lib/borrow_direct/authentication.rb', line 34

def get_auth_id
  response = authentication_request

  if response["Authentication"] && response["Authentication"]["AuthnUserInfo"] && response["Authentication"]["AuthnUserInfo"]["AId"]
    return response["Authentication"]["AuthnUserInfo"]["AId"]
  else
    raise BorrowDirect::Error.new("Could not obtain AId from Authorization API call: #{response.inspect}")
  end
end