Beispiel #1
0
    def createSubscription(self, length=None):
        'Creates a subscription with the Telstra API, ie gets a mobile number to use. length defines the number of days to create the subscription for, no value will default to API default.'

        self.__checkAuthToken()
        body = Telstra_Messaging.ProvisionNumberRequest(length)
        try:
            api_response = self.provisionInstance.create_subscription(body)
            pprint(api_response)
        except ApiException as e:
            print(
                "Exception when calling ProvisioningApi->create_subscription: %s\n"
                % e)
Beispiel #2
0
    def provision_client(self):
        api_instance = Telstra_Messaging.ProvisioningApi(
            Telstra_Messaging.ApiClient(self.configuration))
        provision_number_request = Telstra_Messaging.ProvisionNumberRequest()

        try:
            # Create Subscription
            api_response = api_instance.create_subscription(
                provision_number_request)
            api_response = api_instance.get_subscription()

        except ApiException as e:
            print(
                "Exception when calling ProvisioningApi->create_subscription: %s\n"
                % e)
Beispiel #3
0
def get_from_number():
    destination_address = r.get(TELSTRA_SMS_DESTINATION_ADDRESS)
    if destination_address:
        return destination_address

    configuration = Telstra_Messaging.Configuration()
    configuration.access_token = get_token()
    api_instance = Telstra_Messaging.ProvisioningApi(Telstra_Messaging.ApiClient(configuration))
    provision_number_request = Telstra_Messaging.ProvisionNumberRequest()  # ProvisionNumberRequest | A JSON payload containing the required attributes
    api_response = api_instance.create_subscription(provision_number_request)
    destination_address = api_response.destination_address
    expiry_timestamp = int(api_response.expiry_date / 1000)
    expires_in = expiry_timestamp - int(time.mktime(datetime.datetime.now().timetuple()))
    r.setex(TELSTRA_SMS_DESTINATION_ADDRESS, expires_in, destination_address)
    return destination_address
Beispiel #4
0
def get_from_number():
    global TELSTRA_DESTINATION_ADDRESS, TELSTRA_DESTINATION_ADDRESS_EXPIRY
    destination_address = TELSTRA_DESTINATION_ADDRESS if TELSTRA_DESTINATION_ADDRESS_EXPIRY > datetime.now(
    ) else None
    if destination_address:
        return destination_address

    configuration = Telstra_Messaging.Configuration()
    configuration.access_token = get_token()
    api_instance = Telstra_Messaging.ProvisioningApi(
        Telstra_Messaging.ApiClient(configuration))
    provision_number_request = Telstra_Messaging.ProvisionNumberRequest(
    )  # ProvisionNumberRequest | A JSON payload containing the required attributes
    api_response = api_instance.create_subscription(provision_number_request)
    destination_address = api_response.destination_address
    expiry_timestamp = int(api_response.expiry_date / 1000)
    expires_in = expiry_timestamp - int(time.mktime(
        datetime.now().timetuple()))
    TELSTRA_DESTINATION_ADDRESS = destination_address
    TELSTRA_DESTINATION_ADDRESS_EXPIRY = datetime.now() + timedelta(
        seconds=expires_in)
    return destination_address
Beispiel #5
0
 def provision_subscription(self):
     # maximum subscription is 5 years, 1825 days
     telstra_api = telstra.ProvisioningApi(self._client)
     req = telstra.ProvisionNumberRequest(active_days=1825)
     telstra_api.create_subscription(req)