Skip to content

Commit 6a035b3

Browse files
Merge pull request #125 from Bandwidth/DX-2911
DX-2911 `<StartRecording>` Verb Refactored
2 parents 1e8ec23 + d8fad5c commit 6a035b3

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

bandwidth/model/bxml/verbs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .phone_number import PhoneNumber
44
from .play_audio import PlayAudio
55
from .record import Record
6+
from .start_recording import StartRecording
67
from .sip_uri import SipUri
78
from .speak_sentence import SpeakSentence
89
from .tag import Tag
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""
2+
start_recording.py
3+
4+
Bandwidth's StartRecording BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
10+
11+
class StartRecording(TerminalVerb):
12+
13+
def __init__(
14+
self, recording_available_url: str = None,
15+
recording_available_method: str = None,
16+
transcribe: str = None, transcription_available_url: str = None,
17+
transcription_available_method: str = None, username: str=None,
18+
password: str=None, tag: str=None,
19+
file_format: str = None, multi_channel: str = None
20+
):
21+
"""Initialize a <StartRecording> verb
22+
23+
Args:
24+
recording_available_url (str, optional): URL to send the Recording Available event to once it has been processed. Does not accept BXML. May be a relative URL. Defaults to None.
25+
recording_available_method (str, optional): The HTTP method to use for the request to recordingAvailableUrl. GET or POST. Default value is POST.
26+
transcribe (str, optional): A boolean value to indicate that recording should be transcribed. Transcription can succeed only for recordings of length greater than 500 milliseconds and less than 4 hours. Default is false. Defaults to None.
27+
transcription_available_url (str, optional): URL to send the Transcription Available event to once it has been processed. Does not accept BXML. May be a relative URL. Defaults to None.
28+
transcription_available_method (str, optional): The HTTP method to use for the request to transcriptionAvailableUrl. GET or POST. Default value is POST. Defaults to None.
29+
username (str, optional): The username to send in the HTTP request to recordCompleteUrl, recordingAvailableUrl or transcriptionAvailableUrl. If specified, the URLs must be TLS-encrypted (i.e., https). Defaults to None.
30+
password (str, optional): The password to send in the HTTP request to recordCompleteUrl, recordingAvailableUrl or transcriptionAvailableUrl. If specified, the URLs must be TLS-encrypted (i.e., https). Defaults to None.
31+
tag (str, optional): A custom string that will be sent with this and all future callbacks unless overwritten by a future tag attribute or <Tag> verb, or cleared. May be cleared by setting tag="". Max length 256 characters. Defaults to None.
32+
file_format (str, optional): The audio format that the recording will be saved as: mp3 or wav. Default value is wav. Defaults to None. max_duration (str, optional): Maximum length of recording (in seconds). Max 10800 (3 hours). Default value is 60. Defaults to None.
33+
multi_channel (str, optional): A boolean value indicating whether or not the recording file should separate each side of the call into its own audio channel. Default value is false.
34+
35+
"""
36+
self.recording_available_url = recording_available_url
37+
self.recording_available_method = recording_available_method
38+
self.transcribe = transcribe
39+
self.transcription_available_url = transcription_available_url
40+
self.transcription_available_method = transcription_available_method
41+
self.username = username
42+
self.password = password
43+
self.tag = tag
44+
self.file_format = file_format
45+
self.multi_channel = multi_channel
46+
super().__init__(tag="StartRecording", content=None)
47+
48+
@property
49+
def _attributes(self):
50+
return {
51+
"recordingAvailableUrl": self.recording_available_url,
52+
"recordingAvailableMethod": self.recording_available_method,
53+
"transcribe": self.transcribe,
54+
"transcriptionAvailableUrl": self.transcription_available_url,
55+
"transcriptionAvailableMethod": self.transcription_available_method,
56+
"username": self.username,
57+
"password": self.password,
58+
"tag": self.tag,
59+
"fileFormat": self.file_format,
60+
"multiChannel": self.multi_channel
61+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
test_start_recording.py
3+
4+
Unit tests for the <StartRecording> BXML verb
5+
6+
@copyright Bandwidth Inc.
7+
"""
8+
import os
9+
import pytest
10+
import unittest
11+
12+
from bandwidth.model.bxml.verb import Verb
13+
from bandwidth.model.bxml.verbs.start_recording import StartRecording
14+
15+
16+
class TestRecord(unittest.TestCase):
17+
18+
def setUp(self):
19+
self.start_recording = StartRecording(
20+
recording_available_url = "example.com",
21+
recording_available_method = "POST",
22+
transcribe = "true",
23+
transcription_available_url = "transcription-example.com",
24+
transcription_available_method = "POST",
25+
username = "user",
26+
password = "pass",
27+
tag = "tag",
28+
file_format = "wav",
29+
multi_channel = "true"
30+
)
31+
self.test_verb = Verb(tag="test")
32+
33+
34+
def test_to_bxml(self):
35+
if os.environ['PYTHON_VERSION'] == '3.7':
36+
expected = '<StartRecording fileFormat="wav" multiChannel="true" password="pass" recordingAvailableMethod="POST" recordingAvailableUrl="example.com" tag="tag" transcribe="true" transcriptionAvailableMethod="POST" transcriptionAvailableUrl="transcription-example.com" username="user" />'
37+
else:
38+
expected = '<StartRecording recordingAvailableUrl="example.com" recordingAvailableMethod="POST" transcribe="true" transcriptionAvailableUrl="transcription-example.com" transcriptionAvailableMethod="POST" username="user" password="pass" tag="tag" fileFormat="wav" multiChannel="true" />'
39+
40+
assert(expected == self.start_recording.to_bxml())
41+
42+
43+
def test_add_verb(self):
44+
with pytest.raises(AttributeError):
45+
self.start_recording.add_verb(self.test_verb)

0 commit comments

Comments
 (0)