From 347c13385689f443ef168abc208ea0137798e304 Mon Sep 17 00:00:00 2001 From: Eason Yang Date: Wed, 30 Sep 2020 19:45:55 -0700 Subject: [PATCH 1/6] add tnm samples v0 --- .../samples/phone_number_area_codes_sample.py | 43 +++++++ .../phone_number_area_codes_sample_async.py | 47 ++++++++ .../phone_number_capabilities_sample.py | 63 ++++++++++ .../phone_number_capabilities_sample_async.py | 77 +++++++++++++ .../phone_number_configuration_sample.py | 54 +++++++++ ...phone_number_configuration_sample_async.py | 62 ++++++++++ .../samples/phone_number_orders_sample.py | 88 ++++++++++++++ .../phone_number_orders_sample_async.py | 108 ++++++++++++++++++ .../samples/phone_number_plans_sample.py | 63 ++++++++++ .../phone_number_plans_sample_async.py | 74 ++++++++++++ ...phone_number_supported_countries_sample.py | 38 ++++++ ...number_supported_countries_sample_async.py | 43 +++++++ 12 files changed, 760 insertions(+) create mode 100644 sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample.py create mode 100644 sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample_async.py create mode 100644 sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample.py create mode 100644 sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample_async.py create mode 100644 sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample.py create mode 100644 sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample_async.py create mode 100644 sdk/communication/azure-communication-administration/samples/phone_number_orders_sample.py create mode 100644 sdk/communication/azure-communication-administration/samples/phone_number_orders_sample_async.py create mode 100644 sdk/communication/azure-communication-administration/samples/phone_number_plans_sample.py create mode 100644 sdk/communication/azure-communication-administration/samples/phone_number_plans_sample_async.py create mode 100644 sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample.py create mode 100644 sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample_async.py diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample.py new file mode 100644 index 0000000000000..d3760eda1dac1 --- /dev/null +++ b/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample.py @@ -0,0 +1,43 @@ +# 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: phone_number_area_codes_sample.py +DESCRIPTION: + These samples demonstrate area codes samples. + + ///getting all area codes via a connection string, country code and phone plan id +USAGE: + python phone_number_area_codes_sample.py +""" +import os +from azure.communication.administration import ( + PhoneNumberAdministrationClient +) + +class CommunicationAreaCodesSamples(object): + + def __init__(self): + self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + self.country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_COUNTRY_CODE', "US") + self.phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID_AREA_CODES', "phone-plan-id") + + def get_all_area_codes(self): + all_area_codes = self._phone_number_administration_client.get_all_area_codes( + location_type="NotRequired", + country_code=self.country_code, + phone_plan_id=self.phone_plan_id_area_codes + ) + print('all_area_codes:') + print(all_area_codes) + +if __name__ == '__main__': + sample = CommunicationAreaCodesSamples() + sample.get_all_area_codes() diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample_async.py new file mode 100644 index 0000000000000..f9e5e21d40b72 --- /dev/null +++ b/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample_async.py @@ -0,0 +1,47 @@ +# 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: phone_number_area_codes_sample.py +DESCRIPTION: + These samples demonstrate area codes samples. + + ///getting all area codes via a connection string, country code and phone plan id +USAGE: + python phone_number_area_codes_sample.py +""" +import os +import asyncio +from azure.communication.administration.aio import PhoneNumberAdministrationClient + +class CommunicationAreaCodesSamplesAsync(object): + + def __init__(self): + self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') + self.country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_COUNTRY_CODE', "US") + self.phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID_AREA_CODES', "phone-plan-id") + + async def get_all_area_codes(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + async with self._phone_number_administration_client: + all_area_codes = await self._phone_number_administration_client.get_all_area_codes( + location_type="NotRequired", + country_code=self.country_code, + phone_plan_id=self.phone_plan_id_area_codes + ) + print('all_area_codes:') + print(all_area_codes) + +async def main(): + sample = CommunicationAreaCodesSamplesAsync() + await sample.get_all_area_codes() + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample.py new file mode 100644 index 0000000000000..5c3f81880ff4c --- /dev/null +++ b/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample.py @@ -0,0 +1,63 @@ +# 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: phone_number_capabilities_sample.py +DESCRIPTION: + These samples demonstrate number capabilities samples. + + ///getting number capabilities via a connection string, capabilities update id and phone number for capabilities +USAGE: + python phone_number_capabilities_sample.py +""" +import os +from azure.communication.administration import ( + PhoneNumberAdministrationClient, + NumberUpdateCapabilities +) + +class CommunicationNumberCapabilitiesSamples(object): + + def __init__(self): + self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + self.capabilities_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_CAPABILITIES_ID', "capabilities-id") + self.phonenumber_for_capabilities = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_FOR_CAPABILITIES', "+17771234567") + + def list_all_phone_numbers(self): + list_all_phone_numbers_response = self._phone_number_administration_client.list_all_phone_numbers() + print('list_all_phone_numbers_response:') + for phone_number in list_all_phone_numbers_response: + print(phone_number) + + def get_capabilities_update(self): + capabilities_response = self._phone_number_administration_client.get_capabilities_update( + capabilities_update_id=self.capabilities_id + ) + print('capabilities_response:') + print(capabilities_response) + + def update_capabilities(self): + update = NumberUpdateCapabilities(add=iter(["InboundCalling"])) + + phone_number_capabilities_update = { + self.phonenumber_for_capabilities: update + } + + capabilities_response = self._phone_number_administration_client.update_capabilities( + phone_number_capabilities_update=phone_number_capabilities_update + ) + print('capabilities_response:') + print(capabilities_response) + +if __name__ == '__main__': + sample = CommunicationNumberCapabilitiesSamples() + sample.list_all_phone_numbers() + sample.get_capabilities_update() + sample.update_capabilities() diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample_async.py new file mode 100644 index 0000000000000..17a0c9447c0bf --- /dev/null +++ b/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample_async.py @@ -0,0 +1,77 @@ +# 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: phone_number_capabilities_sample.py +DESCRIPTION: + These samples demonstrate number capabilities samples. + + ///getting number capabilities via a connection string, capabilities update id and phone number for capabilities +USAGE: + python phone_number_capabilities_sample.py +""" +import asyncio +import os +from azure.communication.administration.aio import PhoneNumberAdministrationClient +from azure.communication.administration import NumberUpdateCapabilities + + +class CommunicationNumberCapabilitiesSamplesAsync(object): + + def __init__(self): + self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') + self.capabilities_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_CAPABILITIES_ID', "capabilities-id") + self.phonenumber_for_capabilities = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_FOR_CAPABILITIES', + "phone-number-for-capabilities") + + async def list_all_phone_numbers(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + async with self._phone_number_administration_client: + list_all_phone_numbers_response = self._phone_number_administration_client.list_all_phone_numbers() + print('list_all_phone_numbers_response:') + async for phone_number in list_all_phone_numbers_response: + print(phone_number) + + async def get_capabilities_update(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + async with self._phone_number_administration_client: + capabilities_response = await self._phone_number_administration_client.get_capabilities_update( + capabilities_update_id=self.capabilities_id + ) + print('capabilities_response:') + print(capabilities_response) + + async def update_capabilities(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + update = NumberUpdateCapabilities(add=iter(["InboundCalling"])) + + phone_number_capabilities_update = { + self.phonenumber_for_capabilities: update + } + + async with self._phone_number_administration_client: + capabilities_response = await self._phone_number_administration_client.update_capabilities( + phone_number_capabilities_update=phone_number_capabilities_update + ) + print('capabilities_response:') + print(capabilities_response) + + +async def main(): + sample = CommunicationNumberCapabilitiesSamplesAsync() + await sample.list_all_phone_numbers() + await sample.get_capabilities_update() + await sample.update_capabilities() + + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample.py new file mode 100644 index 0000000000000..29359d16a7f43 --- /dev/null +++ b/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample.py @@ -0,0 +1,54 @@ +# 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: phone_number_configuration_sample.py +DESCRIPTION: + These samples demonstrate phone number configuration samples. + + ///listing phone plans via a connection string and phone number to configure +USAGE: + python phone_number_configuration_sample.py +""" +import os +from azure.communication.administration import ( + PhoneNumberAdministrationClient, + PstnConfiguration +) + +class CommunicationPhoneNumberConfigurationSamples(object): + + def __init__(self): + self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + self.phonenumber_to_configure = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_TO_CONFIGURE', + "phonenumber_to_configure") + + def get_number_configuration(self): + phone_number_configuration_response = self._phone_number_administration_client.get_number_configuration( + phone_number=self.phonenumber_to_configure + ) + print('phone_number_configuration_response:') + print(phone_number_configuration_response) + + def configure_number(self): + pstn_config = PstnConfiguration( + callback_url="https://callbackurl", + application_id="ApplicationId", + azure_pstn_target_id="AzurePstnTargetId" + ) + self._phone_number_administration_client.configure_number( + pstn_configuration=pstn_config, + phone_number=self.phonenumber_to_configure + ) + +if __name__ == '__main__': + sample = CommunicationPhoneNumberConfigurationSamples() + sample.get_number_configuration() + sample.configure_number() diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample_async.py new file mode 100644 index 0000000000000..f15e3b9bfe6c2 --- /dev/null +++ b/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample_async.py @@ -0,0 +1,62 @@ +# 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: phone_number_configuration_sample_async.py +DESCRIPTION: + These samples demonstrate phone number configuration samples. + + ///listing phone plans via a connection string and phone number to configure +USAGE: + python phone_number_configuration_sample_async.py +""" +import os +import asyncio +from azure.communication.administration.aio import PhoneNumberAdministrationClient +from azure.communication.administration import PstnConfiguration + +class CommunicationPhoneNumberConfigurationSamplesAsync(object): + + def __init__(self): + self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') + self.phonenumber_to_configure = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_TO_CONFIGURE', + "phonenumber_to_configure") + + async def get_number_configuration(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + async with self._phone_number_administration_client: + phone_number_configuration_response = await self._phone_number_administration_client.get_number_configuration( + phone_number=self.phonenumber_to_configure + ) + print('phone_number_configuration_response:') + print(phone_number_configuration_response) + + async def configure_number(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + pstn_config = PstnConfiguration( + callback_url="https://callbackurl", + application_id="ApplicationId", + azure_pstn_target_id="AzurePstnTargetId" + ) + async with self._phone_number_administration_client: + await self._phone_number_administration_client.configure_number( + pstn_configuration=pstn_config, + phone_number=self.phonenumber_to_configure + ) + + +async def main(): + sample = CommunicationPhoneNumberConfigurationSamplesAsync() + await sample.get_number_configuration() + await sample.configure_number() + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample.py new file mode 100644 index 0000000000000..2d01e440750db --- /dev/null +++ b/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample.py @@ -0,0 +1,88 @@ +# 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: phone_number_orders_sample.py +DESCRIPTION: + These samples demonstrate phone number orders samples. + + ///listing, acquiring and cancelling phone number orders via a connection string, search id, phone plan id and and area code +USAGE: + python phone_number_orders_sample.py +""" +import os +from azure.communication.administration import ( + PhoneNumberAdministrationClient, + CreateSearchOptions +) + +class CommunicationPhoneNumberOrdersSamples(object): + + def __init__(self): + self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + self.release_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_RELEASE_ID', "release-id") + self.search_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID', "search-id") + self.area_code_for_search = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_AREA_CODE_FOR_SEARCH', "area-code") + self.phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID', "phone-plan-id") + self.search_id_to_purchase = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID_TO_PURCHASE', "search-id") + self.search_id_to_cancel = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID_TO_CANCEL', "search-id") + + def get_release_by_id(self): + phone_number_release_response = self._phone_number_administration_client.get_release_by_id( + release_id=self.release_id + ) + print('phone_number_release_response:') + print(phone_number_release_response) + + def list_all_releases(self): + releases_response = self._phone_number_administration_client.list_all_releases() + print('releases_response:') + for release in releases_response: + print(release) + + def get_search_by_id(self): + phone_number_search_response = self._phone_number_administration_client.get_search_by_id( + search_id=self.search_id + ) + print('phone_number_search_response:') + print(phone_number_search_response) + + def create_search(self): + searchOptions = CreateSearchOptions( + area_code=self.area_code_for_search, + description="testsearch20200014", + display_name="testsearch20200014", + phone_plan_ids=[self.phone_plan_id], + quantity=1 + ) + search_response = self._phone_number_administration_client.create_search( + body=searchOptions + ) + print('search_response:') + print(search_response) + + def cancel_search(self): + self._phone_number_administration_client.cancel_search( + search_id=self.search_id_to_cancel + ) + + def purchase_search(self): + self._phone_number_administration_client.purchase_search( + search_id=self.search_id_to_purchase + ) + +if __name__ == '__main__': + sample = CommunicationPhoneNumberOrdersSamples() + sample.get_release_by_id() + sample.list_all_releases() + sample.get_search_by_id() + sample.create_search() + sample.cancel_search() + # sample.purchase_search() #currently throws error if purchase an already purchased number diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample_async.py new file mode 100644 index 0000000000000..adb23ac7714a3 --- /dev/null +++ b/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample_async.py @@ -0,0 +1,108 @@ +# 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: phone_number_orders_sample_async.py +DESCRIPTION: + These samples demonstrate phone number orders samples. + + ///listing, acquiring and cancelling phone number orders via a connection string, search id, phone plan id and and area code +USAGE: + python phone_number_orders_sample_async.py +""" +import os +import asyncio +from azure.communication.administration.aio import PhoneNumberAdministrationClient +from azure.communication.administration import CreateSearchOptions + +class CommunicationPhoneNumberOrdersSamplesAsync(object): + + def __init__(self): + self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') + self.release_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_RELEASE_ID', "release-id") + self.search_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID', "search-id") + self.area_code_for_search = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_AREA_CODE_FOR_SEARCH', "area-code") + self.phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID', "phone-plan-id") + self.search_id_to_purchase = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID_TO_PURCHASE', "search-id") + self.search_id_to_cancel = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID_TO_CANCEL', "search-id") + + async def get_release_by_id(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + async with self._phone_number_administration_client: + phone_number_release_response = await self._phone_number_administration_client.get_release_by_id( + release_id=self.release_id + ) + print('phone_number_release_response:') + print(phone_number_release_response) + + async def list_all_releases(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + async with self._phone_number_administration_client: + releases_response = self._phone_number_administration_client.list_all_releases() + print('releases_response:') + async for release in releases_response: + print(release) + + async def get_search_by_id(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + async with self._phone_number_administration_client: + phone_number_search_response = await self._phone_number_administration_client.get_search_by_id( + search_id=self.search_id + ) + print('phone_number_search_response:') + print(phone_number_search_response) + + async def create_search(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + searchOptions = CreateSearchOptions( + area_code=self.area_code_for_search, + description="testsearch20200014", + display_name="testsearch20200014", + phone_plan_ids=[self.phone_plan_id], + quantity=1 + ) + async with self._phone_number_administration_client: + search_response = await self._phone_number_administration_client.create_search( + body=searchOptions + ) + print('search_response:') + print(search_response) + + async def cancel_search(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + async with self._phone_number_administration_client: + await self._phone_number_administration_client.cancel_search( + search_id=self.search_id_to_cancel + ) + + async def purchase_search(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + async with self._phone_number_administration_client: + await self._phone_number_administration_client.purchase_search( + search_id=self.search_id_to_purchase + ) + + +async def main(): + sample = CommunicationPhoneNumberOrdersSamplesAsync() + await sample.get_release_by_id() + await sample.list_all_releases() + await sample.get_search_by_id() + await sample.create_search() + await sample.cancel_search() + await sample.purchase_search() #currently throws error if purchase an already purchased number + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample.py new file mode 100644 index 0000000000000..5fcfd9e87e609 --- /dev/null +++ b/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample.py @@ -0,0 +1,63 @@ +# 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: phone_number_plans_sample.py +DESCRIPTION: + These samples demonstrate phone plan samples. + + ///listing phone plans via a connection string, country code, phone plan id and phone plan group id +USAGE: + python phone_number_plans_sample.py +""" +import os +from azure.communication.administration import ( + PhoneNumberAdministrationClient +) + +class CommunicationPhonePlansSamples(object): + + def __init__(self): + self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + self.country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_COUNTRY_CODE', "US") + self.phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_GROUP_ID', "phone-plan-group-id") + self.phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID', "phone-plan-id") + + def list_phone_plan_groups(self): + phone_plan_groups_response = self._phone_number_administration_client.list_phone_plan_groups( + country_code=self.country_code + ) + print('list_phone_plan_groups:') + for phone_plan_group in phone_plan_groups_response: + print(phone_plan_group) + + def list_phone_plans(self): + phone_plans_response = self._phone_number_administration_client.list_phone_plans( + country_code=self.country_code, + phone_plan_group_id=self.phone_plan_group_id + ) + print('list_phone_plans:') + for phone_plan in phone_plans_response: + print(phone_plan) + + def get_phone_plan_location_options(self): + location_options_response = self._phone_number_administration_client.get_phone_plan_location_options( + country_code=self.country_code, + phone_plan_group_id=self.phone_plan_group_id, + phone_plan_id=self.phone_plan_id + ) + print('get_phone_plan_location_options:') + print(location_options_response) + +if __name__ == '__main__': + sample = CommunicationPhonePlansSamples() + sample.list_phone_plan_groups() + sample.list_phone_plans() + sample.get_phone_plan_location_options() diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample_async.py new file mode 100644 index 0000000000000..1c96b4c950258 --- /dev/null +++ b/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample_async.py @@ -0,0 +1,74 @@ +# 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: phone_number_plans_sample_async.py +DESCRIPTION: + These samples demonstrate phone plan samples. + + ///listing phone plans via a connection string, country code, phone plan id and phone plan group id +USAGE: + python phone_number_plans_sample_async.py +""" +import os +import asyncio +from azure.communication.administration.aio import PhoneNumberAdministrationClient + +class CommunicationPhoneNumberPlansSamplesAsync(object): + + def __init__(self): + self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') + self.country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_COUNTRY_CODE', "US") + self.phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_GROUP_ID', "phone-plan-group-id") + self.phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID', "phone-plan-id") + + async def list_phone_plan_groups(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + async with self._phone_number_administration_client: + phone_plan_groups_response = self._phone_number_administration_client.list_phone_plan_groups( + country_code=self.country_code + ) + print('list_phone_plan_groups:') + async for phone_plan_group in phone_plan_groups_response: + print(phone_plan_group) + + async def list_phone_plans(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + async with self._phone_number_administration_client: + phone_plans_response = self._phone_number_administration_client.list_phone_plans( + country_code=self.country_code, + phone_plan_group_id=self.phone_plan_group_id + ) + print('list_phone_plans:') + async for phone_plan in phone_plans_response: + print(phone_plan) + + async def get_phone_plan_location_options(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + async with self._phone_number_administration_client: + location_options_response = await self._phone_number_administration_client.get_phone_plan_location_options( + country_code=self.country_code, + phone_plan_group_id=self.phone_plan_group_id, + phone_plan_id=self.phone_plan_id + ) + print('get_phone_plan_location_options:') + print(location_options_response) + + +async def main(): + sample = CommunicationPhoneNumberPlansSamplesAsync() + await sample.list_phone_plan_groups() + await sample.list_phone_plans() + await sample.get_phone_plan_location_options() + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample.py new file mode 100644 index 0000000000000..71e2809f1fef5 --- /dev/null +++ b/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample.py @@ -0,0 +1,38 @@ +# 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: phone_number_supported_countries_sample.py +DESCRIPTION: + These samples demonstrate supported countries samples. + + ///getting supported countries via a connection string +USAGE: + python phone_number_supported_countries_sample.py +""" +import os +from azure.communication.administration import ( + PhoneNumberAdministrationClient +) + +class CommunicationSupportedCountriesSamples(object): + + def __init__(self): + self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + + def list_all_supported_countries(self): + supported_countries = self._phone_number_administration_client.list_all_supported_countries() + print('supported_countries:') + for supported_country in supported_countries: + print(supported_country) + +if __name__ == '__main__': + sample = CommunicationSupportedCountriesSamples() + sample.list_all_supported_countries() diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample_async.py new file mode 100644 index 0000000000000..cac5f7d017138 --- /dev/null +++ b/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample_async.py @@ -0,0 +1,43 @@ +# 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: phone_number_supported_countries_sample_async.py +DESCRIPTION: + These samples demonstrate supported countries samples. + + ///getting supported countries via a connection string +USAGE: + python phone_number_supported_countries_sample_async.py +""" +import os +import asyncio +from azure.communication.administration.aio import PhoneNumberAdministrationClient + +class CommunicationSupportedCountriesSamplesAsync(object): + + def __init__(self): + self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') + + async def list_all_supported_countries(self): + self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + self.connection_str) + async with self._phone_number_administration_client: + supported_countries = self._phone_number_administration_client.list_all_supported_countries() + print('supported_countries:') + async for supported_country in supported_countries: + print(supported_country) + + +async def main(): + sample = CommunicationSupportedCountriesSamplesAsync() + await sample.list_all_supported_countries() + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) From 257851b33d7bcc6a6d7dad0c24a1941ddc32934a Mon Sep 17 00:00:00 2001 From: Eason Yang Date: Thu, 1 Oct 2020 15:20:01 -0700 Subject: [PATCH 2/6] address comments --- .../samples/phone_number_area_codes_sample.py | 44 +++-- .../phone_number_area_codes_sample_async.py | 53 +++--- .../phone_number_capabilities_sample.py | 92 +++++---- .../phone_number_capabilities_sample_async.py | 103 +++++----- .../phone_number_configuration_sample.py | 67 ++++--- ...phone_number_configuration_sample_async.py | 70 +++---- .../samples/phone_number_orders_sample.py | 156 ++++++++------- .../phone_number_orders_sample_async.py | 180 ++++++++++-------- .../samples/phone_number_plans_sample.py | 95 ++++----- .../phone_number_plans_sample_async.py | 99 +++++----- ...phone_number_supported_countries_sample.py | 33 ++-- ...number_supported_countries_sample_async.py | 36 ++-- 12 files changed, 554 insertions(+), 474 deletions(-) diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample.py index d3760eda1dac1..143f359ae6ae6 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample.py @@ -9,35 +9,37 @@ """ FILE: phone_number_area_codes_sample.py DESCRIPTION: - These samples demonstrate area codes samples. - - ///getting all area codes via a connection string, country code and phone plan id + This sample demonstrates how to get all area codes via a connection string, country code and phone plan id. USAGE: - python phone_number_area_codes_sample.py + phone_number_area_codes_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_PHONENUMBERS_COUNTRY_CODE - The country code you want to get area codes from + 3) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID_AREA_CODES - The phone plan id you want to get area codes from """ + import os from azure.communication.administration import ( PhoneNumberAdministrationClient ) -class CommunicationAreaCodesSamples(object): +connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') +phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) +country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") +phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID_AREA_CODES', "phone-plan-id") + - def __init__(self): - self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - self.country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_COUNTRY_CODE', "US") - self.phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID_AREA_CODES', "phone-plan-id") +def get_all_area_codes(): + # [START get_all_area_codes] + all_area_codes = phone_number_administration_client.get_all_area_codes( + location_type="NotRequired", + country_code=country_code, + phone_plan_id=phone_plan_id_area_codes + ) + # [END get_all_area_codes] + print('all_area_codes:') + print(all_area_codes) - def get_all_area_codes(self): - all_area_codes = self._phone_number_administration_client.get_all_area_codes( - location_type="NotRequired", - country_code=self.country_code, - phone_plan_id=self.phone_plan_id_area_codes - ) - print('all_area_codes:') - print(all_area_codes) if __name__ == '__main__': - sample = CommunicationAreaCodesSamples() - sample.get_all_area_codes() + get_all_area_codes() diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample_async.py index f9e5e21d40b72..f868c52f11850 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample_async.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample_async.py @@ -7,40 +7,43 @@ # -------------------------------------------------------------------------- """ -FILE: phone_number_area_codes_sample.py +FILE: phone_number_area_codes_sample_async.py DESCRIPTION: - These samples demonstrate area codes samples. - - ///getting all area codes via a connection string, country code and phone plan id + This sample demonstrates how to get all area codes via a connection string, country code and phone plan id. USAGE: - python phone_number_area_codes_sample.py + phone_number_area_codes_sample_async.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_PHONENUMBERS_COUNTRY_CODE - The country code you want to get area codes from + 3) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID_AREA_CODES - The phone plan id you want to get area codes from """ + import os import asyncio from azure.communication.administration.aio import PhoneNumberAdministrationClient -class CommunicationAreaCodesSamplesAsync(object): - - def __init__(self): - self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') - self.country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_COUNTRY_CODE', "US") - self.phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID_AREA_CODES', "phone-plan-id") - - async def get_all_area_codes(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - async with self._phone_number_administration_client: - all_area_codes = await self._phone_number_administration_client.get_all_area_codes( - location_type="NotRequired", - country_code=self.country_code, - phone_plan_id=self.phone_plan_id_area_codes - ) - print('all_area_codes:') - print(all_area_codes) +connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') +country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") +phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID_AREA_CODES', "phone-plan-id") + + +async def get_all_area_codes(): + # [START get_all_area_codes] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( + connection_str) + async with phone_number_administration_client: + all_area_codes = await phone_number_administration_client.get_all_area_codes( + location_type="NotRequired", + country_code=country_code, + phone_plan_id=phone_plan_id_area_codes + ) + # [END get_all_area_codes] + print('all_area_codes:') + print(all_area_codes) + async def main(): - sample = CommunicationAreaCodesSamplesAsync() - await sample.get_all_area_codes() + await get_all_area_codes() if __name__ == '__main__': loop = asyncio.get_event_loop() diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample.py index 5c3f81880ff4c..162c3d8941f99 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample.py @@ -9,55 +9,63 @@ """ FILE: phone_number_capabilities_sample.py DESCRIPTION: - These samples demonstrate number capabilities samples. - - ///getting number capabilities via a connection string, capabilities update id and phone number for capabilities + This sample demonstrates how to get number capabilities via a connection string, capabilities update id and phone number for capabilities. USAGE: - python phone_number_capabilities_sample.py + 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_PHONENUMBERS_CAPABILITIES_ID - The capabilities id you want to get + 3) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_FOR_CAPABILITIES - The phone number you want to update capabilities to """ + import os from azure.communication.administration import ( PhoneNumberAdministrationClient, NumberUpdateCapabilities ) -class CommunicationNumberCapabilitiesSamples(object): - - def __init__(self): - self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - self.capabilities_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_CAPABILITIES_ID', "capabilities-id") - self.phonenumber_for_capabilities = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_FOR_CAPABILITIES', "+17771234567") - - def list_all_phone_numbers(self): - list_all_phone_numbers_response = self._phone_number_administration_client.list_all_phone_numbers() - print('list_all_phone_numbers_response:') - for phone_number in list_all_phone_numbers_response: - print(phone_number) - - def get_capabilities_update(self): - capabilities_response = self._phone_number_administration_client.get_capabilities_update( - capabilities_update_id=self.capabilities_id - ) - print('capabilities_response:') - print(capabilities_response) - - def update_capabilities(self): - update = NumberUpdateCapabilities(add=iter(["InboundCalling"])) - - phone_number_capabilities_update = { - self.phonenumber_for_capabilities: update - } - - capabilities_response = self._phone_number_administration_client.update_capabilities( - phone_number_capabilities_update=phone_number_capabilities_update - ) - print('capabilities_response:') - print(capabilities_response) +connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') +phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) +capabilities_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_CAPABILITIES_ID', "capabilities-id") +phonenumber_for_capabilities = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_FOR_CAPABILITIES', "+17771234567") + + +def list_all_phone_numbers(): + # [START list_all_phone_numbers] + list_all_phone_numbers_response = phone_number_administration_client.list_all_phone_numbers() + # [END list_all_phone_numbers] + print('list_all_phone_numbers_response:') + for phone_number in list_all_phone_numbers_response: + print(phone_number) + + +def get_capabilities_update(): + # [START get_capabilities_update] + capabilities_response = phone_number_administration_client.get_capabilities_update( + capabilities_update_id=capabilities_id + ) + # [END get_capabilities_update] + print('capabilities_response:') + print(capabilities_response) + + +def update_capabilities(): + # [START update_capabilities] + update = NumberUpdateCapabilities(add=iter(["InboundCalling"])) + + phone_number_capabilities_update = { + phonenumber_for_capabilities: update + } + + capabilities_response = phone_number_administration_client.update_capabilities( + phone_number_capabilities_update=phone_number_capabilities_update + ) + # [END update_capabilities] + print('capabilities_response:') + print(capabilities_response) + if __name__ == '__main__': - sample = CommunicationNumberCapabilitiesSamples() - sample.list_all_phone_numbers() - sample.get_capabilities_update() - sample.update_capabilities() + list_all_phone_numbers() + get_capabilities_update() + update_capabilities() diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample_async.py index 17a0c9447c0bf..5cca02ad12c5b 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample_async.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample_async.py @@ -7,69 +7,74 @@ # -------------------------------------------------------------------------- """ -FILE: phone_number_capabilities_sample.py +FILE: phone_number_capabilities_sample_async.py DESCRIPTION: - These samples demonstrate number capabilities samples. - - ///getting number capabilities via a connection string, capabilities update id and phone number for capabilities + This sample demonstrates how to get number capabilities via a connection string, capabilities update id and phone number for capabilities. USAGE: - python phone_number_capabilities_sample.py + phone_number_capabilities_sample_async.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_PHONENUMBERS_CAPABILITIES_ID - The capabilities id you want to get + 3) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_FOR_CAPABILITIES - The phone number you want to update capabilities to """ + import asyncio import os from azure.communication.administration.aio import PhoneNumberAdministrationClient from azure.communication.administration import NumberUpdateCapabilities -class CommunicationNumberCapabilitiesSamplesAsync(object): - - def __init__(self): - self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') - self.capabilities_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_CAPABILITIES_ID', "capabilities-id") - self.phonenumber_for_capabilities = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_FOR_CAPABILITIES', +connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') +capabilities_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_CAPABILITIES_ID', "capabilities-id") +phonenumber_for_capabilities = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_FOR_CAPABILITIES', "phone-number-for-capabilities") - async def list_all_phone_numbers(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - async with self._phone_number_administration_client: - list_all_phone_numbers_response = self._phone_number_administration_client.list_all_phone_numbers() - print('list_all_phone_numbers_response:') - async for phone_number in list_all_phone_numbers_response: - print(phone_number) - - async def get_capabilities_update(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - async with self._phone_number_administration_client: - capabilities_response = await self._phone_number_administration_client.get_capabilities_update( - capabilities_update_id=self.capabilities_id - ) - print('capabilities_response:') - print(capabilities_response) - - async def update_capabilities(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - update = NumberUpdateCapabilities(add=iter(["InboundCalling"])) - - phone_number_capabilities_update = { - self.phonenumber_for_capabilities: update - } - - async with self._phone_number_administration_client: - capabilities_response = await self._phone_number_administration_client.update_capabilities( - phone_number_capabilities_update=phone_number_capabilities_update - ) - print('capabilities_response:') - print(capabilities_response) + +async def list_all_phone_numbers(): + # [START list_all_phone_numbers] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + async with phone_number_administration_client: + list_all_phone_numbers_response = phone_number_administration_client.list_all_phone_numbers() + print('list_all_phone_numbers_response:') + async for phone_number in list_all_phone_numbers_response: + print(phone_number) + # [END list_all_phone_numbers] + + +async def get_capabilities_update(): + # [START get_capabilities_update] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + async with phone_number_administration_client: + capabilities_response = await phone_number_administration_client.get_capabilities_update( + capabilities_update_id=capabilities_id + ) + print('capabilities_response:') + print(capabilities_response) + # [END get_capabilities_update] + + +async def update_capabilities(): + # [START update_capabilities] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + update = NumberUpdateCapabilities(add=iter(["InboundCalling"])) + + phone_number_capabilities_update = { + phonenumber_for_capabilities: update + } + + async with phone_number_administration_client: + capabilities_response = await phone_number_administration_client.update_capabilities( + phone_number_capabilities_update=phone_number_capabilities_update + ) + print('capabilities_response:') + print(capabilities_response) + # [END update_capabilities] async def main(): - sample = CommunicationNumberCapabilitiesSamplesAsync() - await sample.list_all_phone_numbers() - await sample.get_capabilities_update() - await sample.update_capabilities() + await list_all_phone_numbers() + await get_capabilities_update() + await update_capabilities() if __name__ == '__main__': diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample.py index 29359d16a7f43..24cf07ddbcad5 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample.py @@ -9,46 +9,51 @@ """ FILE: phone_number_configuration_sample.py DESCRIPTION: - These samples demonstrate phone number configuration samples. - - ///listing phone plans via a connection string and phone number to configure + This sample demonstrates how to configure phone numbers and get phone number configuration via a connection string and phone number to configure USAGE: - python phone_number_configuration_sample.py + phone_number_configuration_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_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE - The phone number you want to configure """ + + import os from azure.communication.administration import ( PhoneNumberAdministrationClient, PstnConfiguration ) -class CommunicationPhoneNumberConfigurationSamples(object): - - def __init__(self): - self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - self.phonenumber_to_configure = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_TO_CONFIGURE', +connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') +phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) +phonenumber_to_configure = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE', "phonenumber_to_configure") - def get_number_configuration(self): - phone_number_configuration_response = self._phone_number_administration_client.get_number_configuration( - phone_number=self.phonenumber_to_configure - ) - print('phone_number_configuration_response:') - print(phone_number_configuration_response) - - def configure_number(self): - pstn_config = PstnConfiguration( - callback_url="https://callbackurl", - application_id="ApplicationId", - azure_pstn_target_id="AzurePstnTargetId" - ) - self._phone_number_administration_client.configure_number( - pstn_configuration=pstn_config, - phone_number=self.phonenumber_to_configure - ) + +def get_number_configuration(): + # [START get_number_configuration] + phone_number_configuration_response = phone_number_administration_client.get_number_configuration( + phone_number=phonenumber_to_configure + ) + # [END get_number_configuration] + print('phone_number_configuration_response:') + print(phone_number_configuration_response) + + +def configure_number(): + # [START configure_number] + pstn_config = PstnConfiguration( + callback_url="https://callbackurl", + application_id="ApplicationId", + azure_pstn_target_id="AzurePstnTargetId" + ) + phone_number_administration_client.configure_number( + pstn_configuration=pstn_config, + phone_number=phonenumber_to_configure + ) + # [END configure_number] + if __name__ == '__main__': - sample = CommunicationPhoneNumberConfigurationSamples() - sample.get_number_configuration() - sample.configure_number() + get_number_configuration() + configure_number() diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample_async.py index f15e3b9bfe6c2..1f02bb744e84e 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample_async.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample_async.py @@ -9,53 +9,55 @@ """ FILE: phone_number_configuration_sample_async.py DESCRIPTION: - These samples demonstrate phone number configuration samples. - - ///listing phone plans via a connection string and phone number to configure + This sample demonstrates how to configure phone numbers and get phone number configuration via a connection string and phone number to configure USAGE: - python phone_number_configuration_sample_async.py + phone_number_configuration_sample_async.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_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE - The phone number you want to configure """ + import os import asyncio from azure.communication.administration.aio import PhoneNumberAdministrationClient from azure.communication.administration import PstnConfiguration -class CommunicationPhoneNumberConfigurationSamplesAsync(object): - - def __init__(self): - self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') - self.phonenumber_to_configure = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_TO_CONFIGURE', +connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') +phonenumber_to_configure = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE', "phonenumber_to_configure") - async def get_number_configuration(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - async with self._phone_number_administration_client: - phone_number_configuration_response = await self._phone_number_administration_client.get_number_configuration( - phone_number=self.phonenumber_to_configure - ) - print('phone_number_configuration_response:') - print(phone_number_configuration_response) - - async def configure_number(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - pstn_config = PstnConfiguration( - callback_url="https://callbackurl", - application_id="ApplicationId", - azure_pstn_target_id="AzurePstnTargetId" + +async def get_number_configuration(): + # [START get_number_configuration] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + async with phone_number_administration_client: + phone_number_configuration_response = await phone_number_administration_client.get_number_configuration( + phone_number=phonenumber_to_configure + ) + print('phone_number_configuration_response:') + print(phone_number_configuration_response) + # [END get_number_configuration] + + +async def configure_number(): + # [START configure_number] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + pstn_config = PstnConfiguration( + callback_url="https://callbackurl", + application_id="ApplicationId", + azure_pstn_target_id="AzurePstnTargetId" + ) + async with phone_number_administration_client: + await phone_number_administration_client.configure_number( + pstn_configuration=pstn_config, + phone_number=phonenumber_to_configure ) - async with self._phone_number_administration_client: - await self._phone_number_administration_client.configure_number( - pstn_configuration=pstn_config, - phone_number=self.phonenumber_to_configure - ) + # [END configure_number] async def main(): - sample = CommunicationPhoneNumberConfigurationSamplesAsync() - await sample.get_number_configuration() - await sample.configure_number() + await get_number_configuration() + await configure_number() if __name__ == '__main__': loop = asyncio.get_event_loop() diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample.py index 2d01e440750db..f0f74b4a724cf 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample.py @@ -9,80 +9,102 @@ """ FILE: phone_number_orders_sample.py DESCRIPTION: - These samples demonstrate phone number orders samples. - - ///listing, acquiring and cancelling phone number orders via a connection string, search id, phone plan id and and area code + This sample demonstrates how to list, acquire and cancel phone number orders via a connection string, search id, phone plan id and and area code USAGE: - python phone_number_orders_sample.py + phone_number_orders_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_PHONENUMBERS_RELEASE_ID - The release id you want to get info from + 3) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID - The search id you want to get info from + 4) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_AREA_CODE_FOR_SEARCH - The phone number you want to create search + 5) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID - The phone plan id + 6) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_PURCHASE - The search id you want to purchase + 7) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_CANCEL - The search id you want to cancel """ + + import os from azure.communication.administration import ( PhoneNumberAdministrationClient, CreateSearchOptions ) -class CommunicationPhoneNumberOrdersSamples(object): - - def __init__(self): - self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - self.release_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_RELEASE_ID', "release-id") - self.search_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID', "search-id") - self.area_code_for_search = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_AREA_CODE_FOR_SEARCH', "area-code") - self.phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID', "phone-plan-id") - self.search_id_to_purchase = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID_TO_PURCHASE', "search-id") - self.search_id_to_cancel = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID_TO_CANCEL', "search-id") - - def get_release_by_id(self): - phone_number_release_response = self._phone_number_administration_client.get_release_by_id( - release_id=self.release_id - ) - print('phone_number_release_response:') - print(phone_number_release_response) - - def list_all_releases(self): - releases_response = self._phone_number_administration_client.list_all_releases() - print('releases_response:') - for release in releases_response: - print(release) - - def get_search_by_id(self): - phone_number_search_response = self._phone_number_administration_client.get_search_by_id( - search_id=self.search_id - ) - print('phone_number_search_response:') - print(phone_number_search_response) - - def create_search(self): - searchOptions = CreateSearchOptions( - area_code=self.area_code_for_search, - description="testsearch20200014", - display_name="testsearch20200014", - phone_plan_ids=[self.phone_plan_id], - quantity=1 - ) - search_response = self._phone_number_administration_client.create_search( - body=searchOptions - ) - print('search_response:') - print(search_response) - - def cancel_search(self): - self._phone_number_administration_client.cancel_search( - search_id=self.search_id_to_cancel - ) - - def purchase_search(self): - self._phone_number_administration_client.purchase_search( - search_id=self.search_id_to_purchase - ) +connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') +phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) +release_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RELEASE_ID', "release-id") +search_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID', "search-id") +area_code_for_search = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_AREA_CODE_FOR_SEARCH', "area-code") +phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID', "phone-plan-id") +search_id_to_purchase = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_PURCHASE', "search-id") +search_id_to_cancel = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_CANCEL', "search-id") + + +def get_release_by_id(): + # [START get_release_by_id] + phone_number_release_response = phone_number_administration_client.get_release_by_id( + release_id=release_id + ) + # [END get_release_by_id] + print('phone_number_release_response:') + print(phone_number_release_response) + + +def list_all_releases(): + # [START get_release_by_id] + releases_response = phone_number_administration_client.list_all_releases() + # [END get_release_by_id] + print('releases_response:') + for release in releases_response: + print(release) + + +def get_search_by_id(): + # [START get_search_by_id] + phone_number_search_response = phone_number_administration_client.get_search_by_id( + search_id=search_id + ) + # [END get_search_by_id] + print('phone_number_search_response:') + print(phone_number_search_response) + + +def create_search(): + # [START create_search] + searchOptions = CreateSearchOptions( + area_code=area_code_for_search, + description="testsearch20200014", + display_name="testsearch20200014", + phone_plan_ids=[phone_plan_id], + quantity=1 + ) + search_response = phone_number_administration_client.create_search( + body=searchOptions + ) + # [END create_search] + print('search_response:') + print(search_response) + + +def cancel_search(): + # [START cancel_search] + phone_number_administration_client.cancel_search( + search_id=search_id_to_cancel + ) + # [START cancel_search] + + +def purchase_search(): + # [START cancel_search] + phone_number_administration_client.purchase_search( + search_id=search_id_to_purchase + ) + # [END cancel_search] + if __name__ == '__main__': - sample = CommunicationPhoneNumberOrdersSamples() - sample.get_release_by_id() - sample.list_all_releases() - sample.get_search_by_id() - sample.create_search() - sample.cancel_search() - # sample.purchase_search() #currently throws error if purchase an already purchased number + get_release_by_id() + list_all_releases() + get_search_by_id() + create_search() + cancel_search() + # purchase_search() #currently throws error if purchase an already purchased number diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample_async.py index adb23ac7714a3..ef40428b0848a 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample_async.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample_async.py @@ -9,99 +9,115 @@ """ FILE: phone_number_orders_sample_async.py DESCRIPTION: - These samples demonstrate phone number orders samples. - - ///listing, acquiring and cancelling phone number orders via a connection string, search id, phone plan id and and area code + This sample demonstrates how to list, acquire and cancel phone number orders via a connection string, search id, phone plan id and and area code USAGE: - python phone_number_orders_sample_async.py + phone_number_orders_sample_async.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_PHONENUMBERS_RELEASE_ID - The release id you want to get info from + 3) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID - The search id you want to get info from + 4) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_AREA_CODE_FOR_SEARCH - The phone number you want to create search + 5) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID - The phone plan id + 6) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_PURCHASE - The search id you want to purchase + 7) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_CANCEL - The search id you want to cancel """ + import os import asyncio from azure.communication.administration.aio import PhoneNumberAdministrationClient from azure.communication.administration import CreateSearchOptions -class CommunicationPhoneNumberOrdersSamplesAsync(object): - - def __init__(self): - self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') - self.release_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_RELEASE_ID', "release-id") - self.search_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID', "search-id") - self.area_code_for_search = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_AREA_CODE_FOR_SEARCH', "area-code") - self.phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID', "phone-plan-id") - self.search_id_to_purchase = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID_TO_PURCHASE', "search-id") - self.search_id_to_cancel = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID_TO_CANCEL', "search-id") - - async def get_release_by_id(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - async with self._phone_number_administration_client: - phone_number_release_response = await self._phone_number_administration_client.get_release_by_id( - release_id=self.release_id - ) - print('phone_number_release_response:') - print(phone_number_release_response) - - async def list_all_releases(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - async with self._phone_number_administration_client: - releases_response = self._phone_number_administration_client.list_all_releases() - print('releases_response:') - async for release in releases_response: - print(release) - - async def get_search_by_id(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - async with self._phone_number_administration_client: - phone_number_search_response = await self._phone_number_administration_client.get_search_by_id( - search_id=self.search_id - ) - print('phone_number_search_response:') - print(phone_number_search_response) - - async def create_search(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - searchOptions = CreateSearchOptions( - area_code=self.area_code_for_search, - description="testsearch20200014", - display_name="testsearch20200014", - phone_plan_ids=[self.phone_plan_id], - quantity=1 +connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') +release_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RELEASE_ID', "release-id") +search_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID', "search-id") +area_code_for_search = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_AREA_CODE_FOR_SEARCH', "area-code") +phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID', "phone-plan-id") +search_id_to_purchase = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_PURCHASE', "search-id") +search_id_to_cancel = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_CANCEL', "search-id") + + +async def get_release_by_id(): + # [START get_release_by_id] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + async with phone_number_administration_client: + phone_number_release_response = await phone_number_administration_client.get_release_by_id( + release_id=release_id + ) + print('phone_number_release_response:') + print(phone_number_release_response) + # [END get_release_by_id] + + +async def list_all_releases(): + # [START list_all_releases] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + async with phone_number_administration_client: + releases_response = phone_number_administration_client.list_all_releases() + print('releases_response:') + async for release in releases_response: + print(release) + # [END list_all_releases] + + +async def get_search_by_id(): + # [START get_search_by_id] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + async with phone_number_administration_client: + phone_number_search_response = await phone_number_administration_client.get_search_by_id( + search_id=search_id + ) + print('phone_number_search_response:') + print(phone_number_search_response) + await phone_number_administration_client.close() + # [END get_search_by_id] + + +async def create_search(): + # [START create_search] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + searchOptions = CreateSearchOptions( + area_code=area_code_for_search, + description="testsearch20200014", + display_name="testsearch20200014", + phone_plan_ids=[phone_plan_id], + quantity=1 + ) + async with phone_number_administration_client: + search_response = await phone_number_administration_client.create_search( + body=searchOptions + ) + print('search_response:') + print(search_response) + # [END create_search] + + +async def cancel_search(): + # [START cancel_search] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + async with phone_number_administration_client: + await phone_number_administration_client.cancel_search( + search_id=search_id_to_cancel + ) + # [END cancel_search] + + +async def purchase_search(): + # [START purchase_search] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + async with phone_number_administration_client: + await phone_number_administration_client.purchase_search( + search_id=search_id_to_purchase ) - async with self._phone_number_administration_client: - search_response = await self._phone_number_administration_client.create_search( - body=searchOptions - ) - print('search_response:') - print(search_response) - - async def cancel_search(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - async with self._phone_number_administration_client: - await self._phone_number_administration_client.cancel_search( - search_id=self.search_id_to_cancel - ) - - async def purchase_search(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - async with self._phone_number_administration_client: - await self._phone_number_administration_client.purchase_search( - search_id=self.search_id_to_purchase - ) + # [END purchase_search] async def main(): - sample = CommunicationPhoneNumberOrdersSamplesAsync() - await sample.get_release_by_id() - await sample.list_all_releases() - await sample.get_search_by_id() - await sample.create_search() - await sample.cancel_search() - await sample.purchase_search() #currently throws error if purchase an already purchased number + await get_release_by_id() + await list_all_releases() + await get_search_by_id() + await create_search() + await cancel_search() + # await purchase_search() #currently throws error if purchase an already purchased number if __name__ == '__main__': loop = asyncio.get_event_loop() diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample.py index 5fcfd9e87e609..bfa3b005dd50e 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample.py @@ -9,55 +9,64 @@ """ FILE: phone_number_plans_sample.py DESCRIPTION: - These samples demonstrate phone plan samples. - - ///listing phone plans via a connection string, country code, phone plan id and phone plan group id + This sample demonstrates how to list phone plans via a connection string, country code, phone plan id and phone plan group id USAGE: - python phone_number_plans_sample.py + phone_number_plans_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_PHONENUMBERS_COUNTRY_CODE - The country code + 3) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_GROUP_ID - The phone plan group id you want to use to list phone plans + 4) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID - The phone plan id you want to use to get location options """ + import os from azure.communication.administration import ( PhoneNumberAdministrationClient ) -class CommunicationPhonePlansSamples(object): - - def __init__(self): - self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - self.country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_COUNTRY_CODE', "US") - self.phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_GROUP_ID', "phone-plan-group-id") - self.phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID', "phone-plan-id") - - def list_phone_plan_groups(self): - phone_plan_groups_response = self._phone_number_administration_client.list_phone_plan_groups( - country_code=self.country_code - ) - print('list_phone_plan_groups:') - for phone_plan_group in phone_plan_groups_response: - print(phone_plan_group) - - def list_phone_plans(self): - phone_plans_response = self._phone_number_administration_client.list_phone_plans( - country_code=self.country_code, - phone_plan_group_id=self.phone_plan_group_id - ) - print('list_phone_plans:') - for phone_plan in phone_plans_response: - print(phone_plan) - - def get_phone_plan_location_options(self): - location_options_response = self._phone_number_administration_client.get_phone_plan_location_options( - country_code=self.country_code, - phone_plan_group_id=self.phone_plan_group_id, - phone_plan_id=self.phone_plan_id - ) - print('get_phone_plan_location_options:') - print(location_options_response) +connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') +phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) +country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") +phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_GROUP_ID', "phone-plan-group-id") +phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID', "phone-plan-id") + + +def list_phone_plan_groups(): + # [START list_phone_plan_groups] + phone_plan_groups_response = phone_number_administration_client.list_phone_plan_groups( + country_code=country_code + ) + # [END list_phone_plan_groups] + print('list_phone_plan_groups:') + for phone_plan_group in phone_plan_groups_response: + print(phone_plan_group) + + +def list_phone_plans(): + # [START list_phone_plans] + phone_plans_response = phone_number_administration_client.list_phone_plans( + country_code=country_code, + phone_plan_group_id=phone_plan_group_id + ) + # [END list_phone_plans] + print('list_phone_plans:') + for phone_plan in phone_plans_response: + print(phone_plan) + + +def get_phone_plan_location_options(): + # [START get_phone_plan_location_options] + location_options_response = phone_number_administration_client.get_phone_plan_location_options( + country_code=country_code, + phone_plan_group_id=phone_plan_group_id, + phone_plan_id=phone_plan_id + ) + # [END get_phone_plan_location_options] + print('get_phone_plan_location_options:') + print(location_options_response) + if __name__ == '__main__': - sample = CommunicationPhonePlansSamples() - sample.list_phone_plan_groups() - sample.list_phone_plans() - sample.get_phone_plan_location_options() + list_phone_plan_groups() + list_phone_plans() + get_phone_plan_location_options() diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample_async.py index 1c96b4c950258..6f0616fc57701 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample_async.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample_async.py @@ -9,65 +9,72 @@ """ FILE: phone_number_plans_sample_async.py DESCRIPTION: - These samples demonstrate phone plan samples. - - ///listing phone plans via a connection string, country code, phone plan id and phone plan group id + This sample demonstrates how to list phone plans via a connection string, country code, phone plan id and phone plan group id USAGE: - python phone_number_plans_sample_async.py + phone_number_plans_sample_async.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_PHONENUMBERS_COUNTRY_CODE - The country code + 3) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_GROUP_ID - The phone plan group id you want to use to list phone plans + 4) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID - The phone plan id you want to use to get location options """ + + import os import asyncio from azure.communication.administration.aio import PhoneNumberAdministrationClient -class CommunicationPhoneNumberPlansSamplesAsync(object): +connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') +country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") +phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_GROUP_ID', "phone-plan-group-id") +phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID', "phone-plan-id") + + +async def list_phone_plan_groups(): + # [START list_phone_plan_groups] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + async with phone_number_administration_client: + phone_plan_groups_response = phone_number_administration_client.list_phone_plan_groups( + country_code=country_code + ) + print('list_phone_plan_groups:') + async for phone_plan_group in phone_plan_groups_response: + print(phone_plan_group) + # [END list_phone_plan_groups] - def __init__(self): - self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') - self.country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_COUNTRY_CODE', "US") - self.phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_GROUP_ID', "phone-plan-group-id") - self.phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID', "phone-plan-id") - async def list_phone_plan_groups(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - async with self._phone_number_administration_client: - phone_plan_groups_response = self._phone_number_administration_client.list_phone_plan_groups( - country_code=self.country_code - ) - print('list_phone_plan_groups:') - async for phone_plan_group in phone_plan_groups_response: - print(phone_plan_group) +async def list_phone_plans(): + # [START list_phone_plans] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + async with phone_number_administration_client: + phone_plans_response = phone_number_administration_client.list_phone_plans( + country_code=country_code, + phone_plan_group_id=phone_plan_group_id + ) + print('list_phone_plans:') + async for phone_plan in phone_plans_response: + print(phone_plan) + # [END list_phone_plans] - async def list_phone_plans(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - async with self._phone_number_administration_client: - phone_plans_response = self._phone_number_administration_client.list_phone_plans( - country_code=self.country_code, - phone_plan_group_id=self.phone_plan_group_id - ) - print('list_phone_plans:') - async for phone_plan in phone_plans_response: - print(phone_plan) - async def get_phone_plan_location_options(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - async with self._phone_number_administration_client: - location_options_response = await self._phone_number_administration_client.get_phone_plan_location_options( - country_code=self.country_code, - phone_plan_group_id=self.phone_plan_group_id, - phone_plan_id=self.phone_plan_id - ) - print('get_phone_plan_location_options:') - print(location_options_response) +async def get_phone_plan_location_options(): + # [START get_phone_plan_location_options] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + async with phone_number_administration_client: + location_options_response = await phone_number_administration_client.get_phone_plan_location_options( + country_code=country_code, + phone_plan_group_id=phone_plan_group_id, + phone_plan_id=phone_plan_id + ) + print('get_phone_plan_location_options:') + print(location_options_response) + # [START get_phone_plan_location_options] async def main(): - sample = CommunicationPhoneNumberPlansSamplesAsync() - await sample.list_phone_plan_groups() - await sample.list_phone_plans() - await sample.get_phone_plan_location_options() + await list_phone_plan_groups() + await list_phone_plans() + await get_phone_plan_location_options() if __name__ == '__main__': loop = asyncio.get_event_loop() diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample.py index 71e2809f1fef5..0177c585fe9c2 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample.py @@ -9,30 +9,31 @@ """ FILE: phone_number_supported_countries_sample.py DESCRIPTION: - These samples demonstrate supported countries samples. - - ///getting supported countries via a connection string + This sample demonstrates how to get supported countries via a connection string USAGE: - python phone_number_supported_countries_sample.py + phone_number_supported_countries_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 """ + + import os from azure.communication.administration import ( PhoneNumberAdministrationClient ) -class CommunicationSupportedCountriesSamples(object): +connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') +phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + - def __init__(self): - self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) +def list_all_supported_countries(): + # [START list_all_supported_countries] + supported_countries = phone_number_administration_client.list_all_supported_countries() + # [END list_all_supported_countries] + print('supported_countries:') + for supported_country in supported_countries: + print(supported_country) - def list_all_supported_countries(self): - supported_countries = self._phone_number_administration_client.list_all_supported_countries() - print('supported_countries:') - for supported_country in supported_countries: - print(supported_country) if __name__ == '__main__': - sample = CommunicationSupportedCountriesSamples() - sample.list_all_supported_countries() + list_all_supported_countries() diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample_async.py index cac5f7d017138..692c5ede2aa83 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample_async.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample_async.py @@ -7,36 +7,36 @@ # -------------------------------------------------------------------------- """ -FILE: phone_number_supported_countries_sample_async.py +FILE: phone_number_supported_countries_sample.py DESCRIPTION: - These samples demonstrate supported countries samples. - - ///getting supported countries via a connection string + This sample demonstrates how to get supported countries via a connection string USAGE: - python phone_number_supported_countries_sample_async.py + phone_number_supported_countries_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 """ + + import os import asyncio from azure.communication.administration.aio import PhoneNumberAdministrationClient -class CommunicationSupportedCountriesSamplesAsync(object): +connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') - def __init__(self): - self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') - async def list_all_supported_countries(self): - self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( - self.connection_str) - async with self._phone_number_administration_client: - supported_countries = self._phone_number_administration_client.list_all_supported_countries() - print('supported_countries:') - async for supported_country in supported_countries: - print(supported_country) +async def list_all_supported_countries(): + # [START list_all_supported_countries] + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + async with phone_number_administration_client: + supported_countries = phone_number_administration_client.list_all_supported_countries() + print('supported_countries:') + async for supported_country in supported_countries: + print(supported_country) + # [END list_all_supported_countries] async def main(): - sample = CommunicationSupportedCountriesSamplesAsync() - await sample.list_all_supported_countries() + await list_all_supported_countries() if __name__ == '__main__': loop = asyncio.get_event_loop() From 8b5bccbe5d5556298c8b06eb5ef450f5561da0bc Mon Sep 17 00:00:00 2001 From: Eason Yang Date: Thu, 1 Oct 2020 16:24:52 -0700 Subject: [PATCH 3/6] update samples with long run operation --- .../samples/phone_number_area_codes_sample.py | 2 +- .../samples/phone_number_area_codes_sample_async.py | 2 +- .../samples/phone_number_capabilities_sample.py | 2 +- .../phone_number_capabilities_sample_async.py | 2 +- .../samples/phone_number_configuration_sample.py | 5 ++--- .../phone_number_configuration_sample_async.py | 5 ++--- .../samples/phone_number_orders_sample.py | 12 ++++++------ .../samples/phone_number_orders_sample_async.py | 12 ++++++------ .../samples/phone_number_plans_sample.py | 2 +- .../samples/phone_number_plans_sample_async.py | 2 +- .../phone_number_supported_countries_sample.py | 2 +- .../phone_number_supported_countries_sample_async.py | 2 +- 12 files changed, 24 insertions(+), 26 deletions(-) diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample.py index 143f359ae6ae6..009c008abcea2 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to get all area codes via a connection string, country code and phone plan id. USAGE: - phone_number_area_codes_sample.py + python phone_number_area_codes_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_PHONENUMBERS_COUNTRY_CODE - The country code you want to get area codes from diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample_async.py index f868c52f11850..0cc953b9d1e15 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample_async.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_area_codes_sample_async.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to get all area codes via a connection string, country code and phone plan id. USAGE: - phone_number_area_codes_sample_async.py + python phone_number_area_codes_sample_async.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_PHONENUMBERS_COUNTRY_CODE - The country code you want to get area codes from diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample.py index 162c3d8941f99..44b9dcb1a8796 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to get number capabilities via a connection string, capabilities update id and phone number for capabilities. USAGE: - phone_number_capabilities_sample.py + python 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_PHONENUMBERS_CAPABILITIES_ID - The capabilities id you want to get diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample_async.py index 5cca02ad12c5b..f45c6a430f04f 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample_async.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_capabilities_sample_async.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to get number capabilities via a connection string, capabilities update id and phone number for capabilities. USAGE: - phone_number_capabilities_sample_async.py + python phone_number_capabilities_sample_async.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_PHONENUMBERS_CAPABILITIES_ID - The capabilities id you want to get diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample.py index 24cf07ddbcad5..d66dea3258f17 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to configure phone numbers and get phone number configuration via a connection string and phone number to configure USAGE: - phone_number_configuration_sample.py + python phone_number_configuration_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_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE - The phone number you want to configure @@ -44,8 +44,7 @@ def configure_number(): # [START configure_number] pstn_config = PstnConfiguration( callback_url="https://callbackurl", - application_id="ApplicationId", - azure_pstn_target_id="AzurePstnTargetId" + application_id="ApplicationId" ) phone_number_administration_client.configure_number( pstn_configuration=pstn_config, diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample_async.py index 1f02bb744e84e..917d3992bd8cb 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample_async.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_configuration_sample_async.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to configure phone numbers and get phone number configuration via a connection string and phone number to configure USAGE: - phone_number_configuration_sample_async.py + python phone_number_configuration_sample_async.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_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE - The phone number you want to configure @@ -44,8 +44,7 @@ async def configure_number(): phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) pstn_config = PstnConfiguration( callback_url="https://callbackurl", - application_id="ApplicationId", - azure_pstn_target_id="AzurePstnTargetId" + application_id="ApplicationId" ) async with phone_number_administration_client: await phone_number_administration_client.configure_number( diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample.py index f0f74b4a724cf..1a64a3950cbba 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to list, acquire and cancel phone number orders via a connection string, search id, phone plan id and and area code USAGE: - phone_number_orders_sample.py + python phone_number_orders_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_PHONENUMBERS_RELEASE_ID - The release id you want to get info from @@ -77,17 +77,17 @@ def create_search(): phone_plan_ids=[phone_plan_id], quantity=1 ) - search_response = phone_number_administration_client.create_search( + search_response = phone_number_administration_client.begin_create_search( body=searchOptions ) # [END create_search] - print('search_response:') - print(search_response) + print('search_response status:') + print(search_response.status()) def cancel_search(): # [START cancel_search] - phone_number_administration_client.cancel_search( + phone_number_administration_client.begin_cancel_search( search_id=search_id_to_cancel ) # [START cancel_search] @@ -95,7 +95,7 @@ def cancel_search(): def purchase_search(): # [START cancel_search] - phone_number_administration_client.purchase_search( + phone_number_administration_client.begin_purchase_search( search_id=search_id_to_purchase ) # [END cancel_search] diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample_async.py index ef40428b0848a..ec5b1e851a2dc 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample_async.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_orders_sample_async.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to list, acquire and cancel phone number orders via a connection string, search id, phone plan id and and area code USAGE: - phone_number_orders_sample_async.py + python phone_number_orders_sample_async.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_PHONENUMBERS_RELEASE_ID - The release id you want to get info from @@ -83,11 +83,11 @@ async def create_search(): quantity=1 ) async with phone_number_administration_client: - search_response = await phone_number_administration_client.create_search( + search_response = await phone_number_administration_client.begin_create_search( body=searchOptions ) - print('search_response:') - print(search_response) + print('search_response status:') + print(search_response.status()) # [END create_search] @@ -95,7 +95,7 @@ async def cancel_search(): # [START cancel_search] phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) async with phone_number_administration_client: - await phone_number_administration_client.cancel_search( + await phone_number_administration_client.begin_cancel_search( search_id=search_id_to_cancel ) # [END cancel_search] @@ -105,7 +105,7 @@ async def purchase_search(): # [START purchase_search] phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) async with phone_number_administration_client: - await phone_number_administration_client.purchase_search( + await phone_number_administration_client.begin_purchase_search( search_id=search_id_to_purchase ) # [END purchase_search] diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample.py index bfa3b005dd50e..360c07f099a63 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to list phone plans via a connection string, country code, phone plan id and phone plan group id USAGE: - phone_number_plans_sample.py + python phone_number_plans_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_PHONENUMBERS_COUNTRY_CODE - The country code diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample_async.py index 6f0616fc57701..4460686c8bcea 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample_async.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_plans_sample_async.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to list phone plans via a connection string, country code, phone plan id and phone plan group id USAGE: - phone_number_plans_sample_async.py + python phone_number_plans_sample_async.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_PHONENUMBERS_COUNTRY_CODE - The country code diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample.py b/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample.py index 0177c585fe9c2..40489c488c845 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to get supported countries via a connection string USAGE: - phone_number_supported_countries_sample.py + python phone_number_supported_countries_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 """ diff --git a/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample_async.py b/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample_async.py index 692c5ede2aa83..0069bbe5ec4fc 100644 --- a/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample_async.py +++ b/sdk/communication/azure-communication-administration/samples/phone_number_supported_countries_sample_async.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to get supported countries via a connection string USAGE: - phone_number_supported_countries_sample.py + python phone_number_supported_countries_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 """ From 1038ade344d04e2f622598c75fdc9d8080a33d9d Mon Sep 17 00:00:00 2001 From: Eason Yang Date: Thu, 1 Oct 2020 17:55:13 -0700 Subject: [PATCH 4/6] add basic readme for phone number description --- .../azure-communication-administration/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sdk/communication/azure-communication-administration/README.md b/sdk/communication/azure-communication-administration/README.md index a7c2fc0932956..cfc742f4e790a 100644 --- a/sdk/communication/azure-communication-administration/README.md +++ b/sdk/communication/azure-communication-administration/README.md @@ -24,6 +24,21 @@ pip install azure-communication-administration - Create/revoke scoped user access tokens to access services such as chat, calling, sms. Tokens are issued for a valid Azure Communication identity and can be revoked at any time. +## CommunicationPhoneNumberClient +### Phone plans overview + +Phone plans come in two types; Geographic and Toll-Free. Geographic phone plans are phone plans associated with a location, whose phone numbers' area codes are associated with the area code of a geographic location. Toll-Free phone plans are phone plans not associated location. For example, in the US, toll-free numbers can come with area codes such as 800 or 888. + +All geographic phone plans within the same country are grouped into a phone plan group with a Geographic phone number type. All Toll-Free phone plans within the same country are grouped into a phone plan group. + +### Searching and Acquiring numbers + +Phone numbers search can be search through the search creation API by providing a phone plan id, an area code and quantity of phone numbers. The provided quantity of phone numbers will be reserved for ten minutes. This search of phone numbers can either be cancelled or purchased. If the search is cancelled, then the phone numbers will become available to others. If the search is purchased, then the phone numbers are acquired for the Azure resources. + +### Configuring / Assigning numbers + +Phone numbers can be assigned to a callback URL via the configure number API. As part of the configuration, you will need an acquired phone number, callback URL and application id. + # Examples The following section provides several code snippets covering some of the most common Azure Communication Services tasks, including: From e1e4a87f8046aa103bfa12aaed4a2f01486fbcaa Mon Sep 17 00:00:00 2001 From: Eason Yang Date: Thu, 1 Oct 2020 18:56:30 -0700 Subject: [PATCH 5/6] add e=code example to tnm readme --- .../README.md | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/sdk/communication/azure-communication-administration/README.md b/sdk/communication/azure-communication-administration/README.md index cfc742f4e790a..8fc8b128b4bd8 100644 --- a/sdk/communication/azure-communication-administration/README.md +++ b/sdk/communication/azure-communication-administration/README.md @@ -25,6 +25,15 @@ pip install azure-communication-administration - Create/revoke scoped user access tokens to access services such as chat, calling, sms. Tokens are issued for a valid Azure Communication identity and can be revoked at any time. ## CommunicationPhoneNumberClient +### Initializing Phone Number Client +```python +# You can find your endpoint and access token from your resource in the Azure Portal +import os +from azure.communication.administration import PhoneNumberAdministrationClient + +connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') +phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) +``` ### Phone plans overview Phone plans come in two types; Geographic and Toll-Free. Geographic phone plans are phone plans associated with a location, whose phone numbers' area codes are associated with the area code of a geographic location. Toll-Free phone plans are phone plans not associated location. For example, in the US, toll-free numbers can come with area codes such as 800 or 888. @@ -46,6 +55,135 @@ The following section provides several code snippets covering some of the most c +##Communication Phone number +### Get Countries + +```python +def list_all_supported_countries(): + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + + supported_countries = phone_number_administration_client.list_all_supported_countries() + for supported_country in supported_countries: + print(supported_country) +``` + +### Get Phone Plan Groups + +Phone plan groups come in two types, Geographic and Toll-Free. + +```python +def list_phone_plan_groups(): + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") + + phone_plan_groups_response = phone_number_administration_client.list_phone_plan_groups( + country_code=country_code + ) + for phone_plan_group in phone_plan_groups_response: + print(phone_plan_group) +``` + +### Get Phone Plans + +Unlike Toll-Free phone plans, area codes for Geographic Phone Plans are empty. Area codes are found in the Area Codes API. + +```python +def list_phone_plans(): + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") + phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_GROUP_ID', "phone-plan-group-id") + + phone_plans_response = phone_number_administration_client.list_phone_plans( + country_code=country_code, + phone_plan_group_id=phone_plan_group_id + ) + for phone_plan in phone_plans_response: + print(phone_plan) +``` + +### Get Location Options + +For Geographic phone plans, you can query the available geographic locations. The locations options are structured like the geographic hierarchy of a country. For example, the US has states and within each state are cities. + +```python +def get_phone_plan_location_options(): + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") + phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_GROUP_ID', "phone-plan-group-id") + phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID', "phone-plan-id") + + location_options_response = phone_number_administration_client.get_phone_plan_location_options( + country_code=country_code, + phone_plan_group_id=phone_plan_group_id, + phone_plan_id=phone_plan_id + ) + print(location_options_response) +``` + +### Get Area Codes + +Fetching area codes for geographic phone plans will require the the location options queries set. You must include the chain of geographic locations traversing down the location options object returned by the GetLocationOptions API. + +```python +def get_all_area_codes(): + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") + phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID_AREA_CODES', "phone-plan-id") + + all_area_codes = phone_number_administration_client.get_all_area_codes( + location_type="NotRequired", + country_code=country_code, + phone_plan_id=phone_plan_id_area_codes + ) + print(all_area_codes) +``` + +### Create Search + +```python +def create_search(): + from azure.communication.administration import CreateSearchOptions + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID', "phone-plan-id") + area_code_for_search = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_AREA_CODE_FOR_SEARCH', "area-code") + + searchOptions = CreateSearchOptions( + area_code=area_code_for_search, + description="testsearch20200014", + display_name="testsearch20200014", + phone_plan_ids=[phone_plan_id], + quantity=1 + ) + search_response = phone_number_administration_client.begin_create_search( + body=searchOptions + ) + print(search_response.status()) +``` + +### Get search by id +```python +def get_search_by_id(): + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + search_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID', "search-id") + + phone_number_search_response = phone_number_administration_client.get_search_by_id( + search_id=search_id + ) + print(phone_number_search_response) +``` + +### Purchase Search + +```python +def purchase_search(): + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + search_id_to_purchase = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_PURCHASE', "search-id") + + phone_number_administration_client.begin_purchase_search( + search_id=search_id_to_purchase + ) +``` + # Troubleshooting # Next steps From 77aef049257271bd4c1c972b35945cc16699aff3 Mon Sep 17 00:00:00 2001 From: Eason Yang Date: Thu, 1 Oct 2020 23:50:39 -0700 Subject: [PATCH 6/6] update admin setup.py with long_description_content_type --- sdk/communication/azure-communication-administration/setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/communication/azure-communication-administration/setup.py b/sdk/communication/azure-communication-administration/setup.py index 3966d3cd5ff21..3888e2e3187b4 100644 --- a/sdk/communication/azure-communication-administration/setup.py +++ b/sdk/communication/azure-communication-administration/setup.py @@ -35,6 +35,7 @@ # ensure that these are updated to reflect the package owners' information long_description=long_description, + long_description_content_type='text/markdown', url='https://github.com/Azure/azure-sdk-for-python', author='Microsoft Corporation', author_email='azuresdkengsysadmins@microsoft.com',