Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def call(self, source, destination, callback=None):
phone_numbers = destination.split(',')
for index, phone_number in enumerate(phone_numbers):
phone_number = phone_number.replace(' ', '')
if not validate_phone(phone_number):
raise ValueError(
f'Invalid destination phone number: {phone_number}')
phone_numbers[index] = phone_number
destination = ','.join(phone_numbers)
url = self._make_url('/call')
data = {
'username': self._username,
'from': source,
'to': destination,
}
return self._make_request(url, 'POST', headers=self._headers, params=None, data=data, callback=callback)
def create_subscription(self, short_code, keyword, phone_number, checkout_token, callback=None):
if not validate_phone(phone_number):
raise ValueError('Invalid phone number')
url = self._make_url('/subscription/create', content=True)
data = {
'username': self._username,
'shortCode': short_code,
'keyword': keyword,
'phoneNumber': phone_number,
'checkoutToken': checkout_token,
}
return self._make_request(url, 'POST', headers=self._headers, data=data, params=None, callback=callback)
'phoneNumber': And(str, lambda s: validate_phone(s)),
'currencyCode': And(str, lambda s: len(s) == 3),
'phoneNumber': And(str, lambda s: validate_phone(s)),
'quantity': And(lambda f: float(f) > 0),
def delete_subscription(self, short_code, keyword, phone_number, callback=None):
if not validate_phone(phone_number):
raise ValueError('Invalid phone number')
url = self._make_url('/subscription/delete', content=True)
data = {
'username': self._username,
'shortCode': short_code,
'keyword': keyword,
'phoneNumber': phone_number
}
return self._make_request(url, 'POST', headers=self._headers, data=data, params=None, callback=callback)
def value_validator(phoneNumber, amount, currency_code):
if not validate_phone(phoneNumber):
return 'Invalid phone number'
elif not validate_amount(amount):
return 'Invalid amount'
elif not validate_currency(currency_code):
return 'Invalid currency code'
else:
return False
def send(self, message, recipients, sender_id=None, enqueue=False, callback=None):
for phone in recipients:
if not validate_phone(phone):
raise ValueError('Invalid phone number: ' + phone)
url = self._make_url('/messaging')
data = {
'username': self._username,
'to': ','.join(recipients),
'message': message,
'bulkSMSMode': 1,
}
if sender_id is not None:
data['from'] = sender_id
if enqueue:
data['enqueue'] = 1
def media_upload(self, phone_number, url, callback=None):
if not validate_phone(phone_number):
raise ValueError('Invalid phone number')
call_url = self._make_url('/mediaUpload')
data = {
'username': self._username,
'phoneNumber': phone_number,
'url': url,
}
return self._make_request(call_url, 'POST', headers=self._headers, params=None, data=data, callback=callback)
def fetch_queued_calls(self, phone_number, callback=None):
if not validate_phone(phone_number):
raise ValueError('Invalid phone number')
url = self._make_url('/queueStatus')
data = {
'username': self._username,
'phoneNumbers': phone_number,
}
return self._make_request(url, 'POST', headers=self._headers, params=None, data=data, callback=callback)
def create_checkout_token(self, phone_number, callback=None):
if not validate_phone(phone_number):
raise ValueError('Invalid phone number')
url = self._make_url('/checkout/token/create')
headers = dict(self._headers)
data = {'phoneNumber': phone_number}
return self._make_request(url, 'POST', headers, data=data, params=None, callback=callback)