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 d3760eda1dac..143f359ae6ae 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 f9e5e21d40b7..f868c52f1185 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 5c3f81880ff4..162c3d8941f9 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 17a0c9447c0b..5cca02ad12c5 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 29359d16a7f4..24cf07ddbcad 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 f15e3b9bfe6c..1f02bb744e84 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 2d01e440750d..f0f74b4a724c 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 adb23ac7714a..ef40428b0848 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 5fcfd9e87e60..bfa3b005dd50 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 1c96b4c95025..6f0616fc5770 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 71e2809f1fef..0177c585fe9c 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 cac5f7d01713..692c5ede2aa8 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()