Rename gateway_url to gateway_base_url

In order to prepare for using more than the SMS sending endpoint.
This commit is contained in:
Mikkel Munch Mortensen 2024-08-22 09:10:07 +02:00
parent 19aede533b
commit 5019844761

View file

@ -35,7 +35,7 @@ class Gateway:
options: Dict[str, Any] = {}
username: str
password: str
gateway_url: str = "https://api.cpsms.dk/v2/send"
gateway_base_url: str = "https://api.cpsms.dk"
@property
def default_options(self) -> Dict[str, Any]:
@ -58,7 +58,7 @@ class Gateway:
password: str,
sender_name: str,
options: Dict[str, Any] = None,
gateway_url: str = None,
gateway_base_url: str = None,
) -> None:
"""Initialize SMS gateway."""
self.username = username
@ -70,8 +70,8 @@ class Gateway:
if options is not None:
self.options.update(options)
if gateway_url:
self.gateway_url = gateway_url
if gateway_base_url:
self.gateway_base_url = gateway_base_url
def send(self, to: str = None, message: str = None) -> Tuple[bool, str]:
"""
@ -94,8 +94,7 @@ class Gateway:
if len(self.options["message"]) > 459:
raise ValueError(
"Message not allowed to be more than 459 characters."
"Current message is %i characters."
% len(self.options["message"])
"Current message is %i characters." % len(self.options["message"])
)
# Update recipient if specified.
@ -122,10 +121,8 @@ class Gateway:
auth_header = "{}:{}".format(self.username, self.password)
auth_header = base64.b64encode(auth_header.encode()).decode()
http_request = request.Request(self.gateway_url, data=data)
http_request.add_header(
"Authorization", "Basic {}".format(auth_header)
)
http_request = request.Request(self.gateway_base_url + "/v2/send", data=data)
http_request.add_header("Authorization", "Basic {}".format(auth_header))
response = request.urlopen(http_request)
return json.loads(response.read().decode())