How to use the africastalking.Service.APIService function in africastalking

To help you get started, we’ve selected a few africastalking examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AfricasTalkingLtd / africastalking-python / africastalking / SMS.py View on Github external
from . Service import APIService, validate_phone


class SMSService(APIService):
    def __init__(self, username, api_key):
        super(SMSService, self).__init__(username, api_key)

    def _init_service(self):
        super(SMSService, self)._init_service()
        self._baseUrl = self._baseUrl + '/version1'

    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,
github AfricasTalkingLtd / africastalking-python / africastalking / Airtime.py View on Github external
import json
from . Service import APIService, validate_amount, validate_phone, validate_currency, validate_keys


class AirtimeService(APIService):
    def __init__(self, username, api_key):
        super(AirtimeService, self).__init__(username, api_key)

    def _init_service(self):
        super(AirtimeService, self)._init_service()
        self._baseUrl = self._baseUrl + '/version1/airtime'

    def send(self, phone_number=None, amount=None, currency_code=None, recipients=None,
             idempotency_key=None, callback=None):

        def join_amount_and_currency(obj):
                obj['amount'] = " ".join([str(obj['currency_code']), str(obj['amount'])])
                del obj['currency_code']
                return obj

        def value_validator(phoneNumber, amount, currency_code):
github AfricasTalkingLtd / africastalking-python / africastalking / Application.py View on Github external
from . Service import APIService


class ApplicationService(APIService):
    def __init__(self, username, api_key):
        super(ApplicationService, self).__init__(username, api_key)

    def _init_service(self):
        super(ApplicationService, self)._init_service()
        self._baseUrl = self._baseUrl + '/version1'

    def fetch_application_data(self, callback=None):
        url = self._make_url('/user')
        params = {
            'username': self._username
        }
        return self._make_request(url, 'GET', headers=self._headers, params=params, data=None, callback=callback)
github AfricasTalkingLtd / africastalking-python / africastalking / Token.py View on Github external
import json

from . Service import APIService, validate_phone


class TokenService(APIService):

    def __init__(self, username, api_key):
        super(TokenService, self).__init__(username, api_key)

    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)

    def generate_auth_token(self, callback=None):
github AfricasTalkingLtd / africastalking-python / africastalking / Service.py View on Github external
def __init__(self, username, api_key):
        super(APIService, self).__init__(username, api_key)