Skip to content

Commit 035c3c8

Browse files
committed
Use logger instead of print
1 parent 2b2cd0e commit 035c3c8

File tree

7 files changed

+27
-38
lines changed

7 files changed

+27
-38
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ import contiguity
2121
client = contiguity.login("your_token_here")
2222
```
2323

24-
You can also initialize it with the optional 'debug' flag:
25-
26-
```js
27-
client = contiguity.login("your_token_here", True)
28-
```
29-
3024
You can get your token from the Contiguity [dashboard](https://contiguity.co/dashboard).
3125

3226
## Sending your first email 📤

src/contiguity/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from ._client import ApiClient
22
from .email import Email
3+
from .imessage import IMessage
34
from .otp import OTP
45
from .text import Text
6+
from .whatsapp import WhatsApp
57

68

79
class Contiguity:
@@ -10,33 +12,34 @@ class Contiguity:
1012
1113
Args:
1214
token (str): The authentication token.
13-
debug (bool, optional): A flag indicating whether to enable debug mode. Default is False.
1415
"""
1516

1617
def __init__(
1718
self,
1819
*,
1920
token: str,
2021
base_url: str = "https://api.contiguity.com",
21-
debug: bool = False,
2222
) -> None:
2323
if not token:
2424
msg = "token cannot be empty"
2525
raise ValueError(msg)
2626
self.token = token
2727
self.base_url = base_url
28-
self.debug = debug
2928
self.client = ApiClient(base_url=self.base_url, api_key=token.strip())
3029

31-
self.text = Text(client=self.client, debug=self.debug)
32-
self.email = Email(client=self.client, debug=self.debug)
33-
self.otp = OTP(client=self.client, debug=self.debug)
30+
self.text = Text(client=self.client)
31+
self.email = Email(client=self.client)
32+
self.otp = OTP(client=self.client)
33+
self.imessage = IMessage(client=self.client)
34+
self.whatsapp = WhatsApp(client=self.client)
3435

3536

3637
__all__ = (
3738
"OTP",
3839
"Contiguity",
3940
"Email",
41+
"IMessage",
4042
"Text",
43+
"WhatsApp",
4144
)
4245
__version__ = "3.0.0"

src/contiguity/_instant_messaging.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ def send( # noqa: PLR0913
6363
raise ValueError(msg)
6464

6565
data = decode_response(response.content, type=IMSendResponse)
66-
if self.debug:
67-
logger.debug(f"successfully sent {self._api_path[1:]} message to {to}")
68-
66+
logger.debug("successfully sent %s message to %r", self._api_path[1:], to)
6967
return data
7068

7169
def _typing(self, *, to: str, action: Literal["start", "stop"], from_: str | None = None) -> IMTypingResponse:
@@ -86,9 +84,7 @@ def _typing(self, *, to: str, action: Literal["start", "stop"], from_: str | Non
8684
raise ValueError(msg)
8785

8886
data = decode_response(response.content, type=IMTypingResponse)
89-
if self.debug:
90-
logger.debug(f"successfully {action} {self._api_path[1:]} typing indicator for {to}")
91-
87+
logger.debug("successfully %s %s typing indicator for %r", action, self._api_path[1:], to)
9288
return data
9389

9490
def start_typing(self, *, to: str, from_: str | None = None) -> IMTypingResponse:
@@ -123,9 +119,7 @@ def _reactions(
123119
raise ValueError(msg)
124120

125121
data = decode_response(response.content, type=IMReactionResponse)
126-
if self.debug:
127-
logger.debug(f"successfully {action} {self._api_path[1:]} reaction for {to}")
128-
122+
logger.debug("successfully %s %s reaction for %r", action, self._api_path[1:], to)
129123
return data
130124

131125
def add_reaction(self, *, to: str, reaction: str, message: str) -> IMReactionResponse:

src/contiguity/_product.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33

44
class BaseProduct:
5-
def __init__(self, *, client: ApiClient, debug: bool = False) -> None:
5+
def __init__(self, *, client: ApiClient) -> None:
66
self._client = client
7-
self.debug = debug

src/contiguity/email.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from __future__ import annotations
22

3+
import logging
34
from http import HTTPStatus
45
from typing import overload
56

67
from ._product import BaseProduct
78
from ._response import BaseResponse, ErrorResponse, decode_response
89

10+
logger = logging.getLogger(__name__)
11+
912

1013
class EmailResponse(BaseResponse):
1114
message: str
@@ -86,7 +89,5 @@ def email( # noqa: PLR0913
8689
raise ValueError(msg)
8790

8891
data = decode_response(response.content, type=EmailResponse)
89-
if self.debug:
90-
print(f"successfully sent email to {to}")
91-
92+
logger.debug("successfully sent email to %r", to)
9293
return data

src/contiguity/otp.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import logging
34
from enum import Enum
45
from http import HTTPStatus
56

@@ -8,6 +9,8 @@
89
from ._product import BaseProduct
910
from ._response import BaseResponse, ErrorResponse, decode_response
1011

12+
logger = logging.getLogger(__name__)
13+
1114

1215
class OTPLanguage(str, Enum):
1316
ENGLISH = "en"
@@ -86,9 +89,7 @@ def send(
8689
raise ValueError(msg)
8790

8891
data = decode_response(response.content, type=OTPSendResponse)
89-
if self.debug:
90-
print(f"successfully sent OTP {data.otp_id} to {to}")
91-
92+
logger.debug("successfully sent OTP %r to %r", data.otp_id, to)
9293
return data
9394

9495
def resend(self, otp_id: str, /) -> OTPResendResponse:
@@ -105,9 +106,7 @@ def resend(self, otp_id: str, /) -> OTPResendResponse:
105106
raise ValueError(msg)
106107

107108
data = decode_response(response.content, type=OTPResendResponse)
108-
if self.debug:
109-
print(f"successfully resent OTP {otp_id} with status: {data.resent}")
110-
109+
logger.debug("successfully resent OTP %r with status: %r", otp_id, data.resent)
111110
return data
112111

113112
def verify(self, otp: int | str, /, *, otp_id: str) -> OTPVerifyResponse:
@@ -125,7 +124,5 @@ def verify(self, otp: int | str, /, *, otp_id: str) -> OTPVerifyResponse:
125124
raise ValueError(msg)
126125

127126
data = decode_response(response.content, type=OTPVerifyResponse)
128-
if self.debug:
129-
print(f"successfully verified OTP ({otp}) with status: {data.verified}")
130-
127+
logger.debug("successfully verified OTP %r with status: %r", otp_id, data.verified)
131128
return data

src/contiguity/text.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import logging
12
from http import HTTPStatus
23

34
import phonenumbers
45

56
from ._product import BaseProduct
67
from ._response import BaseResponse, ErrorResponse, decode_response
78

9+
logger = logging.getLogger(__name__)
10+
811

912
class TextResponse(BaseResponse):
1013
message_id: str
@@ -45,7 +48,5 @@ def send(self, *, to: str, message: str) -> TextResponse:
4548
raise ValueError(msg)
4649

4750
data = decode_response(response.content, type=TextResponse)
48-
if self.debug:
49-
print(f"successfully sent text to {to}")
50-
51+
logger.debug("successfully sent text to %r", to)
5152
return data

0 commit comments

Comments
 (0)