Development repo for API integration between LibCal and Passage Point
libcal_requests.py
, which contains theLibCalRequests
class.- 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_bookings
method 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 theAlmaRequests
class.- Instantiation argument is the same as for
LibCalRequests
. - Pass the
main
method a Pythonlist
of 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 theSQLiteCache
class.- Instantiate with an optional name/path string for the database file.
- If not present, a new instance creates the
users
andappts
tables. add_user
accepts a list of dictionaries of the following structure:{'primary_id': 'GXXXXXXXX', 'barcode': '2282XXXXXXXXX', 'visitor_id': 'sdfjh3'}
wherevisitor_id
corresponds to theid
returned by thecreateVistor
endpoint of the PassagePoint API, and the other values are from Alma.lookup_user
queries the database for a providedprimary_id
and returns the user's other identifiers (if found).add_appt
accepts a single Python dictionary of the following structure:{'appt_id': 'yt54884', 'prereg_id': '343234jf'}
whereappt_id
corresponds to thebookId
from the LibCal API, andprereg_id
corresponds to theid
returned by thecreatePreReg
endpoint in PassagePoint.lookup_appt
queries the database for a single providedappt_id
(LibCal'sbookId
) and returns the mapping to the PassagePoint ID.
app.py
, which contains theLibCal2PP
class.__init__
creates instances of theAlmaRequests
,LibCalRequests
, andSQLiteCache
classes.log_new_bookings
does 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_users
to 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
PassagePointRequests
to create each pre-reg. - Records these pre-regs in the SQL cache.
process_users
does 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_users
to create the PassagePoint accounts. - Saves these users in the SQL cache.
- Returns the VisitorId's for all users.
register_new_users
does the following:- Retrieve barcodes for new users from Alma, using the Primary Id (GWID) from the LibCal appointment.
- Calls the appropriate method in
PassagePointRequests
to 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. (
LibCalRequests
is 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.py
to 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.