Development repo for API integration between LibCal and Passage Point
libcal_requests.py, which contains theLibCalRequestsclass.- On instantiation, pass the name of a config YAML file. (Default is
config.yml, which should reside in the same directory as the module.) - The
__init__method gets a new auth token (using the supplied paramters in the config.) - The
retrieve_bookingsmethod fetches the day's current bookings for the locations specified in the config.
- On instantiation, pass the name of a config YAML file. (Default is
alma_requests.py, which contains theAlmaRequestsclass.- Instantiation argument is the same as for
LibCalRequests. - Pass the
mainmethod a Pythonlistof Alma Primary ID's (GWID numbers) to return the users' barcodes. Failed matches will be omitted from the returned results.
- Instantiation argument is the same as for
sqlite_cache.py, which contains theSQLiteCacheclass.- Instantiate with an optional name/path string for the database file.
- If not present, a new instance creates the
usersandapptstables. add_useraccepts a list of dictionaries of the following structure:{'primary_id': 'GXXXXXXXX', 'barcode': '2282XXXXXXXXX', 'visitor_id': 'sdfjh3'}wherevisitor_idcorresponds to theidreturned by thecreateVistorendpoint of the PassagePoint API, and the other values are from Alma.lookup_userqueries the database for a providedprimary_idand returns the user's other identifiers (if found).add_apptaccepts a single Python dictionary of the following structure:{'appt_id': 'yt54884', 'prereg_id': '343234jf'}whereappt_idcorresponds to thebookIdfrom the LibCal API, andprereg_idcorresponds to theidreturned by thecreatePreRegendpoint in PassagePoint.lookup_apptqueries the database for a single providedappt_id(LibCal'sbookId) and returns the mapping to the PassagePoint ID.
app.py, which contains theLibCal2PPclass.__init__creates instances of theAlmaRequests,LibCalRequests, andSQLiteCacheclasses.log_new_bookingsdoes the following:- Fetches space bookings from LibCal.
- Filters out those that are already in the SQL cache. (These will already have been registered with PassagePoint.)
- Calls
process_usersto obtain the PassagePoint VisitorId's. - Creates PassagePoint metadata for new pre-registrations, using the LibCal booking data and the PassagePoint VisitorId.
- Makes a call to
PassagePointRequeststo create each pre-reg. - Records these pre-regs in the SQL cache.
process_usersdoes the following:- Separates the users with new LibCal appointments into those already in the SQL cache (users with PassagePoint accounts) and those needing to have accounts created.
- Calls
register_new_usersto create the PassagePoint accounts. - Saves these users in the SQL cache.
- Returns the VisitorId's for all users.
register_new_usersdoes the following:- Retrieve barcodes for new users from Alma, using the Primary Id (GWID) from the LibCal appointment.
- Calls the appropriate method in
PassagePointRequeststo create a new user account and return the VisitorId for each new user.
- If running all of the above in a loop, we may need logic to check for an expire auth token for LibCal and PassagePoint.
- For LibCal, it might be easiest just to get a new token before each call to the bookings API. (
LibCalRequestsis currently written to do so on init). - Not sure about PassagePoint.
- For LibCal, it might be easiest just to get a new token before each call to the bookings API. (
- Add a method to
app.pyto run the process at specified intervals. - To keep the size of the db in check, we may want periodically to delete rows with past appointments. We could implement by adding a timestamp column.