Class: BorrowDirect::Authentication
- 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"
Instance Attribute Summary collapse
-
#patron_barcode ⇒ Object
readonly
Returns the value of attribute patron_barcode.
-
#patron_library_symbol ⇒ Object
readonly
Returns the value of attribute patron_library_symbol.
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
-
#authentication_request ⇒ Object
Returns raw Hash results of the Authentication request See also #get_auth_id.
- #authentication_request_hash(patron_barcode, library_symbol) ⇒ Object
-
#get_auth_id ⇒ Object
Makes a request and returns the “AId” value which is used as input “AuthorizationId” in other API calls.
-
#initialize(patron_barcode, patron_library_symbol = Defaults.library_symbol, api_key = Defaults.api_key) ⇒ Authentication
constructor
BorrowDirect::Authentication.new(barcode) BorrowDirect::Authentication.new(barcode, library_symbol).
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, api_key = Defaults.api_key) ⇒ Authentication
BorrowDirect::Authentication.new(barcode) BorrowDirect::Authentication.new(barcode, library_symbol)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/borrow_direct/authentication.rb', line 16 def initialize(, patron_library_symbol = Defaults.library_symbol, api_key = Defaults.api_key) super(@@api_path) @patron_barcode = @patron_library_symbol = patron_library_symbol @api_key = api_key unless @api_key raise ArgumentError, "BorrowDirect::Authentication requires an api key as third paramter or set in BorrowDirect::Defaults.api_key" end end |
Instance Attribute Details
#patron_barcode ⇒ Object (readonly)
Returns the value of attribute patron_barcode.
10 11 12 |
# File 'lib/borrow_direct/authentication.rb', line 10 def @patron_barcode end |
#patron_library_symbol ⇒ Object (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_request ⇒ Object
Returns raw Hash results of the Authentication request See also #get_auth_id
33 34 35 |
# File 'lib/borrow_direct/authentication.rb', line 33 def authentication_request self.request authentication_request_hash(self., self.patron_library_symbol) end |
#authentication_request_hash(patron_barcode, library_symbol) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/borrow_direct/authentication.rb', line 51 def authentication_request_hash(, library_symbol) { "ApiKey" => @api_key, "PartnershipId" => BorrowDirect::Defaults.partnership_id, "UserGroup" => "patron", "LibrarySymbol" => library_symbol, "PatronId" => } end |
#get_auth_id ⇒ Object
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
41 42 43 44 45 46 47 48 49 |
# File 'lib/borrow_direct/authentication.rb', line 41 def get_auth_id response = authentication_request if response["AuthorizationId"] return response["AuthorizationId"] else raise BorrowDirect::Error.new("Could not obtain AId from Authorization API call: #{response.inspect}") end end |