-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add conversion method, SMS tests, refactoring
- Loading branch information
Showing
24 changed files
with
251 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# 0.1.0 | ||
- Initial upload | ||
# 1.0.0 | ||
- Initial upload | ||
|
||
# 1.1.0 | ||
- Add support for signature authentication |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 1.0.0 | ||
- Initial upload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,24 @@ | ||
# Vonage SMS Package | ||
|
||
This package contains the code to use Vonage's SMS API with Python. | ||
This package contains the code to use Vonage's SMS API in Python. | ||
|
||
It includes a method for sending SMS messages and returns an `SmsResponse` class to handle the response. | ||
|
||
## Usage | ||
|
||
It is recommended to use this as part of the main `vonage` package. The examples below assume you've created an instance of the `vonage.Vonage` class called `vonage_client`. | ||
|
||
### Send an SMS | ||
|
||
Create an `SmsMessage` object, then pass into the `Sms.send` method. | ||
|
||
```python | ||
from vonage_sms import SmsMessage, SmsResponse | ||
|
||
message = SmsMessage(to='1234567890', from_='Acme Inc.', text='Hello, World!') | ||
response: SmsResponse = vonage_client.sms.send(message) | ||
|
||
print(response.model_dump(exclude_unset=True)) | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
from .errors import PartialFailureError, SmsError | ||
from .requests import SmsMessage | ||
from .responses import MessageResponse, SmsResponse | ||
from .sms import Sms | ||
|
||
__all__ = [ | ||
'Sms', | ||
'SmsMessage', | ||
'SmsResponse', | ||
'MessageResponse', | ||
'SmsError', | ||
'PartialFailureError', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
from dataclasses import dataclass | ||
from typing import List, Optional | ||
|
||
from pydantic import BaseModel, Field, field_validator | ||
|
||
@dataclass | ||
class MessageResponse: | ||
|
||
class MessageResponse(BaseModel): | ||
to: str | ||
message_id: str | ||
message_id: str = Field(..., validation_alias='message-id') | ||
status: str | ||
remaining_balance: str | ||
message_price: str | ||
remaining_balance: str = Field(..., validation_alias='remaining-balance') | ||
message_price: str = Field(..., validation_alias='message-price') | ||
network: str | ||
client_ref: Optional[str] = None | ||
account_ref: Optional[str] = None | ||
client_ref: Optional[str] = Field(None, validation_alias='client-ref') | ||
account_ref: Optional[str] = Field(None, validation_alias='account-ref') | ||
|
||
|
||
class SmsResponse(BaseModel): | ||
message_count: str = Field(..., validation_alias='message-count') | ||
messages: List[dict] | ||
|
||
@dataclass | ||
class SmsResponse: | ||
message_count: str | ||
messages: List[MessageResponse] | ||
@field_validator('messages') | ||
@classmethod | ||
def create_message_response(cls, value): | ||
messages = [] | ||
for message in value: | ||
messages.append(MessageResponse(**message)) | ||
return messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/> | ||
<title>Error 402 </title> | ||
</head> | ||
<body> | ||
<h2>HTTP ERROR: 402</h2> | ||
<p>Problem accessing /conversions/sms. Reason: | ||
<pre> Bad Account Credentials</pre></p> | ||
<hr /><i><small>Powered by Jetty://</small></i> | ||
</body> | ||
</html> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
{} | ||
{ | ||
"message-count": "1", | ||
"messages": [ | ||
{ | ||
"to": "1234567890", | ||
"message-id": "3295d748-4e14-4681-af78-166dca3c5aab", | ||
"status": "0", | ||
"remaining-balance": "38.07243628", | ||
"message-price": "0.04120000", | ||
"network": "23420" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"message-count": "1", | ||
"messages": [ | ||
{ | ||
"status": "7", | ||
"error-text": "Number barred." | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"message-count": "2", | ||
"messages": [ | ||
{ | ||
"to": "1234567890", | ||
"message-id": "3295d748-4e14-4681-af78-166dca3c5aab", | ||
"status": "0", | ||
"remaining-balance": "38.07243628", | ||
"message-price": "0.04120000", | ||
"network": "23420" | ||
}, | ||
{ | ||
"status": "1", | ||
"error-text": "Throttled" | ||
} | ||
] | ||
} |
Oops, something went wrong.