Пример #1
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)
Пример #2
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
Пример #3
0
    def generateAuthToken(self):
        'Uses the Telstra messaging API client credientals to get an OAuth 2.0 token.'

        api_instance_Auth = Telstra_Messaging.AuthenticationApi()
        try:
            self.authToken = api_instance_Auth.auth_token(
                self.client_id, self.client_secret, self.grant_type)
            self.authTokenExpiry = datetime.now() + timedelta(seconds=3598)
            pprint(self.authToken)
        except ApiException as e:
            print(
                "Exception when calling AuthenticationApi->auth_token: %s\n" %
                e)

        self.configuration = Telstra_Messaging.Configuration()
        self.configuration.access_token = self.authToken.access_token
        self.provisionInstance = Telstra_Messaging.ProvisioningApi(
            Telstra_Messaging.ApiClient(self.configuration))
Пример #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
Пример #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)