Skip to content

Commit 016e34c

Browse files
committed
get list_calls working
1 parent 5819ed3 commit 016e34c

File tree

17 files changed

+270
-78
lines changed

17 files changed

+270
-78
lines changed

users/src/vonage_users/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from .common import User
2-
from .requests import ListUsersRequest
2+
from .requests import ListUsersFilter
33
from .responses import UserSummary
44
from .users import Users
55

66
__all__ = [
77
'Users',
88
'User',
9-
'ListUsersRequest',
9+
'ListUsersFilter',
1010
'UserSummary',
1111
]

users/src/vonage_users/common.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
from typing import List, Optional
22

33
from pydantic import BaseModel, Field, model_validator
4+
from vonage_utils.models import Link
45
from vonage_utils.types import PhoneNumber
56

67

7-
class Link(BaseModel):
8-
href: str
9-
10-
118
class ResourceLink(BaseModel):
129
self: Link
1310

users/src/vonage_users/requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pydantic import BaseModel, Field
44

55

6-
class ListUsersRequest(BaseModel):
6+
class ListUsersFilter(BaseModel):
77
"""Request object for listing users."""
88

99
page_size: Optional[int] = Field(100, ge=1, le=100)

users/src/vonage_users/responses.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class UserSummary(BaseModel):
1919
link: Optional[str] = None
2020

2121
@model_validator(mode='after')
22-
@classmethod
2322
def get_link(self):
2423
if self.links is not None:
2524
self.link = self.links.self.href

users/src/vonage_users/users.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from vonage_http_client.http_client import HttpClient
66

77
from .common import User
8-
from .requests import ListUsersRequest
8+
from .requests import ListUsersFilter
99
from .responses import ListUsersResponse, UserSummary
1010

1111

@@ -22,23 +22,27 @@ def __init__(self, http_client: HttpClient) -> None:
2222

2323
@validate_call
2424
def list_users(
25-
self, params: ListUsersRequest = ListUsersRequest()
26-
) -> Tuple[List[UserSummary], str]:
25+
self, filter: ListUsersFilter = ListUsersFilter()
26+
) -> Tuple[List[UserSummary], Optional[str]]:
2727
"""List all users.
2828
2929
Retrieves a list of all users. Gets 100 users by default.
30-
If you want to see more information about a specific user, you can use the `Users.get_user` method.
30+
If you want to see more information about a specific user, you can use the
31+
`Users.get_user` method.
3132
3233
Args:
33-
params (ListUsersRequest, optional): An instance of the ListUsersRequest class that allows you to specify additional parameters for the user listing.
34+
params (ListUsersFilter, optional): An instance of the `ListUsersFilter`
35+
class that allows you to specify additional parameters for the user listing.
3436
3537
Returns:
36-
Tuple[List[UserSummary], str]: A tuple containing a list of UserSummary objects representing the users and a string representing the next cursor for pagination.
38+
Tuple[List[UserSummary], Optional[str]]: A tuple containing a list of `UserSummary`
39+
objects representing the users and a string representing the next cursor for
40+
pagination, if there are more results than the specified `page_size`.
3741
"""
3842
response = self._http_client.get(
3943
self._http_client.api_host,
4044
'/v1/users',
41-
params.model_dump(exclude_none=True),
45+
filter.model_dump(exclude_none=True),
4246
self._auth_type,
4347
)
4448

users/tests/test_users.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from vonage_http_client.http_client import HttpClient
66
from vonage_users import Users
77
from vonage_users.common import *
8-
from vonage_users.requests import ListUsersRequest
8+
from vonage_users.requests import ListUsersFilter
99

1010
from testutils import build_response, get_mock_jwt_auth
1111

@@ -21,7 +21,7 @@ def test_create_list_users_request():
2121
'cursor': '7EjDNQrAcipmOnc0HCzpQRkhBULzY44ljGUX4lXKyUIVfiZay5pv9wg=',
2222
'name': 'my_user',
2323
}
24-
list_users_request = ListUsersRequest(**params)
24+
list_users_request = ListUsersFilter(**params)
2525

2626
assert list_users_request.model_dump() == params
2727

@@ -52,7 +52,7 @@ def test_list_users_options():
5252
path, 'GET', 'https://api.nexmo.com/v1/users', 'list_users_options.json'
5353
)
5454

55-
params = ListUsersRequest(
55+
params = ListUsersFilter(
5656
page_size=2,
5757
order='asc',
5858
cursor='zAmuSchIBsUF1QaaohGdaf32NgHOkP130XeQrZkoOPEuGPnIxFb0Xj3iqCfOzxSSq9Es/S/2h+HYumKt3HS0V9ewjis+j74oMcsvYBLN1PwFEupI6ENEWHYC7lk=',

voice/src/vonage_voice/models/common.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
11
from typing import Literal, Optional
22

33
from pydantic import BaseModel, Field
4+
from vonage_utils.types import Dtmf, PhoneNumber, SipUri
5+
from vonage_voice.models.enums import Channel
6+
7+
8+
class Phone(BaseModel):
9+
number: PhoneNumber
10+
type: Channel = Channel.PHONE
11+
12+
13+
class ToPhone(Phone):
14+
dtmf_answer: Optional[Dtmf] = Field(None, serialization_alias='dtmfAnswer')
15+
16+
17+
class Sip(BaseModel):
18+
uri: SipUri
19+
type: Channel = Channel.SIP
20+
21+
22+
class Websocket(BaseModel):
23+
uri: str = Field(..., min_length=1, max_length=50)
24+
content_type: Literal['audio/l16;rate=8000', 'audio/l16;rate=16000'] = Field(
25+
'audio/l16;rate=16000', serialization_alias='content-type'
26+
)
27+
type: Channel = Channel.WEBSOCKET
28+
headers: Optional[dict] = None
29+
30+
31+
class Vbc(BaseModel):
32+
extension: str
33+
type: Channel = Channel.VBC
434

535

636
class AdvancedMachineDetection(BaseModel):

voice/src/vonage_voice/models/ncco.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Annotated, List, Optional, Union
1+
from typing import List, Optional, Union
22

33
from pydantic import BaseModel, Field, model_validator
44
from typing_extensions import Literal
Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,11 @@
11
from typing import List, Literal, Optional, Union
22

33
from pydantic import BaseModel, Field, model_validator
4-
from vonage_utils.types import Dtmf, PhoneNumber, SipUri
54

65
from ..errors import VoiceError
7-
from .common import AdvancedMachineDetection
8-
from .enums import CallStatus, Channel
9-
from .ncco import Record, Conversation, Connect, Input, Talk, Stream, Notify
10-
11-
12-
class Phone(BaseModel):
13-
number: PhoneNumber
14-
type: Channel = Channel.PHONE
15-
16-
17-
class ToPhone(Phone):
18-
dtmf_answer: Optional[Dtmf] = Field(None, serialization_alias='dtmfAnswer')
19-
20-
21-
class Sip(BaseModel):
22-
uri: SipUri
23-
type: Channel = Channel.SIP
24-
25-
26-
class Websocket(BaseModel):
27-
uri: str = Field(..., min_length=1, max_length=50)
28-
content_type: Literal['audio/l16;rate=8000', 'audio/l16;rate=16000'] = Field(
29-
'audio/l16;rate=16000', serialization_alias='content-type'
30-
)
31-
type: Channel = Channel.WEBSOCKET
32-
headers: Optional[dict] = None
33-
34-
35-
class Vbc(BaseModel):
36-
extension: str
37-
type: Channel = Channel.VBC
6+
from .common import AdvancedMachineDetection, Phone, Sip, ToPhone, Vbc, Websocket
7+
from .enums import CallStatus
8+
from .ncco import Connect, Conversation, Input, Notify, Record, Stream, Talk
389

3910

4011
class CreateCallRequest(BaseModel):
@@ -73,7 +44,7 @@ class ListCallsFilter(BaseModel):
7344
status: Optional[CallStatus] = None
7445
date_start: Optional[str] = None
7546
date_end: Optional[str] = None
76-
page_size: Optional[int] = Field(None, ge=1, le=100)
47+
page_size: Optional[int] = Field(100, ge=1, le=100)
7748
record_index: Optional[int] = None
7849
order: Optional[Literal['asc', 'desc']] = None
7950
conversation_uuid: Optional[str] = None

voice/src/vonage_voice/models/responses.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
from typing import List, Optional
1+
from typing import List, Optional, Union
2+
23
from pydantic import BaseModel, Field, model_validator
4+
from vonage_utils.models import Link
5+
6+
from .common import Phone, Sip, ToPhone, Vbc, Websocket
37

48

59
class CreateCallResponse(BaseModel):
@@ -14,27 +18,19 @@ class CallStatus(BaseModel):
1418
uuid: str
1519

1620

17-
class Link(BaseModel):
18-
href: str
19-
20-
2121
class Links(BaseModel):
2222
self: Link
2323
first: Optional[Link] = None
24-
next: Optional[Link] = None
24+
last: Optional[Link] = None
2525
prev: Optional[Link] = None
26-
27-
28-
class Endpoint(BaseModel):
29-
type: str
30-
number: str
26+
next: Optional[Link] = None
3127

3228

3329
class CallInfo(BaseModel):
3430
uuid: str
3531
conversation_uuid: str
36-
to: Endpoint
37-
from_: Endpoint = Field(..., alias='from')
32+
to: ToPhone
33+
from_: Union[Phone, Sip, Websocket, Vbc] = Field(..., validation_alias='from')
3834
status: str
3935
direction: str
4036
rate: Optional[str] = None
@@ -47,7 +43,6 @@ class CallInfo(BaseModel):
4743
link: Optional[str] = None
4844

4945
@model_validator(mode='after')
50-
@classmethod
5146
def get_link(self):
5247
self.link = self.links.self.href
5348
return self

0 commit comments

Comments
 (0)