async def cancel_reservation(): # [START cancel_reservation] phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( connection_str) async with phone_number_administration_client: await phone_number_administration_client.cancel_reservation( reservation_id=reservation_id_to_cancel)
async def begin_purchase_reservation(): # [START begin_purchase_reservation] phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( connection_str) async with phone_number_administration_client: await phone_number_administration_client.begin_purchase_reservation( reservation_id=reservation_id_to_purchase)
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 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)
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)
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)
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)
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)
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)
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()
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)
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)
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 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)
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)
async def begin_reserve_phone_numbers(): # [START begin_reserve_phone_numbers] phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( connection_str) reservationOptions = CreateSearchOptions( area_code=area_code_for_reservation, description="testreservation20200014", display_name="testreservation20200014", phone_plan_ids=[phone_plan_id], quantity=1) async with phone_number_administration_client: reserve_phone_numbers_response = await phone_number_administration_client.begin_reserve_phone_numbers( options=reservationOptions) print('reserve phone numbers status:') print(reserve_phone_numbers_response.status())
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_RESERVATION_ID - The reservation id you want to get info from 4) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_AREA_CODE_FOR_RESERVATION - The area code to create reservation 5) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID - The phone plan id 6) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RESERVATION_ID_TO_PURCHASE - The reservation id you want to purchase 7) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RESERVATION_ID_TO_CANCEL - The reservation id you want to cancel """ import os import asyncio from azure.communication.administration.aio import PhoneNumberAdministrationClient from azure.communication.administration import CreateSearchOptions 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") reservation_id = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RESERVATION_ID', "reservation-id") area_code_for_reservation = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_AREA_CODE_FOR_RESERVATION', "area-code") phone_plan_id = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID', "phone-plan-id") reservation_id_to_purchase = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RESERVATION_ID_TO_PURCHASE', "reservation-id") reservation_id_to_cancel = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RESERVATION_ID_TO_CANCEL',
def setUp(self): super(PhoneNumberAdministrationClientTestAsync, self).setUp() self.recording_processors.extend([ BodyReplacerProcessor(keys=[ "id", "token", "capabilitiesUpdateId", "phoneNumber", "phonePlanIds", "phoneNumberCapabilitiesUpdates", "releaseId", "phoneNumberReleaseStatusDetails", "searchId", "phoneNumbers", "entities", "phonePlanGroups", "phonePlans", "phoneNumberCapabilitiesUpdate" ]), PhoneNumberUriReplacer(), ResponseReplacerProcessor(keys=[self._resource_name]) ]) self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( self.connection_str) if self.is_live: self.country_code = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE') self.locale = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_LOCALE') self.phone_plan_group_id = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_GROUP_ID') self.phone_plan_id = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID') self.phone_plan_id_area_codes = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID_AREA_CODES' ) self.area_code_for_reservation = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_AREA_CODE_FOR_RESERVATION' ) self.reservation_id = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RESERVATION_ID') self.reservation_id_to_purchase = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RESERVATION_ID_TO_PURCHASE' ) self.reservation_id_to_cancel = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RESERVATION_ID_TO_CANCEL' ) self.phonenumber_to_configure = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE' ) self.phonenumber_to_get_config = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_GET_CONFIG' ) self.phonenumber_to_unconfigure = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_UNCONFIGURE' ) self.phonenumber_for_capabilities = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_FOR_CAPABILITIES' ) self.phonenumber_to_release = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_RELEASE' ) self.capabilities_id = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_CAPABILITIES_ID') self.release_id = os.getenv( 'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RELEASE_ID') self.scrubber.register_name_pair(self.phone_plan_group_id, "phone_plan_group_id") self.scrubber.register_name_pair(self.phone_plan_id, "phone_plan_id") self.scrubber.register_name_pair(self.phone_plan_id_area_codes, "phone_plan_id_area_codes") self.scrubber.register_name_pair(self.area_code_for_reservation, "area_code_for_reservation") self.scrubber.register_name_pair(self.reservation_id, "reservation_id") self.scrubber.register_name_pair(self.reservation_id_to_purchase, "reservation_id_to_purchase") self.scrubber.register_name_pair(self.reservation_id_to_cancel, "reservation_id_to_cancel") self.scrubber.register_name_pair(self.phonenumber_to_configure, "phonenumber_to_configure") self.scrubber.register_name_pair(self.phonenumber_to_get_config, "phonenumber_to_get_config") self.scrubber.register_name_pair(self.phonenumber_to_unconfigure, "phonenumber_to_unconfigure") self.scrubber.register_name_pair(self.phonenumber_for_capabilities, "phonenumber_for_capabilities") self.scrubber.register_name_pair(self.phonenumber_to_release, "phonenumber_to_release") self.scrubber.register_name_pair(self.capabilities_id, "capabilities_id") self.scrubber.register_name_pair(self.release_id, "release_id") else: self.connection_str = "endpoint=https://sanitized.communication.azure.com/;accesskey=fake===" self.country_code = "US" self.locale = "en-us" self.phone_plan_group_id = "phone_plan_group_id" self.phone_plan_id = "phone_plan_id" self.phone_plan_id_area_codes = "phone_plan_id_area_codes" self.area_code_for_reservation = "area_code_for_reservation" self.reservation_id = "reservation_id" self.reservation_id_to_purchase = "reservation_id_to_purchase" self.reservation_id_to_cancel = "reservation_id_to_cancel" self.phonenumber_to_configure = "phonenumber_to_configure" self.phonenumber_to_get_config = "phonenumber_to_get_config" self.phonenumber_to_unconfigure = "phonenumber_to_unconfigure" self.phonenumber_for_capabilities = "phonenumber_for_capabilities" self.phonenumber_to_release = "phonenumber_to_release" self.capabilities_id = "capabilities_id" self.release_id = "release_id"