Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason Yang committed Oct 1, 2020
1 parent 347c133 commit 257851b
Show file tree
Hide file tree
Showing 12 changed files with 554 additions and 474 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
Loading

0 comments on commit 257851b

Please sign in to comment.