Skip to content

Commit

Permalink
make data models accessible from top level
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkahan committed Jan 30, 2025
1 parent 7139a4e commit fb32f46
Show file tree
Hide file tree
Showing 24 changed files with 116 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ["3.9", "3.10", "3.11", "3.12", "3.13"]
python: ["3.9", "3.10", "3.11", "3.12"]
os: ["ubuntu-latest"]
steps:
- name: Clone repo
Expand Down
55 changes: 26 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,12 @@ verify_signature(TOKEN, SIGNATURE_SECRET) # Returns a boolean

## Messages API


### How to Construct a Message

In order to send a message, you must construct a message object of the correct type. These are all found under `vonage_messages.models`.
In order to send a message, you must construct a message object of the correct type.

```python
from vonage_messages.models import Sms
from vonage_messages import Sms

message = Sms(
from_='Vonage APIs',
Expand All @@ -435,7 +434,7 @@ Some message types have submodels with additional fields. In this case, import t
e.g.

```python
from vonage_messages.models import MessengerImage, MessengerOptions, MessengerResource
from vonage_messages import MessengerImage, MessengerOptions, MessengerResource

messenger = MessengerImage(
to='1234567890',
Expand All @@ -451,7 +450,7 @@ To send a message, access the `Messages.send` method via the main Vonage object,

```python
from vonage import Auth, Vonage
from vonage_messages.models import Sms
from vonage_messages import Sms

vonage_client = Vonage(Auth(application_id='my-application-id', private_key='my-private-key'))

Expand Down Expand Up @@ -970,12 +969,10 @@ response = vonage_client.verify_legacy.request_network_unblock('23410')

## Video API

You will use the custom Pydantic data models to make most of the API calls in this package. They are accessed from the `vonage_video.models` package.

### Generate a Client Token

```python
from vonage_video.models import TokenOptions
from vonage_video import TokenOptions

token_options = TokenOptions(session_id='your_session_id', role='publisher')
client_token = vonage_client.video.generate_client_token(token_options)
Expand All @@ -984,7 +981,7 @@ client_token = vonage_client.video.generate_client_token(token_options)
### Create a Session

```python
from vonage_video.models import SessionOptions
from vonage_video import SessionOptions

session_options = SessionOptions(media_mode='routed')
video_session = vonage_client.video.create_session(session_options)
Expand All @@ -1005,7 +1002,7 @@ stream_info = vonage_client.video.get_stream(session_id='your_session_id', strea
### Change Stream Layout

```python
from vonage_video.models import StreamLayoutOptions
from vonage_video import StreamLayoutOptions

layout_options = StreamLayoutOptions(type='bestFit')
updated_streams = vonage_client.video.change_stream_layout(session_id='your_session_id', stream_layout_options=layout_options)
Expand All @@ -1014,7 +1011,7 @@ updated_streams = vonage_client.video.change_stream_layout(session_id='your_sess
### Send a Signal

```python
from vonage_video.models import SignalData
from vonage_video import SignalData

signal_data = SignalData(type='chat', data='Hello, World!')
vonage_client.video.send_signal(session_id='your_session_id', data=signal_data)
Expand Down Expand Up @@ -1047,7 +1044,7 @@ vonage_client.video.disable_mute_all_streams(session_id='your_session_id')
### Start Captions

```python
from vonage_video.models import CaptionsOptions
from vonage_video import CaptionsOptions

captions_options = CaptionsOptions(language='en-US')
captions_data = vonage_client.video.start_captions(captions_options)
Expand All @@ -1056,7 +1053,7 @@ captions_data = vonage_client.video.start_captions(captions_options)
### Stop Captions

```python
from vonage_video.models import CaptionsData
from vonage_video import CaptionsData

captions_data = CaptionsData(captions_id='your_captions_id')
vonage_client.video.stop_captions(captions_data)
Expand All @@ -1065,7 +1062,7 @@ vonage_client.video.stop_captions(captions_data)
### Start Audio Connector

```python
from vonage_video.models import AudioConnectorOptions
from vonage_video import AudioConnectorOptions

audio_connector_options = AudioConnectorOptions(session_id='your_session_id', token='your_token', url='https://example.com')
audio_connector_data = vonage_client.video.start_audio_connector(audio_connector_options)
Expand All @@ -1074,7 +1071,7 @@ audio_connector_data = vonage_client.video.start_audio_connector(audio_connector
### Start Experience Composer

```python
from vonage_video.models import ExperienceComposerOptions
from vonage_video import ExperienceComposerOptions

experience_composer_options = ExperienceComposerOptions(session_id='your_session_id', token='your_token', url='https://example.com')
experience_composer = vonage_client.video.start_experience_composer(experience_composer_options)
Expand All @@ -1083,7 +1080,7 @@ experience_composer = vonage_client.video.start_experience_composer(experience_c
### List Experience Composers

```python
from vonage_video.models import ListExperienceComposersFilter
from vonage_video import ListExperienceComposersFilter

filter = ListExperienceComposersFilter(page_size=10)
experience_composers, count, next_page_offset = vonage_client.video.list_experience_composers(filter)
Expand All @@ -1105,7 +1102,7 @@ vonage_client.video.stop_experience_composer(experience_composer_id='experience_
### List Archives

```python
from vonage_video.models import ListArchivesFilter
from vonage_video import ListArchivesFilter

filter = ListArchivesFilter(offset=2)
archives, count, next_page_offset = vonage_client.video.list_archives(filter)
Expand All @@ -1115,7 +1112,7 @@ print(archives)
### Start Archive

```python
from vonage_video.models import CreateArchiveRequest
from vonage_video import CreateArchiveRequest

archive_options = CreateArchiveRequest(session_id='your_session_id', name='My Archive')
archive = vonage_client.video.start_archive(archive_options)
Expand All @@ -1137,7 +1134,7 @@ vonage_client.video.delete_archive(archive_id='your_archive_id')
### Add Stream to Archive

```python
from vonage_video.models import AddStreamRequest
from vonage_video import AddStreamRequest

add_stream_request = AddStreamRequest(stream_id='your_stream_id')
vonage_client.video.add_stream_to_archive(archive_id='your_archive_id', params=add_stream_request)
Expand All @@ -1159,7 +1156,7 @@ print(archive)
### Change Archive Layout

```python
from vonage_video.models import ComposedLayout
from vonage_video import ComposedLayout

layout = ComposedLayout(type='bestFit')
archive = vonage_client.video.change_archive_layout(archive_id='your_archive_id', layout=layout)
Expand All @@ -1169,7 +1166,7 @@ print(archive)
### List Broadcasts

```python
from vonage_video.models import ListBroadcastsFilter
from vonage_video import ListBroadcastsFilter

filter = ListBroadcastsFilter(page_size=10)
broadcasts, count, next_page_offset = vonage_client.video.list_broadcasts(filter)
Expand All @@ -1179,7 +1176,7 @@ print(broadcasts)
### Start Broadcast

```python
from vonage_video.models import CreateBroadcastRequest, BroadcastOutputSettings, BroadcastHls, BroadcastRtmp
from vonage_video import CreateBroadcastRequest, BroadcastOutputSettings, BroadcastHls, BroadcastRtmp

broadcast_options = CreateBroadcastRequest(session_id='your_session_id', outputs=BroadcastOutputSettings(
hls=BroadcastHls(dvr=True, low_latency=False),
Expand Down Expand Up @@ -1213,7 +1210,7 @@ print(broadcast)
### Change Broadcast Layout

```python
from vonage_video.models import ComposedLayout
from vonage_video import ComposedLayout

layout = ComposedLayout(type='bestFit')
broadcast = vonage_client.video.change_broadcast_layout(broadcast_id='your_broadcast_id', layout=layout)
Expand All @@ -1223,7 +1220,7 @@ print(broadcast)
### Add Stream to Broadcast

```python
from vonage_video.models import AddStreamRequest
from vonage_video import AddStreamRequest

add_stream_request = AddStreamRequest(stream_id='your_stream_id')
vonage_client.video.add_stream_to_broadcast(broadcast_id='your_broadcast_id', params=add_stream_request)
Expand All @@ -1238,7 +1235,7 @@ vonage_client.video.remove_stream_from_broadcast(broadcast_id='your_broadcast_id
### Initiate SIP Call

```python
from vonage_video.models import InitiateSipRequest, SipOptions, SipAuth
from vonage_video import InitiateSipRequest, SipOptions, SipAuth

sip_request_params = InitiateSipRequest(
session_id='your_session_id',
Expand Down Expand Up @@ -1281,7 +1278,7 @@ vonage_client.video.play_dtmf(session_id=session_id, digits=digits, connection_i
To create a call, you must pass an instance of the `CreateCallRequest` model to the `create_call` method. If supplying an NCCO, import the NCCO actions you want to use and pass them in as a list to the `ncco` model field.

```python
from vonage_voice.models import CreateCallRequest, Talk
from vonage_voice import CreateCallRequest, Talk

ncco = [Talk(text='Hello world', loop=3, language='en-GB')]

Expand All @@ -1303,7 +1300,7 @@ print(response.model_dump())
calls, next_record_index = vonage_client.voice.list_calls()

# Specify filtering options
from vonage_voice.models import ListCallsFilter
from vonage_voice import ListCallsFilter

call_filter = ListCallsFilter(
status='completed',
Expand Down Expand Up @@ -1364,7 +1361,7 @@ vonage_client.voice.unearmuff('UUID')
### Play Audio Into a Call

```python
from vonage_voice.models import AudioStreamOptions
from vonage_voice import AudioStreamOptions

# Only the `stream_url` option is required
options = AudioStreamOptions(
Expand All @@ -1382,7 +1379,7 @@ vonage_client.voice.stop_audio_stream('UUID')
### Play TTS Into a Call

```python
from vonage_voice.models import TtsStreamOptions
from vonage_voice import TtsStreamOptions

# Only the `text` field is required
options = TtsStreamOptions(
Expand Down
3 changes: 3 additions & 0 deletions messages/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.4.0
- Make all models originally accessed by `vonage_messages.models.***` available at the top level of the package, i.e. `vonage_messages.***`

# 1.3.0
- Add support for API key/secret header authentication
- Updated dependency versions
Expand Down
8 changes: 4 additions & 4 deletions messages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ It is recommended to use this as part of the main `vonage` package. The examples

### How to Construct a Message

In order to send a message, you must construct a message object of the correct type. These are all found under `vonage_messages.models`.
In order to send a message, you must construct a message object of the correct type.

```python
from vonage_messages.models import Sms
from vonage_messages import Sms

message = Sms(
from_='Vonage APIs',
Expand All @@ -35,7 +35,7 @@ Some message types have submodels with additional fields. In this case, import t
e.g.

```python
from vonage_messages.models import MessengerImage, MessengerOptions, MessengerResource
from vonage_messages import MessengerImage, MessengerOptions, MessengerResource

messenger = MessengerImage(
to='1234567890',
Expand All @@ -51,7 +51,7 @@ To send a message, access the `Messages.send` method via the main Vonage object,

```python
from vonage import Auth, Vonage
from vonage_messages.models import Sms
from vonage_messages import Sms

vonage_client = Vonage(Auth(application_id='my-application-id', private_key='my-private-key'))

Expand Down
3 changes: 2 additions & 1 deletion messages/src/vonage_messages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import models
from . import models # Import models to access the module directly
from .messages import Messages
from .models import * # Need this to directly expose data models
from .responses import SendMessageResponse

__all__ = ['models', 'Messages', 'SendMessageResponse']
2 changes: 1 addition & 1 deletion messages/src/vonage_messages/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.0'
__version__ = '1.4.0'
12 changes: 5 additions & 7 deletions messages/tests/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import responses
from pytest import raises
from vonage_http_client.auth import Auth
from vonage_http_client.errors import HttpRequestError
from vonage_http_client.http_client import HttpClient, HttpClientOptions
from vonage_messages.messages import Messages
from vonage_messages.models import Sms
from vonage_messages.models.messenger import (
from vonage_http_client import Auth, HttpClient, HttpClientOptions, HttpRequestError
from vonage_messages import (
Messages,
MessengerImage,
MessengerOptions,
MessengerResource,
SendMessageResponse,
Sms,
)
from vonage_messages.responses import SendMessageResponse

from testutils import build_response, get_mock_api_key_auth, get_mock_jwt_auth

Expand Down
2 changes: 1 addition & 1 deletion pants.ci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
colors = true

[python]
interpreter_constraints = ['>=3.8']
interpreter_constraints = ['>=3.9']
10 changes: 5 additions & 5 deletions pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ interpreter_constraints = ['==3.12.*']
args = ['-vv', '--no-header']

[coverage-py]
interpreter_constraints = ['>=3.8']
interpreter_constraints = ['>=3.9']
report = ['html', 'console']

[black]
args = ['--line-length=90', '--skip-string-normalization']
interpreter_constraints = ['>=3.8']
interpreter_constraints = ['>=3.9']

[isort]
args = ['--profile=black', '--line-length=90']
interpreter_constraints = ['>=3.8']
interpreter_constraints = ['>=3.9']

[docformatter]
args = ['--wrap-summaries=90', '--wrap-descriptions=90']
interpreter_constraints = ['>=3.8']
interpreter_constraints = ['>=3.9']

[autoflake]
interpreter_constraints = ['>=3.8']
interpreter_constraints = ['>=3.9']
3 changes: 3 additions & 0 deletions video/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.2.0
- Make all models originally accessed by `vonage_video.models.***` available at the top level of the package, i.e. `vonage_video.***`

# 1.1.0
- Add new `max_bitrate` field for archives

Expand Down
6 changes: 3 additions & 3 deletions video/OPENTOK_TO_VONAGE_MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ vonage_client.video.video_api_method...

## Accessing Video API Data Models

You can access data models for the Video API, e.g. as arguments to video methods, by importing them from the `vonage_video.models` package, e.g.
You can access data models for the Video API, e.g. as arguments to video methods, by importing them from the `vonage_video` package, e.g.

```python
from vonage_video.models import SessionOptions
from vonage_video import SessionOptions

session_options = SessionOptions(...)

Expand All @@ -78,7 +78,7 @@ vonage_client.video.create_session(session_options)

There are some changes to methods between the `opentok` SDK and the Video API implementation in the `vonage-video` SDK.

- Any positional parameters in method signatures have been replaced with data models in the `vonage-video` package, stored at `vonage_video.models`.
- Any positional parameters in method signatures have been replaced with data models in the `vonage-video` package.
- Methods now return responses as Pydantic data models.
- Some methods have been renamed, for clarity and/or to better reflect what the method does. These are listed below:

Expand Down
Loading

0 comments on commit fb32f46

Please sign in to comment.