How jason9294/nyust-sso-client works
Main Components
• NYUST SSO Client: This is the core component (located in nyust_sso/client.py) that exposes methods like fetch_captcha(), login(), and fetch_my_courses(). It encapsulates the overall API used by client applications.
• HTTP/Network Layer: Found in nyust_sso/http.py, this handles all the networking interactions with the NYUST SSO system (e.g., establishing connections, sending HTTP requests).
• Error Handling: The nyust_sso/errors.py module centrally manages errors, which is important for depicting resilience and exception pathways.
• Domain/Class Entities: The “tronclass” sub-package (under nyust_sso/tronclass) is responsible for modeling domain-specific entities (like course, activity, and base entities). These classes represent the data retrieved after logging in.
• Utility Functions: Both nyust_sso/utils.py and nyust_sso/tronclass/utils.py encapsulate shared functionality that supports the main operations.
• Example Scripts: Located in the “example” directory, these show how to integrate with third-party libraries (like ddddocr for captcha recognition) and how to use the client.
Component Relationships and Data Flow
• The user (or an external application) calls the NYUSTSSOClient interface.
• The client first interacts with the HTTP module to fetch the captcha image (fetch_captcha()).
• An external OCR module (e.g., ddddocr) is then used to interpret the captcha image. (This dependency should be noted as an optional integration point.)
• Once the user provides credentials (username, password) along with the captcha text (with appropriate formatting, such as converting to lower-case), the client sends the login request via the HTTP layer.
• Upon successful login, the client fetches course data (e.g., fetch_my_courses()). The data returned might be mapped into domain entities defined in the tronclass package.
• Errors and exceptional cases are managed via the error-handling module.