11import sys
22import requests
33from base64 import b64encode
4- from typing import List , Dict , Union
54from collections import namedtuple
5+ from typing import List , Dict , Union , Iterable
66
77
88class NextSms (object ):
99
10- BASE_URL_SINGLE = 'https://messaging-service.co.tz/api/sms/v1/test/text/single'
11- BASE_URL_MULTIPLE = 'https://messaging-service.co.tz/api/sms/v1/test/text/multi'
10+ SANDBOX_URL_SINGLE = 'https://messaging-service.co.tz/api/sms/v1/test/text/single'
11+ SANDBOX_URL_MULTIPLE = 'https://messaging-service.co.tz/api/sms/v1/test/text/multi'
12+ PRODUCTION_URL_SINGLE = 'https://messaging-service.co.tz/api/sms/v1/text/single'
13+ PRODUCTION_URL_MULTIPLE = 'https://messaging-service.co.tz/api/sms/v1/text/multi'
1214
15+ _sandbox = False
1316 User = namedtuple ('User' , 'username password secret_key' )
1417
15- def __init__ (self , username : str = '' , password : str = '' ) -> None :
18+ def __init__ (self , username : str = '' , password : str = '' , sandbox = False ) -> None :
1619 """Initialize nextsms access credentials
1720
1821 Args:
1922 username (str): your username for nextsms
2023 password (str): your login password for nextsms
2124 """
25+ self .sandbox = sandbox
2226 self ._user = (None
2327 if not all (username and password )
2428 else self .create_user (username , password ))
2529
30+ @property
31+ def sandbox (self ) -> bool :
32+ """Return the state of the sandbox environment whether its active or inactive
33+
34+ Returns:
35+ bool: True if sandbox environment is active, False if not
36+ """
37+ return self ._sandbox
38+
39+ @sandbox .setter
40+ def sandbox (self , is_active : bool ) -> None :
41+ """Set sandbox environment to active or inactive
42+
43+ Args:
44+ is_active (bool): State of the sandbox environment (True|False)
45+
46+ Raises:
47+ TypeError: If is_active is not of <class 'bool'>
48+
49+ Example:
50+ >> import nextsms
51+ >> sender = nextsms('KalebuJordan', 'kalebu@opensource')
52+ >> sender.sandbox = True
53+ """
54+ if not isinstance (is_active , bool ):
55+ raise TypeError (
56+ f"sandbox should of of type <class 'bool'> not { type (is_active )} " )
57+
58+ if is_active :
59+ self .base_url_single = self .SANDBOX_URL_SINGLE
60+ self .base_url_multiple = self .SANDBOX_URL_MULTIPLE
61+ else :
62+ self .base_url_single = self .PRODUCTION_URL_SINGLE
63+ self .base_url_multiple = self .PRODUCTION_URL_MULTIPLE
64+
2665 def initialize (self , username : str , password : str ) -> None :
2766 """Initialize nextsms access credentials
2867
@@ -32,7 +71,7 @@ def initialize(self, username: str, password: str) -> None:
3271 """
3372 self ._user = self .create_user (username , password )
3473
35- def create_user (self , username : str , password : str ) -> User :
74+ def create_user (self , username : str , password : str ) -> Iterable :
3675 """Create a namedtuple of user credentials
3776
3877 Args:
0 commit comments