Skip to content

Commit

Permalink
Added fixed samples
Browse files Browse the repository at this point in the history
  • Loading branch information
jorge-beauregard committed Feb 17, 2021
1 parent a11fa64 commit cb958a4
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@
AcquiredPhoneNumber,
AcquiredPhoneNumbers,
CommunicationError,
CommunicationErrorResponse,
PhoneNumberCapabilities,
PhoneNumberCapabilitiesRequest,
PhoneNumberCost,
PhoneNumberOperation,
PhoneNumberPurchaseRequest,
PhoneNumberSearchRequest,
PhoneNumberSearchResult,
BillingFrequency,
PhoneNumberAssignmentType,
Expand All @@ -30,13 +26,9 @@
'AcquiredPhoneNumber',
'AcquiredPhoneNumbers',
'CommunicationError',
'CommunicationErrorResponse',
'PhoneNumberCapabilities',
'PhoneNumberCapabilitiesRequest',
'PhoneNumberCost',
'PhoneNumberOperation',
'PhoneNumberPurchaseRequest',
'PhoneNumberSearchRequest',
'PhoneNumberSearchResult',
'BillingFrequency',
'PhoneNumberAssignmentType',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
# --------------------------------------------------------------------------

"""
FILE: phone_number_area_codes_sample.py
FILE:get_phone_number_sample.py
DESCRIPTION:
This sample demonstrates how to get all area codes via a connection string, country code and phone plan id.
This sample demonstrates how to get the information from an acquired phone number using your connection string
USAGE:
python list_acquired_phone_numbers_sample.py
python get_phone_number_sample.py
Set the environment variables with your own values before running the sample:
1) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - The endpoint of your Azure Communication Service
2) AZURE_COMMUNICATION_SERVICE_PHONE_NUMBER_INFORMATION - The phone number you want to get its information
2) AZURE_COMMUNICATION_SERVICE_PHONE_NUMBER - The phone number you want to get its information
"""

import os
Expand All @@ -23,7 +23,7 @@
)

connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')
phone_number = os.getenv("AZURE_COMMUNICATION_SERVICE_PHONE_NUMBER")
phone_number = os.getenv("AZURE_COMMUNICATION_SERVICE_PHONE_NUMBER") # e.g. "+18001234567"
phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str)

def get_phone_number_information():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
# --------------------------------------------------------------------------

"""
FILE: phone_number_area_codes_sample.py
FILE: list_acquired_phone_numbers_sample.py
DESCRIPTION:
This sample demonstrates how to get all area codes via a connection string, country code and phone plan id.
This sample demonstrates how to get all off you acquired phone numbers using your connection string
USAGE:
python list_acquired_phone_numbers_sample.py
Set the environment variables with your own values before running the sample:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
# --------------------------------------------------------------------------

"""
FILE: phone_number_area_codes_sample.py
FILE: purchase_phone_number_sample.py
DESCRIPTION:
This sample demonstrates how to get all area codes via a connection string, country code and phone plan id.
This sample demonstrates how to purchase a phone number using the search id you got from the search_available_phone_number API
USAGE:
python list_acquired_phone_numbers_sample.py
python purchase_phone_number_sample.py
Set the environment variables with your own values before running the sample:
1) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - The endpoint of your Azure Communication Service
2) AZURE_COMMUNICATION_SERVICE_SEARCH_ID_TO_PURCHASE - The search id for the phone number you reserved and want to purchase
Expand All @@ -23,14 +23,18 @@
)

connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')
phone_number = os.getenv("AZURE_COMMUNICATION_SERVICE_PHONE_NUMBER_INFORMATION")
search_id = os.getenv("AZURE_COMMUNICATION_SERVICE_SEARCH_ID_TO_PURCHASE")
phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str)

def get_phone_number_information():
phone_number_information = phone_numbers_client.get_phone_number(phone_number)
print('Phone number information:')
print(phone_number_information)
def purchase_phone_number():
poller = phone_numbers_client.begin_purchase_phone_numbers(
search_id,
polling = True
)
poller.result()
print("Result from the purchase operation: ")
print(poller.status)


if __name__ == '__main__':
get_phone_number_information()
purchase_phone_number()
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
# --------------------------------------------------------------------------

"""
FILE: phone_number_area_codes_sample.py
FILE: release_phone_number_sample.py
DESCRIPTION:
This sample demonstrates how to get all area codes via a connection string, country code and phone plan id.
This sample demonstrates how to release a previously acquired phone number using your connection string.
USAGE:
python list_acquired_phone_numbers_sample.py
python release_phone_number_sample.py
Set the environment variables with your own values before running the sample:
1) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - The endpoint of your Azure Communication Service
2) AZURE_COMMUNICATION_SERVICE_PHONE_NUMBER_RELEASE - The phone number you want to release
2) AZURE_COMMUNICATION_SERVICE_PHONE_NUMBER_TO_RELEASE - The phone number you want to release
"""

import os
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
# --------------------------------------------------------------------------

