""" AUTHOR: Khushal P Soonderji DATE: Tuesday, 10th Sept., 2024. OBJECTIVE: To provide a data structure for the JSOn received in the API calls to send SMSs through Nimbus IT's service. REFERENCES: N/A DOWNLOADS: N/A """ # ***************************************************************************************************************** # ***** **** # *** IMPORT *** # ***** **** # ***************************************************************************************************************** # To make sibling directories accessible for imports: import sys sys.path.append(".") sys.path.append("..") # For making data models: from pydantic import BaseModel, Field, field_validator, Extra from typing import Optional, Any, Dict from typing_extensions import Annotated # My utils: from utils_v2.string import regex # ***************************************************************************************************************** # ***** **** # *** MACROS / ONE-TIME INIT *** # ***** **** # ***************************************************************************************************************** # --- Nothing Yet # ***************************************************************************************************************** # ***** **** # *** VARIABLES *** # ***** **** # ***************************************************************************************************************** # --- Nothing Yet # ***************************************************************************************************************** # ***** **** # *** FUNCTIONS *** # ***** **** # ***************************************************************************************************************** class NimbusSMSSendRequest(BaseModel): entityId: str | int | None = Field( description = "The id given to you by DLT.", default = None, frozen = True ) templateId: str | int = Field( description = "The id given to you by DLT for a template of a message.", frozen = True ) recipientNo: str | int = Field( description = "The phone number of the person you want to send the message to.", frozen = True ) message: str = Field( description = "The message you want to send.", frozen = True ) senderId: str | int | None = Field( description = "6-char code like 'HDFCBK', 'NSESMS', 'ZRODHA' that you see in your SMS inbox.", default = None, frozen = True ) userId: str | int | None = Field( description = "The 6-digit id given to you by Nimbus.", default = None, frozen = True ) apiKey: str | None = Field( description = "The key generated on Nimbus's portal.", default = None, frozen = True ) class Config: extra = "forbid" def get(self, key: str, default = None): return getattr(self, key, default) @field_validator( "entityId", "templateId", "recipientNo", "senderId" ) def validate_fields(cls, value): if isinstance(value, str): return value elif isinstance(value, int): return str(value) raise ValueError @field_validator("userId") def validate_user_id(cls, value): if isinstance(value, int): value = str(value) if regex.match(text = value, pattern = r"^[\d]{6}$"): return value raise ValueError("userId must be 6-digits long") # --------------------------------------------------------------------------------------------------------------------- class NimbusGetBalanceRequest(BaseModel): userId: str | int | None = Field( description = "The 6-digit id given to you by Nimbus.", default = None, frozen = True ) apiKey: str | None = Field( description = "The key generated on Nimbus's portal.", default = None, frozen = True ) class Config: extra = "forbid" def get(self, key: str, default = None): return getattr(self, key, default) @field_validator("userId") def validate_user_id(cls, value): if isinstance(value, int): value = str(value) if regex.match(text = value, pattern = r"^[\d]{6}$"): return value raise ValueError("userId must be 6-digits long") # ***************************************************************************************************************** # ***** **** # *** MAIN PROGRAM *** # ***** **** # ***************************************************************************************************************** if __name__ == "__main__": pass