-
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.
- Loading branch information
Showing
11 changed files
with
161 additions
and
223 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
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,54 @@ | ||
from typing import Literal, Optional | ||
|
||
from pydantic import ( | ||
BaseModel, | ||
Field, | ||
ValidationInfo, | ||
field_validator, | ||
model_validator, | ||
) | ||
|
||
|
||
class SmsMessage(BaseModel): | ||
"""Message object containing the data and options for an SMS message.""" | ||
|
||
to: str | ||
from_: str = Field(..., serialization_alias='from') | ||
text: str | ||
sig: Optional[str] = Field(None, min_length=16, max_length=60) | ||
client_ref: Optional[str] = Field( | ||
None, serialization_alias='client-ref', max_length=100 | ||
) | ||
type: Optional[Literal['text', 'binary', 'unicode']] = None | ||
ttl: Optional[int] = Field(None, ge=20000, le=604800000) | ||
status_report_req: Optional[bool] = Field( | ||
None, serialization_alias='status-report-req' | ||
) | ||
callback: Optional[str] = Field(None, max_length=100) | ||
message_class: Optional[int] = Field( | ||
None, serialization_alias='message-class', ge=0, le=3 | ||
) | ||
body: Optional[str] = None | ||
udh: Optional[str] = None | ||
protocol_id: Optional[int] = Field( | ||
None, serialization_alias='protocol-id', ge=0, le=255 | ||
) | ||
account_ref: Optional[str] = Field(None, serialization_alias='account-ref') | ||
entity_id: Optional[str] = Field(None, serialization_alias='entity-id') | ||
content_id: Optional[str] = Field(None, serialization_alias='content-id') | ||
|
||
@field_validator('body', 'udh') | ||
@classmethod | ||
def validate_body(cls, value, info: ValidationInfo): | ||
data = info.data | ||
if 'type' not in data or not data['type'] == 'binary': | ||
raise ValueError( | ||
'This parameter can only be set when the "type" parameter is set to "binary".' | ||
) | ||
return value | ||
|
||
@model_validator(mode='after') | ||
def validate_type(self) -> 'SmsMessage': | ||
if self.type == 'binary' and self.body is None and self.udh is None: | ||
raise ValueError('This parameter is required for binary messages.') | ||
return self |
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,20 @@ | ||
from dataclasses import dataclass | ||
from typing import List, Optional | ||
|
||
|
||
@dataclass | ||
class MessageResponse: | ||
to: str | ||
message_id: str | ||
status: str | ||
remaining_balance: str | ||
message_price: str | ||
network: str | ||
client_ref: Optional[str] = None | ||
account_ref: Optional[str] = None | ||
|
||
|
||
@dataclass | ||
class SmsResponse: | ||
message_count: str | ||
messages: List[MessageResponse] |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
{} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.