ClickSend formatting for consistency with alike services

pull/155/head
Chris Caron 2019-09-20 20:56:19 -04:00
parent eae45149b3
commit 3b8b72f56d
1 changed files with 8 additions and 11 deletions

View File

@ -87,7 +87,7 @@ class NotifyClickSend(NotifyBase):
title_maxlen = 0 title_maxlen = 0
# The maximum SMS batch size accepted by the ClickSend API # The maximum SMS batch size accepted by the ClickSend API
sms_batch_size = 1000 default_batch_size = 1000
# Define object templates # Define object templates
templates = ( templates = (
@ -197,18 +197,15 @@ class NotifyClickSend(NotifyBase):
'messages': [] 'messages': []
} }
# Create a copy of the target list
targets = list(self.targets)
# Send in batches if identified to do so # Send in batches if identified to do so
sms_batch_size = 1 if not self.batch else self.sms_batch_size default_batch_size = 1 if not self.batch else self.default_batch_size
for index in range(0, len(targets), sms_batch_size): for index in range(0, len(self.targets), default_batch_size):
payload['messages'] = [{ payload['messages'] = [{
'source': 'php', 'source': 'php',
'body': body, 'body': body,
'to': '+{}'.format(to), 'to': '+{}'.format(to),
} for to in targets[index:index + sms_batch_size]] } for to in self.targets[index:index + default_batch_size]]
self.logger.debug('ClickSend POST URL: %s (cert_verify=%r)' % ( self.logger.debug('ClickSend POST URL: %s (cert_verify=%r)' % (
self.notify_url, self.verify_certificate, self.notify_url, self.verify_certificate,
@ -234,8 +231,8 @@ class NotifyClickSend(NotifyBase):
'Failed to send {} ClickSend notification{}: ' 'Failed to send {} ClickSend notification{}: '
'{}{}error={}.'.format( '{}{}error={}.'.format(
len(payload['messages']), len(payload['messages']),
' to {}'.format(targets[index]) ' to {}'.format(self.targets[index])
if sms_batch_size == 1 else '(s)', if default_batch_size == 1 else '(s)',
status_str, status_str,
', ' if status_str else '', ', ' if status_str else '',
r.status_code)) r.status_code))
@ -252,8 +249,8 @@ class NotifyClickSend(NotifyBase):
'Sent {} ClickSend notification{}.' 'Sent {} ClickSend notification{}.'
.format( .format(
len(payload['messages']), len(payload['messages']),
' to {}'.format(targets[index]) ' to {}'.format(self.targets[index])
if sms_batch_size == 1 else '(s)', if default_batch_size == 1 else '(s)',
)) ))
except requests.RequestException as e: except requests.RequestException as e: