Skip to content

Commit 62f8959

Browse files
authored
Refactor begin_reserve_phone_numbers() by flattening CreateSearchOptions into args (Azure#15378)
* refactor the params of begin_reserve_phone_numbers * update test and samples * rename reserve_phone_numbers_response to create_reservation_poller * refactor async method begin_reserve_phone_numbers * update samples for reserve_phone_numbers_poller * correct missed async calls * refresh tests and the generated test yaml files * refresh CHANGELOG
1 parent dde0272 commit 62f8959

File tree

42 files changed

+721
-731
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+721
-731
lines changed

sdk/communication/azure-communication-administration/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## 1.0.0b4 (Unreleased)
44

5+
##### `PhoneNumberAdministrationClient`
6+
- `begin_reserve_phone_numbers` now takes `display_name`, `description`, `phone_plan_ids`,
7+
`area_code`, `quantity`, `location_options`, or `continuation_token` keywords as input.
8+
Caller must provide one of the following:
9+
(1) all of keywords `display_name`, `description`, `phone_plan_ids`, `area_code`, `quantity` if all the phone plans
10+
to reserve are toll-free plans.
11+
(2) all of keywords `display_name`, `description`, `phone_plan_ids`, `area_code`, `quantity`, `location_options`
12+
if at least one phone plan to reserve is not toll-free plans.
13+
(3) only keyword `continuation_token` to restart a poller from a saved state.
514

615
## 1.0.0b3 (2020-11-16)
716

sdk/communication/azure-communication-administration/azure/communication/administration/_phone_number_administration_client.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Copyright (c) Microsoft Corporation.
55
# Licensed under the MIT License.
66
# ------------------------------------
7-
from azure.communication.administration._phonenumber._generated.models import ReleaseStatus
7+
from azure.communication.administration._phonenumber._generated.models import ReleaseStatus, CreateSearchOptions
88
from azure.core.tracing.decorator import distributed_trace
99
from azure.core.paging import ItemPaged
1010
from azure.core.polling import LROPoller
@@ -444,10 +444,21 @@ def begin_reserve_phone_numbers(
444444
):
445445
# type: (...) -> LROPoller[PhoneNumberReservation]
446446
"""Begins creating a phone number search to reserve phone numbers.
447-
Caller must provide either options, or continuation_token keywords to use the method.
448-
If both options and continuation_token are specified, only continuation_token will be used to
449-
restart a poller from a saved state, and keyword options will be ignored.
450-
:keyword azure.communication.administration.CreateSearchOptions options: reservation options.
447+
Caller must provide one of the following:
448+
(1) all of keywords display_name, description, phone_plan_ids, area_code, quantity if all the phone plans
449+
to reserve are toll-free plans.
450+
(2) all of keywords display_name, description, phone_plan_ids, area_code, quantity, location_options
451+
if at least one phone plan to reserve is not toll-free plans.
452+
(3) only keyword continuation_token to restart a poller from a saved state.
453+
If both continuation_token and other keywords are specified, only continuation_token will be used to
454+
restart a poller from a saved state, and other keywords will be ignored.
455+
:keyword str display_name: display name of the search.
456+
:keyword str description: description of the search.
457+
:keyword list[str] phone_plan_ids: the plan subtype ids from which to create the search.
458+
:keyword str area_code: the area code from which to create the search.
459+
:keyword int quantity: the quantity of phone numbers to request.
460+
:keyword list[~azure.communication.administration.models.LocationOptionsDetails] location_options:
461+
the location options of the search.
451462
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
452463
:rtype: ~azure.core.polling.LROPoller[~azure.communication.administration.PhoneNumberReservation]
453464
"""
@@ -470,10 +481,23 @@ def begin_reserve_phone_numbers(
470481
client=self._phone_number_administration_client.phone_number_administration
471482
)
472483

473-
if "options" not in kwargs:
474-
raise ValueError("Either kwarg 'options' or 'continuation_token' needs to be specified")
484+
required_kwargs = ['display_name', 'description', 'phone_plan_ids', 'area_code', 'quantity']
485+
for required_kwarg in required_kwargs:
486+
if required_kwarg not in kwargs:
487+
raise ValueError("Either kwarg 'continuation_token', or a set of kwargs " +
488+
"'display_name', 'description', 'phone_plan_ids', "
489+
"'area_code', 'quantity' needs to be specified")
490+
491+
reservation_options = CreateSearchOptions(
492+
display_name=kwargs.pop('display_name'),
493+
description=kwargs.pop('description'),
494+
phone_plan_ids=kwargs.pop('phone_plan_ids'),
495+
area_code=kwargs.pop('area_code'),
496+
quantity=kwargs.pop('quantity')
497+
)
475498

476-
reservation_options = kwargs.pop('options') # type: str
499+
if 'location_options' in kwargs:
500+
reservation_options.location_options = kwargs.pop('location_options')
477501

478502
create_reservation_response = self._phone_number_administration_client.\
479503
phone_number_administration.create_search(

sdk/communication/azure-communication-administration/azure/communication/administration/aio/_phone_number_administration_client_async.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# ------------------------------------
77
from typing import Dict, List
88

9-
from azure.communication.administration._phonenumber._generated.models import ReleaseStatus
9+
from azure.communication.administration._phonenumber._generated.models import ReleaseStatus, CreateSearchOptions
1010
from azure.core.async_paging import AsyncItemPaged
1111
from azure.core.tracing.decorator import distributed_trace
1212
from azure.core.tracing.decorator_async import distributed_trace_async
@@ -454,10 +454,21 @@ async def begin_reserve_phone_numbers(
454454
):
455455
# type: (...) -> AsyncLROPoller[PhoneNumberReservation]
456456
"""Begins creating a phone number search to reserve phone numbers.
457-
Caller must provide either options, or continuation_token keywords to use the method.
458-
If both options and continuation_token are specified, only continuation_token will be used to
459-
restart a poller from a saved state, and keyword options will be ignored.
460-
:keyword azure.communication.administration.CreateSearchOptions options: reservation options.
457+
Caller must provide one of the following:
458+
(1) all of keywords display_name, description, phone_plan_ids, area_code, quantity if all the phone plans
459+
to reserve are toll-free plans.
460+
(2) all of keywords display_name, description, phone_plan_ids, area_code, quantity, location_options
461+
if at least one phone plan to reserve is not toll-free plans.
462+
(3) only keyword continuation_token to restart a poller from a saved state.
463+
If both continuation_token and other keywords are specified, only continuation_token will be used to
464+
restart a poller from a saved state, and other keywords will be ignored.
465+
:keyword str display_name: display name of the search.
466+
:keyword str description: description of the search.
467+
:keyword list[str] phone_plan_ids: the plan subtype ids from which to create the search.
468+
:keyword str area_code: the area code from which to create the search.
469+
:keyword int quantity: the quantity of phone numbers to request.
470+
:keyword list[~azure.communication.administration.models.LocationOptionsDetails] location_options:
471+
the location options of the search.
461472
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
462473
:rtype: ~azure.core.polling.AsyncLROPoller[~azure.communication.administration.PhoneNumberReservation]
463474
"""
@@ -480,18 +491,31 @@ async def begin_reserve_phone_numbers(
480491
client=self._phone_number_administration_client.phone_number_administration
481492
)
482493

483-
if "options" not in kwargs:
484-
raise ValueError("Either kwarg 'options' or 'continuation_token' needs to be specified")
494+
required_kwargs = ['display_name', 'description', 'phone_plan_ids', 'area_code', 'quantity']
495+
for required_kwarg in required_kwargs:
496+
if required_kwarg not in kwargs:
497+
raise ValueError("Either kwarg 'continuation_token', or a set of kwargs " +
498+
"'display_name', 'description', 'phone_plan_ids', "
499+
"'area_code', 'quantity' needs to be specified")
500+
501+
reservation_options = CreateSearchOptions(
502+
display_name=kwargs.pop('display_name'),
503+
description=kwargs.pop('description'),
504+
phone_plan_ids=kwargs.pop('phone_plan_ids'),
505+
area_code=kwargs.pop('area_code'),
506+
quantity=kwargs.pop('quantity')
507+
)
485508

486-
reservation_options = kwargs.pop('options') # type: str
509+
if 'location_options' in kwargs:
510+
reservation_options.location_options = kwargs.pop('location_options')
487511

488-
create_search_response = await self._phone_number_administration_client.\
512+
create_reservation_response = await self._phone_number_administration_client.\
489513
phone_number_administration.create_search(
490514
body=reservation_options,
491515
**kwargs
492-
)
516+
)
493517
initial_state = await self._phone_number_administration_client.phone_number_administration.get_search_by_id(
494-
search_id=create_search_response.search_id
518+
search_id=create_reservation_response.search_id
495519
)
496520
return AsyncLROPoller(client=self._phone_number_administration_client.phone_number_administration,
497521
initial_response=initial_state,

sdk/communication/azure-communication-administration/samples/phone_number_orders_sample.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,16 @@ def get_reservation_by_id():
7373

7474
def begin_reserve_phone_numbers():
7575
# [START begin_reserve_phone_numbers]
76-
reservationOptions = CreateSearchOptions(
76+
reserve_phone_numbers_poller = phone_number_administration_client.begin_reserve_phone_numbers(
7777
area_code=area_code_for_reservation,
7878
description="testreservation20200014",
7979
display_name="testreservation20200014",
8080
phone_plan_ids=[phone_plan_id],
8181
quantity=1
8282
)
83-
reserve_phone_numbers_response = phone_number_administration_client.begin_reserve_phone_numbers(
84-
options=reservationOptions
85-
)
8683
# [END begin_reserve_phone_numbers]
8784
print('reserve phone numbers status:')
88-
print(reserve_phone_numbers_response.status())
85+
print(reserve_phone_numbers_poller.status())
8986

9087

9188
def cancel_reservation():

sdk/communication/azure-communication-administration/samples/phone_number_orders_sample_async.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ async def begin_reserve_phone_numbers():
8787
quantity=1
8888
)
8989
async with phone_number_administration_client:
90-
reserve_phone_numbers_response = await phone_number_administration_client.begin_reserve_phone_numbers(
91-
options=reservationOptions
90+
reserve_phone_numbers_poller = await phone_number_administration_client.begin_reserve_phone_numbers(
91+
area_code=area_code_for_reservation,
92+
description="testreservation20200014",
93+
display_name="testreservation20200014",
94+
phone_plan_ids=[phone_plan_id],
95+
quantity=1
9296
)
9397
print('reserve phone numbers status:')
94-
print(reserve_phone_numbers_response.status())
98+
print(reserve_phone_numbers_poller.status())
9599
# [END begin_reserve_phone_numbers]
96100

97101

sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client.test_cancel_reservation.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interactions:
1111
Content-Length:
1212
- '0'
1313
Date:
14-
- Tue, 27 Oct 2020 17:26:49 GMT
14+
- Mon, 23 Nov 2020 22:11:17 GMT
1515
User-Agent:
1616
- azsdk-python-communication-administration/1.0.0b2 Python/3.6.9 (Linux-5.4.0-48-generic-x86_64-with-Ubuntu-18.04-bionic)
1717
x-ms-return-client-request-id:
@@ -25,11 +25,11 @@ interactions:
2525
content-length:
2626
- '0'
2727
date:
28-
- Tue, 27 Oct 2020 17:26:50 GMT
28+
- Mon, 23 Nov 2020 22:11:17 GMT
2929
ms-cv:
30-
- QytXiS0WYUWt+Aklz2RkDQ.0
30+
- mbCpJZCKiUK4caapFCbzQg.0
3131
x-processing-time:
32-
- 472ms
32+
- 258ms
3333
status:
3434
code: 202
3535
message: Accepted

sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client.test_configure_number.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
interactions:
22
- request:
33
body: 'b''{"pstnConfiguration": {"callbackUrl": "https://callbackurl", "applicationId":
4-
"ApplicationId"}, "phoneNumber": "+1area_code_for_reservation7840394"}'''
4+
"ApplicationId"}, "phoneNumber": "+1area_code_for_reservation4501240"}'''
55
headers:
66
Accept:
77
- '*/*'
@@ -14,7 +14,7 @@ interactions:
1414
Content-Type:
1515
- application/json
1616
Date:
17-
- Tue, 27 Oct 2020 17:26:50 GMT
17+
- Mon, 23 Nov 2020 22:11:17 GMT
1818
User-Agent:
1919
- azsdk-python-communication-administration/1.0.0b2 Python/3.6.9 (Linux-5.4.0-48-generic-x86_64-with-Ubuntu-18.04-bionic)
2020
x-ms-return-client-request-id:
@@ -28,11 +28,11 @@ interactions:
2828
content-length:
2929
- '0'
3030
date:
31-
- Tue, 27 Oct 2020 17:26:50 GMT
31+
- Mon, 23 Nov 2020 22:11:18 GMT
3232
ms-cv:
33-
- Bv+CA5160EOmb87qa0O06Q.0
33+
- G9imTJyYkkSUmuTD6LmwNg.0
3434
x-processing-time:
35-
- 552ms
35+
- 886ms
3636
status:
3737
code: 200
3838
message: OK

0 commit comments

Comments
 (0)