From ebbb6f43a9c8843b1694910c7235f02045a409a7 Mon Sep 17 00:00:00 2001 From: Michael Mendy Date: Wed, 11 Sep 2024 07:55:44 -0700 Subject: [PATCH] Added notation, and refactor. --- R1_example3.py | 73 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/R1_example3.py b/R1_example3.py index 0737548..be973a8 100644 --- a/R1_example3.py +++ b/R1_example3.py @@ -1,36 +1,59 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ -Created on Fri Jan 26 14:28:24 2024 - -@author: marcelomolinari -""" +R1 API Integration Script -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on Wed Jun 28 14:20:26 2023. +This script demonstrates the usage of the R1 API for retrieving +JWT tokens, MSP-EC tenant IDs, and venue information. -@author: Marcelo M. Molinari +Created on Fri Jan 26 14:28:24 2024 +@author: marcelomolinari """ import warnings from R1_API import R1_API_calls -warnings.filterwarnings("ignore", message="Unverified HTTPS request") - -HOST = 'base your for your region' -TENANT_ID = 'your tenant id' -CLIENT_ID = 'your client id' -SECRET_ID = 'your secret id' - -r1 = R1_API_calls() -jwt = r1.getJWT(HOST, TENANT_ID, CLIENT_ID, SECRET_ID)['access_token'] -print('jwt:', jwt) - -mspEcTenantId = r1.getMspECs(HOST, TENANT_ID, jwt)[0]['tenant_id'] -print('MSP-EC tenantId:', mspEcTenantId) - -mspEcVenues = r1.getVenues(HOST, mspEcTenantId, jwt) -print('MSP-EC venues:', mspEcVenues) +# Suppress unverified HTTPS request warnings +warnings.filterwarnings("ignore", message="Unverified HTTPS request") +# Configuration +CONFIG = { + 'HOST': 'base your for your region', + 'TENANT_ID': 'your tenant id', + 'CLIENT_ID': 'your client id', + 'SECRET_ID': 'your secret id' +} + +def main(): + """Main function to execute the R1 API calls.""" + r1 = R1_API_calls() + + # Get JWT token + jwt = get_jwt(r1) + print('JWT:', jwt) + + # Get MSP-EC tenant ID + msp_ec_tenant_id = get_msp_ec_tenant_id(r1, jwt) + print('MSP-EC tenant ID:', msp_ec_tenant_id) + + # Get MSP-EC venues + msp_ec_venues = get_msp_ec_venues(r1, msp_ec_tenant_id, jwt) + print('MSP-EC venues:', msp_ec_venues) + +def get_jwt(r1): + """Retrieve JWT token.""" + response = r1.getJWT(CONFIG['HOST'], CONFIG['TENANT_ID'], + CONFIG['CLIENT_ID'], CONFIG['SECRET_ID']) + return response['access_token'] + +def get_msp_ec_tenant_id(r1, jwt): + """Retrieve MSP-EC tenant ID.""" + response = r1.getMspECs(CONFIG['HOST'], CONFIG['TENANT_ID'], jwt) + return response[0]['tenant_id'] + +def get_msp_ec_venues(r1, msp_ec_tenant_id, jwt): + """Retrieve MSP-EC venues.""" + return r1.getVenues(CONFIG['HOST'], msp_ec_tenant_id, jwt) + +if __name__ == "__main__": + main()