Skip to content

Commit 7e1186a

Browse files
committed
add other applications endpoints
1 parent ec0d9f2 commit 7e1186a

File tree

9 files changed

+207
-86
lines changed

9 files changed

+207
-86
lines changed

application/README.md

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,24 @@ It includes methods for managing applications.
88

99
It is recommended to use this as part of the main `vonage` package. The examples below assume you've created an instance of the `vonage.Vonage` class called `vonage_client`.
1010

11-
--------------
12-
--------------
13-
--------------
14-
--------------
15-
--------------
16-
--------------
17-
--------------
18-
--------------
19-
--------------
20-
--------------
21-
--------------
22-
--------------
23-
--------------
24-
--------------
25-
--------------
26-
27-
### List Users
28-
29-
With no custom options specified, this method will get the last 100 users. It returns a tuple consisting of a list of `UserSummary` objects and a string describing the cursor to the next page of results.
11+
### List Applications
12+
13+
With no custom options specified, this method will get the first 100 applications. It returns a tuple consisting of a list of `ApplicationData` objects and an int showing the page number of the next page of results.
3014

3115
```python
32-
from vonage_users import ListUsersRequest
16+
from vonage_application import ListApplicationsFilter, ApplicationData
3317

34-
users, _ = vonage_client.users.list_users()
18+
applications, next_page = vonage_client.application.list_applications()
3519

3620
# With options
37-
params = ListUsersRequest(
38-
page_size=10,
39-
cursor=my_cursor,
40-
order='desc',
41-
)
42-
users, next_cursor = vonage_client.users.list_users(params)
21+
options = ListApplicationsFilter(page_size=3, page=2)
22+
applications, next_page = vonage_client.applications.list_applications(options)
4323
```
4424

25+
26+
--------
27+
28+
4529
### Create a New User
4630

4731
```python
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
1+
from . import errors
12
from .application import Application
3+
from .common import (
4+
ApplicationUrl,
5+
Capabilities,
6+
Keys,
7+
Messages,
8+
MessagesWebhooks,
9+
Privacy,
10+
Rtc,
11+
RtcWebhooks,
12+
Vbc,
13+
Verify,
14+
VerifyWebhooks,
15+
Voice,
16+
VoiceUrl,
17+
VoiceWebhooks,
18+
)
19+
from .enums import Region
20+
from .requests import ApplicationConfig, ListApplicationsFilter
21+
from .responses import ApplicationData, ListApplicationsResponse
222

323
__all__ = [
424
'Application',
25+
'ApplicationConfig',
26+
'ApplicationData',
27+
'ApplicationUrl',
28+
'Capabilities',
29+
'Keys',
30+
'ListApplicationsFilter',
31+
'ListApplicationsResponse',
32+
'Messages',
33+
'MessagesWebhooks',
34+
'Privacy',
35+
'Region',
36+
'Rtc',
37+
'RtcWebhooks',
38+
'Vbc',
39+
'Verify',
40+
'VerifyWebhooks',
41+
'Voice',
42+
'VoiceUrl',
43+
'VoiceWebhooks',
44+
'errors',
545
]

application/src/vonage_application/application.py

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pydantic import validate_call
44
from vonage_http_client.http_client import HttpClient
55

6-
from .requests import ApplicationOptions, ListApplicationsFilter
6+
from .requests import ApplicationConfig, ListApplicationsFilter
77
from .responses import ApplicationData, ListApplicationsResponse
88

99

@@ -56,12 +56,13 @@ def list_applications(
5656

5757
@validate_call
5858
def create_application(
59-
self, params: Optional[ApplicationOptions] = None
59+
self, params: Optional[ApplicationConfig] = None
6060
) -> ApplicationData:
6161
"""Create a new application.
6262
6363
Args:
64-
params (Optional[ApplicationOptions]): The application options.
64+
params (Optional[ApplicationConfig]): Parameters describing the
65+
application options to set.
6566
6667
Returns:
6768
ApplicationData: The created application object.
@@ -85,39 +86,40 @@ def get_application(self, id: str) -> ApplicationData:
8586
ApplicationData: The created application object.
8687
"""
8788
response = self._http_client.get(
88-
self._http_client.api_host, f'/v1/users/{id}', None, self._auth_type
89+
self._http_client.api_host, f'/v2/applications/{id}', None, self._auth_type
8990
)
9091
return ApplicationData(**response)
9192

92-
# @validate_call
93-
# def update_application(self, id: str, params: User) -> User:
94-
# """Update a user.
95-
96-
# Args:
97-
# id (str): The ID of the user to update.
98-
# params (User): The updated user object.
99-
100-
# Returns:
101-
# User: The updated user object.
102-
# """
103-
# response = self._http_client.patch(
104-
# self._http_client.api_host,
105-
# f'/v1/users/{id}',
106-
# params.model_dump(exclude_none=True),
107-
# self._auth_type,
108-
# )
109-
# return User(**response)
110-
111-
# @validate_call
112-
# def delete_application(self, id: str) -> None:
113-
# """Delete an application.
114-
115-
# Args:
116-
# id (str): The ID of the application to delete.
117-
118-
# Returns:
119-
# None
120-
# """
121-
# self._http_client.delete(
122-
# self._http_client.api_host, f'/v2/applications/{id}', None, self._auth_type
123-
# )
93+
@validate_call
94+
def update_application(self, id: str, params: ApplicationConfig) -> ApplicationData:
95+
"""Update an application.
96+
97+
Args:
98+
id (str): The ID of the application to update.
99+
params (ApplicationConfig): Parameters describing the
100+
application options to update.
101+
102+
Returns:
103+
ApplicationData: The updated application object.
104+
"""
105+
response = self._http_client.put(
106+
self._http_client.api_host,
107+
f'/v2/applications/{id}',
108+
params.model_dump(exclude_none=True),
109+
self._auth_type,
110+
)
111+
return ApplicationData(**response)
112+
113+
@validate_call
114+
def delete_application(self, id: str) -> None:
115+
"""Delete an application.
116+
117+
Args:
118+
id (str): The ID of the application to delete.
119+
120+
Returns:
121+
None
122+
"""
123+
self._http_client.delete(
124+
self._http_client.api_host, f'/v2/applications/{id}', None, self._auth_type
125+
)

application/src/vonage_application/common.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Literal, Optional
22

3-
from pydantic import BaseModel, Field, field_validator
3+
from pydantic import BaseModel, ConfigDict, Field, field_validator
44

55
from .enums import Region
66
from .errors import ApplicationError
@@ -103,10 +103,17 @@ class Capabilities(BaseModel):
103103
verify: Optional[Verify] = None
104104

105105

106+
class Keys(BaseModel):
107+
model_config = ConfigDict(extra='allow')
108+
109+
public_key: Optional[str] = None
110+
111+
106112
class ApplicationBase(BaseModel):
107113
"""Base application object used in requests and responses when communicating with the Vonage
108114
Application API."""
109115

110116
name: str
111117
capabilities: Optional[Capabilities] = None
112118
privacy: Optional[Privacy] = None
119+
keys: Optional[Keys] = None

application/src/vonage_application/requests.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,5 @@ class ListApplicationsFilter(BaseModel):
1212
page: int = None
1313

1414

15-
class RequestKeys(BaseModel):
16-
public_key: str
17-
18-
19-
class ApplicationOptions(ApplicationBase):
20-
keys: Optional[RequestKeys] = None
15+
class ApplicationConfig(ApplicationBase):
16+
pass

application/src/vonage_application/responses.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@
33
from pydantic import BaseModel, Field, model_validator
44
from vonage_utils.models import HalLinks, ResourceLink
55

6-
from .common import ApplicationBase
7-
8-
9-
class ResponseKeys(BaseModel):
10-
public_key: Optional[str] = None
11-
private_key: Optional[str] = None
6+
from .common import ApplicationBase, Keys
127

138

149
class ApplicationData(ApplicationBase):
1510
id: str
16-
keys: Optional[ResponseKeys] = None
11+
keys: Optional[Keys] = None
1712
links: Optional[ResourceLink] = Field(None, validation_alias='_links', exclude=True)
1813
link: Optional[str] = None
1914

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"id": "1b1b1b1b-1b1b-1b1b-1b1b-1b1b1b1b1b1b",
3+
"name": "My Server Demo",
4+
"keys": {
5+
"public_key": "-----BEGIN PUBLIC KEY-----\npublic_key_info_goes_here\n-----END PUBLIC KEY-----\n"
6+
},
7+
"privacy": {
8+
"improve_ai": false
9+
},
10+
"capabilities": {
11+
"voice": {
12+
"webhooks": {
13+
"event_url": {
14+
"address": "http://example.ngrok.app/webhooks/events",
15+
"http_method": "POST",
16+
"socket_timeout": 10000,
17+
"connect_timeout": 1000
18+
},
19+
"answer_url": {
20+
"address": "http://example.ngrok.app/webhooks/answer",
21+
"http_method": "GET",
22+
"socket_timeout": 5000,
23+
"connect_timeout": 1000
24+
}
25+
},
26+
"signed_callbacks": true,
27+
"conversations_ttl": 48,
28+
"leg_persistence_time": 7
29+
}
30+
},
31+
"_links": {
32+
"self": {
33+
"href": "/v2/applications/1b1b1b1b-1b1b-1b1b-1b1b-1b1b1b1b1b1b"
34+
}
35+
}
36+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"id": "1b1b1b1b-1b1b-1b1b-1b1b-1b1b1b1b1b1b",
3+
"name": "My Updated Application",
4+
"keys": {
5+
"public_key": "-----BEGIN PUBLIC KEY-----\nupdated_public_key_info\n-----END PUBLIC KEY-----\n"
6+
},
7+
"capabilities": {},
8+
"_links": {
9+
"self": {
10+
"href": "/v2/applications/1b1b1b1b-1b1b-1b1b-1b1b-1b1b1b1b1b1b"
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)