11# SDK Usage Guide
22
3- Welcome to the SDK Usage Guide for the ** messaging-sdk** . This guide will walk you through the installation, configuration , and practical usage of the SDK, providing detailed examples and instructions for integrating the SDK into your applications .
3+ Welcome to the ** messaging-sdk** SDK Usage Guide . This document provides detailed instructions for installing, configuring , and utilizing the SDK, including advanced features and best practices .
44
55---
66
@@ -13,90 +13,114 @@ Welcome to the SDK Usage Guide for the **messaging-sdk**. This guide will walk y
1313 - [ Sending Messages] ( #sending-messages )
1414 - [ Managing Contacts] ( #managing-contacts )
15155 . [ Advanced Usage] ( #advanced-usage )
16+ - [ Pagination] ( #pagination )
17+ - [ Retry Mechanism] ( #retry-mechanism )
16186 . [ Error Handling] ( #error-handling )
17197 . [ Testing] ( #testing )
18208 . [ Logging] ( #logging )
21+ 9 . [ Complete Functionalities] ( #complete-functionalities )
1922
2023---
2124
2225## Introduction
2326
24- The ` messaging-sdk ` is a Python library designed to simplify interactions with the messaging and contacts API. The SDK provides:
27+ The ` messaging-sdk ` is a Python library designed for seamless integration with messaging and contacts APIs. It provides:
2528
26- - Simplified API interactions without requiring manual configuration of authentication headers .
27- - IDE-friendly auto-completion for seamless development .
28- - Robust retry mechanisms for handling transient errors .
29- - Built-in validation to ensure API requests meet expected formats .
29+ - Simplified API interactions with minimal setup .
30+ - Robust error handling and retry mechanisms .
31+ - Logging for debugging and monitoring .
32+ - Easy-to-use methods for sending messages and managing contacts .
3033
3134---
3235
3336## Installation
3437
35- To install the SDK, use ` pip ` :
38+ To install the SDK locally :
3639
37- ``` bash
38- pip install -r requirements.txt
39- ```
40+ 1 . Clone the repository:
41+
42+ ``` bash
43+ git clone https://github.com/shiningflash/messaging-sdk.git
44+ cd messaging-sdk
45+ ```
46+
47+ 2. Install additional dependencies if required:
48+
49+ ` ` ` bash
50+ pip install -r requirements.txt
51+ ` ` `
4052
4153---
4254
4355# # Configuration
4456
45- 1 . Copy the ` .env.example ` file to ` .env ` in the root directory :
57+ 1. Copy the ` .env.example` file and rename it to ` .env` :
4658
4759 ` ` ` bash
4860 cp .env.example .env
4961 ` ` `
5062
51- 2. Open ` .env` and update the variables accordingly.
63+ 2. Open ` .env` and configure the following variables:
64+
65+ - ` BASE_URL` : Base URL for the API (e.g., ` http://localhost:3000` ).
66+ - ` API_KEY` : Your API key for authentication.
67+ - ` WEBHOOK_SECRET` : Secret key for validating webhooks.
68+
69+ Install the SDK using pip in editable mode:
70+
71+ ` ` ` bash
72+ pip install -e .
73+ ` ` `
5274
5375---
5476
5577# # Basic Usage
5678
5779# ## Sending Messages
5880
59- The SDK provides a straightforward way to send messages:
81+ The SDK allows you to send messages easily :
6082
6183` ` ` python
62- from src. sdk.features.messages import Messages
63- from src. sdk.client import ApiClient
84+ from sdk.client import ApiClient
85+ from sdk.features.messages import Messages
6486
6587client = ApiClient ()
6688messages = Messages(client)
6789
6890# Prepare the payload
6991payload = {
70- " to" : " +123456789 " ,
92+ " to" : { " id " : " contact-id " }, # Contact ID
7193 " content" : " Hello, world!" ,
72- " sender " : " +987654321 "
94+ " from " : " +9876543210 " # Sender's phone number
7395}
7496
7597# Send the message
7698response = messages.send_message(payload=payload)
99+ print(response)
77100` ` `
78101
79102# ## Managing Contacts
80103
81- You can create, list, and delete contacts using the SDK :
104+ You can create, list, and delete contacts:
82105
83106` ` ` python
84- from src. sdk.features.contacts import Contacts
107+ from sdk.features.contacts import Contacts
85108
86109contacts = Contacts(client)
87110
88111# Create a new contact
89112new_contact = {
90113 " name" : " John Doe" ,
91- " phone" : " +123456789 "
114+ " phone" : " +1234567890 "
92115}
93116response = contacts.create_contact(new_contact)
94117
95118# List all contacts
96- contacts_list = contacts.list_contacts ()
119+ contacts_list = contacts.list_contacts(page=1, max=5)
120+ print(contacts_list)
97121
98122# Delete a contact
99- contacts.delete_contact(contact_id=" contact123 " )
123+ contacts.delete_contact(contact_id=" contact-id " )
100124` ` `
101125
102126---
@@ -105,55 +129,57 @@ contacts.delete_contact(contact_id="contact123")
105129
106130# ## Pagination
107131
108- Retrieve paginated lists for messages or contacts:
132+ The SDK supports pagination for listing messages and contacts:
109133
110134` ` ` python
111135# Retrieve paginated messages
112- messages_list = messages.list_messages(page=1, limit=5 )
136+ messages_list = messages.list_messages(page=1, limit=10 )
113137print(messages_list)
114138
115139# Retrieve paginated contacts
116140contacts_list = contacts.list_contacts(page=1, max=5)
117141print(contacts_list)
118142` ` `
119143
120- # ## Retry Mechanisms
144+ # ## Retry Mechanism
121145
122- The SDK automatically retries failed requests for transient errors (e.g., `503 Service Unavailable` ). You can customize retry logic in the ` src/sdk/utils/ retry.py` module .
146+ The SDK automatically retries requests for transient errors (e.g., HTTP 503 ). The retry logic is located in ` src/core/ retry.py` and can be customized .
123147
124148---
125149
126150# # Error Handling
127151
128- The SDK raises specific exceptions for various error scenarios:
152+ The SDK provides built-in exceptions for various scenarios:
129153
130- - ` UnauthorizedError` : Raised for ` 401 Unauthorized` responses.
131- - ` NotFoundError` : Raised for ` 404 Not Found` responses.
132- - ` ServerError` : Raised for ` 500 Internal Server Error` responses.
133- - ` ApiError` : Raised for other unexpected API errors.
154+ - ` UnauthorizedError` : Raised for authentication errors (` 401 Unauthorized` ).
155+ - ` NotFoundError` : Raised when a resource is not found (` 404 Not Found` ).
156+ - ` ServerError` : Raised for server-side errors (` 500 Internal Server Error` ).
157+ - ` ContactNotFoundError` : Raised for missing contacts.
158+ - ` MessageNotFoundError` : Raised for missing messages.
159+ - ` ApiError` : Raised for other API-related issues.
134160
135161Example:
136162
137163` ` ` python
138164try:
139- messages.list_messages ( )
140- except UnauthorizedError as e:
141- print(f" Authentication failed : {e}" )
165+ messages.get_message( " invalid-id " )
166+ except MessageNotFoundError as e:
167+ print(f" Message not found : {e}" )
142168except ApiError as e:
143- print(f" Unexpected error : {e}" )
169+ print(f" API Error : {e}" )
144170` ` `
145171
146172---
147173
148174# # Testing
149175
150- The SDK includes unit, integration, and end-to-end tests. To run all tests :
176+ Run tests using ` pytest ` :
151177
152178` ` ` bash
153179pytest
154180` ` `
155181
156- To generate a coverage report :
182+ To check code coverage:
157183
158184` ` ` bash
159185pytest --cov=src --cov-report=term-missing
@@ -163,15 +189,31 @@ pytest --cov=src --cov-report=term-missing
163189
164190# # Logging
165191
166- The SDK includes comprehensive logging for debugging and auditing. Logs are categorized as follows :
192+ Logs provide detailed insights into SDK operations :
167193
168- - ** Console Logs** : Informational and error logs for immediate feedback .
169- - ** File Logs** : Warnings and errors logged to ` logs/app.log` .
194+ - ** Console Logs** : Informational logs for debugging .
195+ - ** File Logs** : Errors and warnings logged to ` logs/app.log` .
170196
171- Example of enabling logger in your application :
197+ Example:
172198
173199` ` ` python
174- from src .core.logger import logger
200+ from sdk .core.logger import logger
175201
176- logger.info(" Application started ." )
202+ logger.info(" Starting application.. ." )
177203` ` `
204+
205+ ---
206+
207+ # # Complete Functionalities
208+
209+ # ## Messages
210+
211+ - ** Send Message** : ` send_message(payload)`
212+ - ** List Messages** : ` list_messages(page, limit)`
213+ - ** Get Message by ID** : ` get_message(message_id)`
214+
215+ # ## Contacts
216+
217+ - ** Create Contact** : ` create_contact(contact_payload)`
218+ - ** List Contacts** : ` list_contacts(page, max)`
219+ - ** Delete Contact** : ` delete_contact(contact_id)`
0 commit comments