-
Notifications
You must be signed in to change notification settings - Fork 20
Add sms channel #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sms channel #65
Conversation
infobip_channels/core/models.py
Outdated
|
|
||
| if date_time_format > datetime.now() + timedelta(days=cls._MAX_TIME_LIMIT): | ||
| raise ValueError( | ||
| "Scheduled message must me sooner than 180 days from today" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "Scheduled message must me sooner than 180 days from today" | |
| "Scheduled message must be sooner than 180 days from today" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
infobip_channels/core/models.py
Outdated
| raise ValueError( | ||
| "Scheduled message must me sooner than 180 days from today" | ||
| ) | ||
| else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else not needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
infobip_channels/core/models.py
Outdated
| def convert_time_to_correct_format(cls, value) -> str: | ||
| date_time_format = cls.convert_to_date_time_format(value) | ||
|
|
||
| return date_time_format.strftime("%Y-%m-%dT%H:%M:%S.%fZ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move "%Y-%m-%dT%H:%M:%S.%fZ" into a class variable and use it here and in the convert_time_to_correct_format_validate_limit method.
class DateTimeValidator:
_MAX_TIME_LIMIT = 180
_EXPECTED_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
infobip_channels/sms/channel.py
Outdated
| SMS_URL_TEMPLATE_VERSION_2 = "/sms/2/" | ||
|
|
||
| @staticmethod | ||
| def validate_query_parameter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is the same here and in the MMSChannel, best to extract it into the Channel class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
infobip_channels/sms/channel.py
Outdated
| **kwargs | ||
| ) -> Type[ResponseBase]: | ||
|
|
||
| if raw_response.status_code in (HTTPStatus.OK,): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if raw_response.status_code in (HTTPStatus.OK,): | |
| if raw_response.status_code == HTTPStatus.OK: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, this was bad 😞
infobip_channels/sms/channel.py
Outdated
|
|
||
| def get_inbound_sms_messages( | ||
| self, | ||
| query_parameters: Union[GetInboundSMSMessagesQueryParameters, Dict] = {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default mutable argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚔️
infobip_channels/sms/channel.py
Outdated
| response = self._client.put( | ||
| self.SMS_URL_TEMPLATE_VERSION_1 + "bulks/status", | ||
| message.dict(by_alias=True), | ||
| PutHeaders(authorization=self._client.auth.api_key), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as for the PostHeaders, this should already be present in the default ones, so you can probably omit this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
| DAY = "DAY" | ||
|
|
||
|
|
||
| class DaysEnum(str, Enum): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have this exact enum in mms channel also, might be good to move it into a core models file and reuse it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| to: Optional[Time] = None | ||
|
|
||
| @root_validator | ||
| def validate_from_and_to(cls, values): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is the same method as we have in the mms channel. We can extract it (along with _validate_time_differences) into a FromAndToTimeValidator and reuse it in both places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, good chunk of code is gone
| send_at: Optional[Union[datetime, str]] = None | ||
|
|
||
| @validator("send_at") | ||
| def convert_send_at_to_correct_format(cls, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very similar to the convert_send_at_to_correct_format method we use in the mms channel. We could extract the common logic into a Validator class and change this version to:
class RescheduleSMSMessagesMessageBody(Validator, MessageBodyBase):
...
@validator("send_at")
def convert_send_at_to_correct_format(cls, value):
if value > datetime.now() + timedelta(days=180):
raise ValueError(
"Scheduled message must me sooner than 180 days from today"
)
return super().convert_send_at_to_correct_format(value)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done done, thanks
Added SMS channel
Added Integration tests for SMS channel
Added model tests for SMS channel