1
1
# SDK Usage Guide
2
2
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 .
4
4
5
5
---
6
6
@@ -13,90 +13,114 @@ Welcome to the SDK Usage Guide for the **messaging-sdk**. This guide will walk y
13
13
- [ Sending Messages] ( #sending-messages )
14
14
- [ Managing Contacts] ( #managing-contacts )
15
15
5 . [ Advanced Usage] ( #advanced-usage )
16
+ - [ Pagination] ( #pagination )
17
+ - [ Retry Mechanism] ( #retry-mechanism )
16
18
6 . [ Error Handling] ( #error-handling )
17
19
7 . [ Testing] ( #testing )
18
20
8 . [ Logging] ( #logging )
21
+ 9 . [ Complete Functionalities] ( #complete-functionalities )
19
22
20
23
---
21
24
22
25
## Introduction
23
26
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:
25
28
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 .
30
33
31
34
---
32
35
33
36
## Installation
34
37
35
- To install the SDK, use ` pip ` :
38
+ To install the SDK locally :
36
39
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
+ ` ` `
40
52
41
53
---
42
54
43
55
# # Configuration
44
56
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` :
46
58
47
59
` ` ` bash
48
60
cp .env.example .env
49
61
` ` `
50
62
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
+ ` ` `
52
74
53
75
---
54
76
55
77
# # Basic Usage
56
78
57
79
# ## Sending Messages
58
80
59
- The SDK provides a straightforward way to send messages:
81
+ The SDK allows you to send messages easily :
60
82
61
83
` ` ` 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
64
86
65
87
client = ApiClient ()
66
88
messages = Messages(client)
67
89
68
90
# Prepare the payload
69
91
payload = {
70
- " to" : " +123456789 " ,
92
+ " to" : { " id " : " contact-id " }, # Contact ID
71
93
" content" : " Hello, world!" ,
72
- " sender " : " +987654321 "
94
+ " from " : " +9876543210 " # Sender's phone number
73
95
}
74
96
75
97
# Send the message
76
98
response = messages.send_message(payload=payload)
99
+ print(response)
77
100
` ` `
78
101
79
102
# ## Managing Contacts
80
103
81
- You can create, list, and delete contacts using the SDK :
104
+ You can create, list, and delete contacts:
82
105
83
106
` ` ` python
84
- from src. sdk.features.contacts import Contacts
107
+ from sdk.features.contacts import Contacts
85
108
86
109
contacts = Contacts(client)
87
110
88
111
# Create a new contact
89
112
new_contact = {
90
113
" name" : " John Doe" ,
91
- " phone" : " +123456789 "
114
+ " phone" : " +1234567890 "
92
115
}
93
116
response = contacts.create_contact(new_contact)
94
117
95
118
# List all contacts
96
- contacts_list = contacts.list_contacts ()
119
+ contacts_list = contacts.list_contacts(page=1, max=5)
120
+ print(contacts_list)
97
121
98
122
# Delete a contact
99
- contacts.delete_contact(contact_id=" contact123 " )
123
+ contacts.delete_contact(contact_id=" contact-id " )
100
124
` ` `
101
125
102
126
---
@@ -105,55 +129,57 @@ contacts.delete_contact(contact_id="contact123")
105
129
106
130
# ## Pagination
107
131
108
- Retrieve paginated lists for messages or contacts:
132
+ The SDK supports pagination for listing messages and contacts:
109
133
110
134
` ` ` python
111
135
# Retrieve paginated messages
112
- messages_list = messages.list_messages(page=1, limit=5 )
136
+ messages_list = messages.list_messages(page=1, limit=10 )
113
137
print(messages_list)
114
138
115
139
# Retrieve paginated contacts
116
140
contacts_list = contacts.list_contacts(page=1, max=5)
117
141
print(contacts_list)
118
142
` ` `
119
143
120
- # ## Retry Mechanisms
144
+ # ## Retry Mechanism
121
145
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 .
123
147
124
148
---
125
149
126
150
# # Error Handling
127
151
128
- The SDK raises specific exceptions for various error scenarios:
152
+ The SDK provides built-in exceptions for various scenarios:
129
153
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.
134
160
135
161
Example:
136
162
137
163
` ` ` python
138
164
try:
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}" )
142
168
except ApiError as e:
143
- print(f" Unexpected error : {e}" )
169
+ print(f" API Error : {e}" )
144
170
` ` `
145
171
146
172
---
147
173
148
174
# # Testing
149
175
150
- The SDK includes unit, integration, and end-to-end tests. To run all tests :
176
+ Run tests using ` pytest ` :
151
177
152
178
` ` ` bash
153
179
pytest
154
180
` ` `
155
181
156
- To generate a coverage report :
182
+ To check code coverage:
157
183
158
184
` ` ` bash
159
185
pytest --cov=src --cov-report=term-missing
@@ -163,15 +189,31 @@ pytest --cov=src --cov-report=term-missing
163
189
164
190
# # Logging
165
191
166
- The SDK includes comprehensive logging for debugging and auditing. Logs are categorized as follows :
192
+ Logs provide detailed insights into SDK operations :
167
193
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` .
170
196
171
- Example of enabling logger in your application :
197
+ Example:
172
198
173
199
` ` ` python
174
- from src .core.logger import logger
200
+ from sdk .core.logger import logger
175
201
176
- logger.info(" Application started ." )
202
+ logger.info(" Starting application.. ." )
177
203
` ` `
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