python-termii 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,388 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-termii
3
+ Version: 0.1.0
4
+ Summary: A clean Python SDK for the Termii API (SMS, Voice, and OTP)
5
+ Author-email: Samuel Doghor Destiny <labs@amdoghor.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/samdoghor/python-termii
8
+ Project-URL: Repository, https://github.com/samdoghor/python-termii
9
+ Keywords: termii,whatsapp,sms,otp,sdk,python,library
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Requires-Python: >=3.8
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: requests
22
+ Requires-Dist: python-dotenv
23
+ Dynamic: license-file
24
+
25
+ # python-termii
26
+
27
+ A clean and lightweight Python SDK for [Termii](https://termii.com) — send SMS, WhatsApp messages, manage phonebooks,
28
+ contacts, campaigns, and more.
29
+
30
+ [![PyPI version](https://img.shields.io/pypi/v/python-termii)](https://pypi.org/project/python-termii/)
31
+ [![Python](https://img.shields.io/pypi/pyversions/python-termii)](https://pypi.org/project/python-termii/)
32
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
33
+ [![Development Status](https://img.shields.io/badge/status-alpha-orange)](https://pypi.org/project/python-termii/)
34
+
35
+ ---
36
+
37
+ ## Table of Contents
38
+
39
+ - [Installation](#installation)
40
+ - [Configuration](#configuration)
41
+ - [Services](#services)
42
+ - [Sender ID](#sender-id)
43
+ - [Messaging](#messaging)
44
+ - [Number](#number)
45
+ - [Template](#template)
46
+ - [Phonebook](#phonebook)
47
+ - [Contact](#contact)
48
+ - [Campaign](#campaign)
49
+ - [Error Handling](#error-handling)
50
+ - [Contributing](#contributing)
51
+ - [License](#license)
52
+
53
+ ---
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ pip install python-termii
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Configuration
64
+
65
+ Initialize the client with your API key and base URL. Both can be passed directly or loaded from environment variables.
66
+
67
+ ```python
68
+ from termii_py import TermiiClient
69
+
70
+ # Pass credentials directly
71
+ client = TermiiClient(api_key="YOUR_API_KEY", base_url="YOUR_BASE_URL")
72
+
73
+ # Or set environment variables and call with no arguments
74
+ client = TermiiClient()
75
+ ```
76
+
77
+ **Using a `.env` file (recommended):**
78
+
79
+ ```env
80
+ TERMII_API_KEY=your_api_key
81
+ TERMII_BASE_URL=your_base_url
82
+ ```
83
+
84
+ ```python
85
+ from termii_py import TermiiClient
86
+
87
+ client = TermiiClient()
88
+ ```
89
+
90
+ > Get your API key and base URL from your [Termii dashboard](https://app.termii.com). A `ClientConfigError` is raised if
91
+ > either value is missing.
92
+
93
+ ---
94
+
95
+ ## Services
96
+
97
+ All services are available as attributes on the `TermiiClient` instance.
98
+
99
+ ### Sender ID
100
+
101
+ **Fetch sender IDs** — optionally filter by name or status:
102
+
103
+ ```python
104
+ # Fetch all
105
+ client.sender_id.fetch_id()
106
+
107
+ # Filter by name or status
108
+ client.sender_id.fetch_id(name="MyBrand", status="approved")
109
+ ```
110
+
111
+ **Request a new sender ID:**
112
+
113
+ ```python
114
+ client.sender_id.request_id(
115
+ sender_id="MyBrand",
116
+ usecase="Transactional alerts for order confirmations",
117
+ company="Acme Ltd"
118
+ )
119
+ ```
120
+
121
+ ---
122
+
123
+ ### Messaging
124
+
125
+ **Send a single SMS:**
126
+
127
+ ```python
128
+ client.message.send_message(
129
+ sent_to="2348012345678",
130
+ sent_from="MyBrand",
131
+ message="Your order has been confirmed.",
132
+ channel="generic", # "generic", "dnd", or "voice"
133
+ type="plain"
134
+ )
135
+ ```
136
+
137
+ > For voice channel, `type` must be `"voice"`. WhatsApp messages must use `send_whatsapp_message()`.
138
+
139
+ **Send a WhatsApp message:**
140
+
141
+ ```python
142
+ # Text only
143
+ client.message.send_whatsapp_message(
144
+ sent_to="2348012345678",
145
+ sent_from="MyBrand",
146
+ message="Hello! Your appointment is confirmed."
147
+ )
148
+
149
+ # With media attachment
150
+ client.message.send_whatsapp_message(
151
+ sent_to="2348012345678",
152
+ sent_from="MyBrand",
153
+ message="Here is your receipt.",
154
+ url="https://example.com/receipt.pdf",
155
+ caption="Receipt - March 2025"
156
+ )
157
+ ```
158
+
159
+ **Send a bulk SMS:**
160
+
161
+ ```python
162
+ client.message.send_bulk_message(
163
+ sent_to=["2348012345678", "2349087654321"],
164
+ sent_from="MyBrand",
165
+ message="Our sale starts today!",
166
+ channel="generic", # "generic" or "dnd" only
167
+ type="plain"
168
+ )
169
+ ```
170
+
171
+ > Voice and WhatsApp are not supported for bulk messaging.
172
+
173
+ ---
174
+
175
+ ### Number
176
+
177
+ Send a message directly to a phone number without a sender ID:
178
+
179
+ ```python
180
+ client.number.send_message(
181
+ sent_to="2348012345678",
182
+ message="Your verification code is 123456."
183
+ )
184
+ ```
185
+
186
+ ---
187
+
188
+ ### Template
189
+
190
+ Send a message using a pre-approved WhatsApp template:
191
+
192
+ ```python
193
+ # Text template
194
+ client.template.send_message(
195
+ sent_to="2348012345678",
196
+ device_id="your-device-id",
197
+ template_id="your-template-id",
198
+ data={"studname": "Victor", "average": "30"}
199
+ )
200
+
201
+ # Media template (url and caption must be provided together)
202
+ client.template.send_message(
203
+ sent_to="2348012345678",
204
+ device_id="your-device-id",
205
+ template_id="your-template-id",
206
+ data={"name": "Victor"},
207
+ url="https://example.com/document.pdf",
208
+ caption="Course Result"
209
+ )
210
+ ```
211
+
212
+ > `device_id` is found on the Manage Device page of your Termii dashboard.
213
+
214
+ ---
215
+
216
+ ### Phonebook
217
+
218
+ **Fetch all phonebooks:**
219
+
220
+ ```python
221
+ client.phonebook.fetch_phonebooks()
222
+ ```
223
+
224
+ **Create a phonebook:**
225
+
226
+ ```python
227
+ client.phonebook.create_phonebooks(
228
+ phonebook_name="Newsletter Subscribers",
229
+ description="Users opted in for weekly updates"
230
+ )
231
+ ```
232
+
233
+ **Update a phonebook:**
234
+
235
+ ```python
236
+ client.phonebook.update_phonebook(
237
+ phonebook_id="abc123",
238
+ phonebook_name="VIP Customers",
239
+ description="High-value customer segment"
240
+ )
241
+ ```
242
+
243
+ **Delete a phonebook:**
244
+
245
+ ```python
246
+ client.phonebook.delete_phonebook(phonebook_id="abc123")
247
+ ```
248
+
249
+ ---
250
+
251
+ ### Contact
252
+
253
+ **Fetch contacts in a phonebook:**
254
+
255
+ ```python
256
+ client.contact.fetch_contacts(phonebook_id="abc123")
257
+ ```
258
+
259
+ **Add a single contact:**
260
+
261
+ ```python
262
+ client.contact.create_contact(
263
+ phonebook_id="abc123",
264
+ phone_number="8012345678",
265
+ country_code="234", # No leading "+"
266
+ first_name="Ada",
267
+ last_name="Obi",
268
+ email_address="ada@example.com",
269
+ company="Acme Ltd"
270
+ )
271
+ ```
272
+
273
+ **Add multiple contacts via CSV upload:**
274
+
275
+ ```python
276
+ client.contact.create_multiple_contacts(
277
+ phonebook_id="abc123",
278
+ country_code="234", # No leading "+"
279
+ file_path="/path/to/contacts.csv"
280
+ )
281
+ ```
282
+
283
+ **Delete all contacts in a phonebook:**
284
+
285
+ ```python
286
+ client.contact.delete_contact(phonebook_id="abc123")
287
+ ```
288
+
289
+ > ⚠️ `delete_contact` removes **all** contacts in the specified phonebook. Use with caution.
290
+
291
+ ---
292
+
293
+ ### Campaign
294
+
295
+ **Send a campaign:**
296
+
297
+ ```python
298
+ # Send immediately
299
+ client.campaign.send_campaign(
300
+ country_code="234", # No leading "+"
301
+ sender_id="MyBrand", # 3–11 characters
302
+ message="Big sale — ends tonight!",
303
+ message_type="plain", # "plain" or "unicode"
304
+ phonebook_id="abc123",
305
+ enable_link_tracking=False,
306
+ campaign_type="promotional",
307
+ schedule_sms_status="regular", # "regular" or "scheduled"
308
+ channel="dnd" # "dnd" or "generic"
309
+ )
310
+
311
+ # Schedule for later
312
+ client.campaign.send_campaign(
313
+ country_code="234",
314
+ sender_id="MyBrand",
315
+ message="Your monthly statement is ready.",
316
+ message_type="plain",
317
+ phonebook_id="abc123",
318
+ enable_link_tracking=True,
319
+ campaign_type="transactional",
320
+ schedule_sms_status="scheduled",
321
+ schedule_time="2025-12-31T23:59:00Z", # Required when schedule_sms_status is "scheduled"
322
+ channel="dnd"
323
+ )
324
+ ```
325
+
326
+ **Fetch all campaigns:**
327
+
328
+ ```python
329
+ client.campaign.fetch_campaigns()
330
+ ```
331
+
332
+ **Fetch a specific campaign's history:**
333
+
334
+ ```python
335
+ client.campaign.fetch_campaign_history(campaign_id="camp_xyz")
336
+ ```
337
+
338
+ **Retry a failed campaign:**
339
+
340
+ ```python
341
+ client.campaign.retry_campaign(campaign_id="camp_xyz")
342
+ ```
343
+
344
+ ---
345
+
346
+ ## Error Handling
347
+
348
+ The SDK validates inputs before making any network call and raises `ValueError` for invalid parameters. Wrap calls
349
+ accordingly:
350
+
351
+ ```python
352
+ try:
353
+ response = client.message.send_message(
354
+ sent_to="2348012345678",
355
+ sent_from="MyBrand",
356
+ message="Hello!",
357
+ channel="generic",
358
+ type="plain"
359
+ )
360
+ except ValueError as e:
361
+ print(f"Validation error: {e}")
362
+ except Exception as e:
363
+ print(f"Unexpected error: {e}")
364
+ ```
365
+
366
+ ---
367
+
368
+ ## Contributing
369
+
370
+ Contributions are welcome!
371
+
372
+ 1. Fork the repository
373
+ 2. Create a feature branch: `git checkout -b feature/your-feature`
374
+ 3. Commit your changes: `git commit -m "feat: describe your change"`
375
+ 4. Push: `git push origin feature/your-feature`
376
+ 5. Open a Pull Request
377
+
378
+ Please open an issue first for significant changes.
379
+
380
+ ---
381
+
382
+ ## License
383
+
384
+ This project is licensed under the [MIT License](LICENSE).
385
+
386
+ ---
387
+
388
+ Built by [Samuel Doghor](https://github.com/samdoghor) · Powered by the [Termii API](https://developer.termii.com)
@@ -0,0 +1,23 @@
1
+ python_termii-0.1.0.dist-info/licenses/LICENSE,sha256=b7acqh5qV1IWkKNwyZRWTytZ7eFj2_5UG1m8e178Rb8,1091
2
+ termii_py/__init__.py,sha256=371P5uXNLQcBi8uLGiWQphteTbWDqPU0jco8uQDswtk,388
3
+ termii_py/client.py,sha256=2OoyRENsMF2ebKqTJR9eb9wCNx8zOalwrMPwP_7wDyY,2609
4
+ termii_py/config.py,sha256=sIJFELvqthOAcO4kQ3wcXUvwa5UTS_2zta1w9ATHCWE,314
5
+ termii_py/http/__init__.py,sha256=dNBPmB1ay13NOhIusHq4F0fyo7NyXtyYPM2jLUNb_Zo,416
6
+ termii_py/http/request_handler.py,sha256=qrCsMEHRwwHZW34ObVOplj6w1INaqrYnsUhgz2XMmos,6947
7
+ termii_py/http/request_response.py,sha256=-YVjwBhRhqVkr91hZ-3WHavF75uRaJQPJNEHKrSMkXE,2108
8
+ termii_py/services/__init__.py,sha256=g3yWvS79cBh2wgaSGg-urEiJK4O64uksjQxytepAA04,714
9
+ termii_py/services/campaign.py,sha256=a-48qcZzaSebKYjyxB49lLuC1mJFm_7HfMWBdxpuAwg,10080
10
+ termii_py/services/contact.py,sha256=5GNgRDyonSEZ-goy4ZJfYA1Qkqd64MqG2zvQA-OEM1g,9082
11
+ termii_py/services/message.py,sha256=IbJS7P1nodoIrWjFtbbPE_wM1PENLnREY29pDMJUsQE,7919
12
+ termii_py/services/number.py,sha256=xWqZhdgFGnxnZ-nv1DceZuE_-hUWadna7n07rPFJPms,2653
13
+ termii_py/services/phonebook.py,sha256=bVAXaIVa_h3rrVdWj5Mr8ptt6tVkkVYkuT-YWlCZok4,6743
14
+ termii_py/services/sender_id.py,sha256=SndQSAo0Ix1UsUeH92sxwAA_9kKiPF9uBz67SQSjyRs,2233
15
+ termii_py/services/template.py,sha256=gGyA8qZLNrA4WIZ-Cb-hT7TjdjBUJhd-Gir9ZpQ3xzo,4000
16
+ termii_py/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
+ termii_py/utils/exception.py,sha256=CMmjcp4dmvh3CjBpBNTux_h42_xpwmy3UWiGdYED-QQ,227
18
+ termii_py/value_object/__init__.py,sha256=M6w20-8yAl4V_ufsAcyfng1xVnv3CWVsud_I5O_E7OA,51
19
+ termii_py/value_object/phone_number.py,sha256=2GynZLKhQlzu0k6SyiYKO2aOaHvlBCghybYhLk8b4cY,2600
20
+ python_termii-0.1.0.dist-info/METADATA,sha256=iBlvTUD0-Zafkp7mibYelk6cb_D83KtFWPLQMZ4s2iA,9178
21
+ python_termii-0.1.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
22
+ python_termii-0.1.0.dist-info/top_level.txt,sha256=TwVUsl84CnJtPudsMuFpoXgw_D_8pfNyME8GMoqIxtw,10
23
+ python_termii-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Samuel Doghor
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ termii_py
termii_py/__init__.py ADDED
@@ -0,0 +1,10 @@
1
+ """
2
+ This module provides a client for interacting with the Termii API, which allows you to send SMS messages, manage
3
+ contacts, and perform other communication-related tasks. The TermiiClient class encapsulates the functionality needed
4
+ to make API requests and handle responses effectively.
5
+ """
6
+
7
+ from .client import TermiiClient
8
+
9
+ __all__ = ["TermiiClient"]
10
+ __version__ = "0.1.0"
termii_py/client.py ADDED
@@ -0,0 +1,64 @@
1
+ """ Termii API Client Module
2
+ This module provides the main client interface for interacting with the Termii API.
3
+ """
4
+ from termii_py import config
5
+ from .http import RequestHandler
6
+ from .services import CampaignService, \
7
+ ContactService, \
8
+ MessageService, \
9
+ NumberService, \
10
+ PhonebookService, \
11
+ SenderIDService, \
12
+ TemplateService
13
+ from .utils.exception import ClientConfigError
14
+
15
+
16
+ class TermiiClient:
17
+ """ This client provides access to various Termii services including sender ID management, messaging, and other
18
+ communication features.
19
+
20
+ Args:
21
+ api_key (str, optional): Your Termii API key. If not provided, will attempt to
22
+ read from TERMII_API_KEY environment variable.
23
+ base_url (str, optional): The Termii API base URL. If not provided, will attempt
24
+ to read from TERMII_BASE_URL environment variable.
25
+
26
+ Raises:
27
+ TermiiConfigError: If api_key or base_url is not provided and cannot be found
28
+ in environment variables.
29
+
30
+ Attributes:
31
+ api_key (str): The API key used for authentication.
32
+ base_url (str): The base URL for API requests.
33
+
34
+ Example:
35
+ Using args in Termii Client (api_key & base_url):
36
+ ``client = TermiiClient(api_key="your_api_key", base_url="your_base_url")``
37
+
38
+ Or using environment variables (TERMII_API_KEY & TERMII_BASE_URL):
39
+ ``client = TermiiClient()``
40
+ """
41
+
42
+ def __init__(self, api_key: str = None, base_url: str = None):
43
+ self.api_key = api_key or config.TERMII_API_KEY
44
+ self.base_url = base_url or config.TERMII_BASE_URL
45
+ self.http = RequestHandler(self.api_key, self.base_url)
46
+ self.sender_id = SenderIDService(self.http)
47
+ self.message = MessageService(self.http)
48
+ self.number = NumberService(self.http)
49
+ self.template = TemplateService(self.http)
50
+ self.phonebook = PhonebookService(self.http)
51
+ self.contact = ContactService(self.http)
52
+ self.campaign = CampaignService(self.http)
53
+
54
+ if not self.api_key:
55
+ raise ClientConfigError(
56
+ "Missing TERMII_API_KEY. Provide via api_key parameter or TERMII_API_KEY environment variable. "
57
+ "Get your API key at: https://app.termii.com/"
58
+ )
59
+
60
+ if not self.base_url:
61
+ raise ClientConfigError(
62
+ "Missing TERMII_BASE_URL. Provide via base_url parameter or TERMII_BASE_URL environment variable. "
63
+ "Get your base url at: https://app.termii.com/"
64
+ )
termii_py/config.py ADDED
@@ -0,0 +1,12 @@
1
+ """
2
+ Environment variable loader for Termii API settings.
3
+ Loads environment variables from a .env file and sets up Termii API configuration.
4
+ """
5
+
6
+ import os
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+
11
+ TERMII_API_KEY: str = os.getenv("TERMII_API_KEY")
12
+ TERMII_BASE_URL: str = os.getenv("TERMII_BASE_URL")
@@ -0,0 +1,8 @@
1
+ """
2
+ This module contains the HTTP request handler and response classes for the Termii Python SDK. The RequestHandler class
3
+ is responsible for making HTTP requests to the Termii API, while the RequestResponse class encapsulates the response
4
+ received from the API, including status code, headers, and body content.
5
+ """
6
+
7
+ from .request_handler import RequestHandler
8
+ from .request_response import RequestResponse
@@ -0,0 +1,141 @@
1
+ """
2
+ RequestHandler class for interacting with the Termii API.
3
+ Classes:
4
+ RequestHandler
5
+ Methods:
6
+ fetch: Sends a GET request to the Termii API.
7
+ post: Sends a POST request to the Termii API.
8
+ """
9
+ import requests
10
+
11
+ from .request_response import RequestResponse
12
+
13
+
14
+ class RequestHandler:
15
+ """
16
+ Initializes a RequestHandler instance.
17
+
18
+ Attributes:
19
+ api_key (str): The API key for authentication.
20
+ base_url (str): The base URL of the Termii API.
21
+ """
22
+
23
+ def __init__(self, api_key, base_url):
24
+ self.api_key = api_key
25
+ self.base_url = base_url.rstrip("/")
26
+
27
+ def fetch(self, endpoint, params=None):
28
+ """
29
+ Sends a GET request to the Termii API.
30
+
31
+ Args:
32
+ endpoint (str): The endpoint to query.
33
+ params (dict, optional): Query parameters. Defaults to None.
34
+
35
+ Returns:
36
+ RequestResponse: The response from the API.
37
+ """
38
+
39
+ params = params or {}
40
+ params["api_key"] = self.api_key
41
+ response = requests.get(f"{self.base_url}{endpoint}", params=params)
42
+
43
+ return RequestResponse.handle_response(response)
44
+
45
+ def post(self, endpoint, json: dict):
46
+ """
47
+ Sends a POST request to the Termii API.
48
+
49
+ Args:
50
+ endpoint (str): The endpoint to query.
51
+ json (dict): The JSON payload.
52
+
53
+ Returns:
54
+ RequestResponse: The response from the API.
55
+ """
56
+
57
+ json["api_key"] = self.api_key
58
+ response = requests.post(f"{self.base_url}{endpoint}", json=json)
59
+
60
+ return RequestResponse.handle_response(response)
61
+
62
+ def patch(self, endpoint, json: dict):
63
+ """
64
+ Sends a PATCH request to the Termii API. This method is used for updating existing resources on the Termii platform.
65
+ The `endpoint` parameter specifies the API endpoint to which the request will be sent, while the `json`
66
+ parameter contains the data to be updated in JSON format. The method automatically includes the API key for
67
+ authentication in the request payload. The response from the API is processed and returned as a
68
+ `RequestResponse` object, which encapsulates the status and data of the API response.
69
+
70
+ Args:
71
+ endpoint (str): The API endpoint to which the PATCH request will be sent (e.g., "/api/phonebooks/{phonebook_id}").
72
+ json (dict): A dictionary containing the data to be updated, which will be sent as a JSON payload in the
73
+ request body. This should include the fields that need to be updated along with their new values.
74
+
75
+ Returns:
76
+ RequestResponse: An object representing the response from the Termii API, which includes the status code,
77
+ response data, and any relevant metadata. The `RequestResponse` class is responsible for handling the
78
+ parsing and interpretation of the API response, allowing for consistent error handling and data extraction
79
+ across different API endpoints.
80
+ """
81
+
82
+ json["api_key"] = self.api_key
83
+ response = requests.patch(f"{self.base_url}{endpoint}", json=json)
84
+
85
+ return RequestResponse.handle_response(response)
86
+
87
+ def delete(self, endpoint, params=None):
88
+ """
89
+ Sends a DELETE request to the Termii API. This method is used for deleting resources from the Termii platform.
90
+ The `endpoint` parameter specifies the API endpoint to which the request will be sent, while the `params`
91
+ parameter contains any query parameters that need to be included in the request URL. The method automatically
92
+ includes the API key for authentication in the query parameters. The response from the API is processed and
93
+ returned as a `RequestResponse` object, which encapsulates the status and data of the API response.
94
+
95
+ Args:
96
+ endpoint (str): The API endpoint to which the DELETE request will be sent (e.g., "/api/phonebooks/{phonebook_id}").
97
+ params (dict, optional): A dictionary of query parameters to be included in the request URL. This can include
98
+ any additional parameters required by the API endpoint, such as filters or identifiers. If no parameters are needed, this can be left as None.
99
+
100
+ Returns:
101
+ RequestResponse: An object representing the response from the Termii API, which includes the status code,
102
+ response data, and any relevant metadata. The `RequestResponse` class is responsible for handling the
103
+ parsing and interpretation of the API response, allowing for consistent error handling and data extraction
104
+ across different API endpoints.
105
+ """
106
+
107
+ params = params or {}
108
+ params["api_key"] = self.api_key
109
+ response = requests.delete(f"{self.base_url}{endpoint}", params=params)
110
+
111
+ return RequestResponse.handle_response(response)
112
+
113
+ def post_file(self, endpoint, file_path: str, data: dict):
114
+ """
115
+ Sends a POST request to the Termii API with a file upload. This method is used for endpoints that require file
116
+ uploads, such as creating multiple contacts from a CSV file. The `endpoint` parameter specifies the API
117
+ endpoint to which the request will be sent, while the `file_path` parameter specifies the local path to the
118
+ file that needs to be uploaded. The `data` parameter contains any additional form data that needs to be
119
+ included in the request body. The method automatically includes the API key for authentication in the form
120
+ data. The response from the API is processed and returned as a `RequestResponse` object, which encapsulates
121
+ the status and data of the API response.
122
+
123
+ Args:
124
+ endpoint (str): The API endpoint to which the POST request will be sent (e.g., "/api/contacts/upload").
125
+ file_path (str): The local file path of the file to be uploaded (e.g., "C:/path/to/contacts.csv").
126
+ data (dict): A dictionary containing any additional form data to be included in the request body. This can include
127
+ fields such as "country_code" or "phonebook_id" that are required by the API endpoint.
128
+
129
+ Returns:
130
+ RequestResponse: An object representing the response from the Termii API, which includes the status code,
131
+ response data, and any relevant metadata. The `RequestResponse` class is responsible for handling the
132
+ parsing and interpretation of the API response, allowing for consistent error handling and data extraction
133
+ across different API endpoints.
134
+ """
135
+
136
+ data["api_key"] = self.api_key
137
+
138
+ files = {"file": open(file_path, "rb")}
139
+ response = requests.post(f"{self.base_url}{endpoint}", files=files, data=data)
140
+
141
+ return RequestResponse.handle_response(response)