"""
FILE: phone_number_area_codes_sample.py
FILE: search_available_phone_numbers_sample.py
DESCRIPTION:
This sample demonstrates how to get all area codes via a connection string, country code and phone plan id.
This sample demonstrates how to search for available numbers you can buy with the respective API.
USAGE:
python list_acquired_phone_numbers_sample.py
python search_available_phone_numbers_sample.py
Set the environment variables with your own values before running the sample:
1) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - The endpoint of your Azure Communication Service
2) AZURE_COMMUNICATION_SERVICE_AREA_CODE - The area code you want the number to be in
Expand Down Expand Up @@ -49,4 +49,4 @@ def search_available_phone_numbers():


if __name__ == '__main__':
list_acquired_phone_numbers()
search_available_phone_numbers()
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# coding: utf-8

# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

"""
FILE: update_phone_number_capabilities_sample.py
DESCRIPTION:
This sample demonstrates how to updtae the capabilities of a phone number using your connection string.
USAGE:
python update_phone_number_capabilities_sample.py
Set the environment variables with your own values before running the sample:
1) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - The endpoint of your Azure Communication Service
2) AZURE_COMMUNICATION_SERVICE_PHONE_NUMBER_TO_UPDATE - The phone number you want to update
"""

import os
from azure.communication.phonenumbers import (
PhoneNumbersClient,
PhoneNumberCapabilityValue
)

connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')
phone_number_to_release = os.getenv(
"AZURE_COMMUNICATION_SERVICE_PHONE_NUMBER_TO_UPDATE" # e.g. "+18001234567"
)
phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str)

def update_phone_number_capabilities():
poller = phone_numbers_client.begin_update_phone_number_capabilities(
"+18335260208",
PhoneNumberCapabilityValue.OUTBOUND,
PhoneNumberCapabilityValue.INBOUND_OUTBOUND,
polling = True
)
poller.result()
print('Status of the operation:')
print(poller.status())

if __name__ == '__main__':
update_phone_number_capabilities()
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def setUp(self):
ResponseReplacerProcessor(keys=[self._resource_name])])

@AsyncCommunicationTestCase.await_prepared_test
@pytest.mark.live_test_only
async def test_list_acquired_phone_numbers(self):
async with self.phone_number_client:
phone_numbers = self.phone_number_client.list_acquired_phone_numbers()
Expand All @@ -24,69 +25,71 @@ async def test_list_acquired_phone_numbers(self):
assert len(items) > 0

@AsyncCommunicationTestCase.await_prepared_test
@pytest.mark.live_test_only
async def test_get_phone_number(self):
async with self.phone_number_client:
phone_number = await self.phone_number_client.get_phone_number("+18332272412")
assert phone_number.phone_number == "+18332272412"

'''
def test_update_phone_number(self):
updated_phone_number = self.phone_number_client.update_phone_number(
"+16194895842",
"",
""
)
assert updated_phone_number.application_id == ""

@AsyncCommunicationTestCase.await_prepared_test
@pytest.mark.live_test_only
async def test_release_phone_number(self):
async with self.phone_number_client:
poller = await self.phone_number_client.begin_release_phone_number("+16194895875")
result = await poller.result()
assert result
def test_search_available_phone_numbers(self):

@AsyncCommunicationTestCase.await_prepared_test
@pytest.mark.live_test_only
async def test_search_available_phone_numbers(self):
capabilities = PhoneNumberCapabilities(
calling = PhoneNumberCapabilityValue.INBOUND,
sms = PhoneNumberCapabilityValue.INBOUND_OUTBOUND
)
poller = self.phone_number_client.begin_search_available_phone_numbers(
"US",
PhoneNumberType.TOLL_FREE,
PhoneNumberAssignmentType.APPLICATION,
capabilities,
"833",
1,
polling = True
)
async with self.phone_number_client:
poller = await self.phone_number_client.begin_search_available_phone_numbers(
"US",
PhoneNumberType.TOLL_FREE,
PhoneNumberAssignmentType.APPLICATION,
capabilities,
"833",
1,
polling = True
)
assert poller.result()

def test_update_phone_number_capabilities(self):
poller = self.phone_number_client.begin_update_phone_number_capabilities(
"+16194895875",
PhoneNumberCapabilityValue.OUTBOUND,
PhoneNumberCapabilityValue.OUTBOUND,
polling = True
)
@AsyncCommunicationTestCase.await_prepared_test
@pytest.mark.live_test_only
async def test_update_phone_number_capabilities(self):
async with self.phone_number_client:
poller = self.phone_number_client.begin_update_phone_number_capabilities(
"+16194895875",
PhoneNumberCapabilityValue.OUTBOUND,
PhoneNumberCapabilityValue.OUTBOUND,
polling = True
)
assert poller.result()

def test_purchase_phone_numbers(self):
@AsyncCommunicationTestCase.await_prepared_test
@pytest.mark.live_test_only
async def test_purchase_phone_numbers(self):
capabilities = PhoneNumberCapabilities(
calling = PhoneNumberCapabilityValue.INBOUND,
sms = PhoneNumberCapabilityValue.INBOUND_OUTBOUND
)
search_poller = self.phone_number_client.begin_search_available_phone_numbers(
"US",
PhoneNumberType.TOLL_FREE,
PhoneNumberAssignmentType.APPLICATION,
capabilities,
"833",
1,
polling = True
)
phone_number_to_buy = search_poller.result()
purchase_poller = self.phone_number_client.begin_purchase_phone_numbers(phone_number_to_buy.search_id, polling=True)
assert purchase_poller.result()
release_poller = self.phone_number_client.begin_release_phone_number(phone_number_to_buy.phone_number)
async with self.phone_number_client:
search_poller = await self.phone_number_client.begin_search_available_phone_numbers(
"US",
PhoneNumberType.TOLL_FREE,
PhoneNumberAssignmentType.APPLICATION,
capabilities,
"833",
1,
polling = True
)
phone_number_to_buy = search_poller.result()
purchase_poller = await self.phone_number_client.begin_purchase_phone_numbers(phone_number_to_buy.search_id, polling=True)
assert purchase_poller.result()
release_poller = await self.phone_number_client.begin_release_phone_number(phone_number_to_buy.phone_number)
assert release_poller.status() == 'succeeded'
'''

0 comments on commit cb958a4

Please sign in to comment.