Skip to content

Commit 9baf6aa

Browse files
authored
DX-2904 <Redirect> BXML (#126)
* DX-2904 `<Redirect>` BXML * Trigger Tests * Add param descriptions for `bridge.py` constructor
1 parent 4eff2ff commit 9baf6aa

File tree

4 files changed

+105
-14
lines changed

4 files changed

+105
-14
lines changed

bandwidth/model/bxml/verbs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .phone_number import PhoneNumber
88
from .play_audio import PlayAudio
99
from .record import Record
10+
from .redirect import Redirect
1011
from .ring import Ring
1112
from .send_dtmf import SendDtmf
1213
from .sip_uri import SipUri

bandwidth/model/bxml/verbs/bridge.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,24 @@ def __init__(
2626
"""Initialize a <Bridge> verb
2727
2828
Args:
29-
target_call (str): _description_
30-
bridge_complete_url (str, optional): _description_. Defaults to None.
31-
bridge_complete_method (str, optional): _description_. Defaults to None.
32-
bridge_complete_fallback_url (str, optional): _description_. Defaults to None.
33-
bridge_complete_fallback_method (str, optional): _description_. Defaults to None.
34-
bridge_target_complete_url (str, optional): _description_. Defaults to None.
35-
bridge_target_complete_method (str, optional): _description_. Defaults to None.
36-
bridge_target_complete_fallback_url (str, optional): _description_. Defaults to None.
37-
bridge_target_complete_fallback_method (str, optional): _description_. Defaults to None.
38-
username (str, optional): _description_. Defaults to None.
39-
password (str, optional): _description_. Defaults to None.
40-
fallback_username (str, optional): _description_. Defaults to None.
41-
fallback_password (str, optional): _description_. Defaults to None.
42-
tag (str, optional): _description_. Defaults to None.
29+
target_call (str): String containing the callId of the call to be bridged.
30+
bridge_complete_url (str, optional): URL to send the Bridge Complete event to and request new BXML.
31+
If this attribute is specified, then Verbs following the <Bridge> verb will be ignored and the BXML returned in this webhook is executed on the call.
32+
If this attribute is not specified then no webhook will be sent, and execution of the verbs following the <Bridge> verb continues. May be a relative URL. Defaults to None.
33+
bridge_complete_method (str, optional): The HTTP method to use for the request to bridgeCompleteUrl. GET or POST. Default value is POST.
34+
bridge_complete_fallback_url (str, optional): A fallback url which, if provided, will be used to retry the Bridge Complete webhook delivery in case bridgeCompleteUrl fails to respond. Defaults to None.
35+
bridge_complete_fallback_method (str, optional): The HTTP method to use to deliver the Bridge Complete webhook to bridgeCompleteFallbackUrl. GET or POST. Default value is POST.
36+
bridge_target_complete_url (str, optional):URL to send the Bridge Target Complete event to and request new BXML.
37+
If this attribute is specified, then the BXML returned in this webhook is executed on the target call.
38+
If this attribute is not specified then no webhook will be sent, and the target call will be hung up. May be a relative URL. Defaults to None.
39+
bridge_target_complete_method (str, optional): The HTTP method to use for the request to bridgeTargetCompleteUrl. GET or POST. Default value is POST.
40+
bridge_target_complete_fallback_url (str, optional): A fallback url which, if provided, will be used to retry the Bridge Target Complete webhook delivery in case bridgeTargetCompleteUrl fails to respond. Defaults to None.
41+
bridge_target_complete_fallback_method (str, optional): The HTTP method to use to deliver the Bridge Target Complete webhook to bridgeTargetCompleteFallbackUrl. GET or POST. Default value is POST.
42+
username (str, optional): The username to send in the HTTP request to bridgeCompleteUrl and to bridgeTargetCompleteUrl. Defaults to None.
43+
password (str, optional): The password to send in the HTTP request to bridgeCompleteUrl and to bridgeTargetCompleteUrl. Defaults to None.
44+
fallback_username (str, optional): The username to send in the HTTP request to bridgeCompleteFallbackUrl and to bridgeTargetCompleteFallbackUrl. Defaults to None.
45+
fallback_password (str, optional): The password to send in the HTTP request to bridgeCompleteFallbackUrl and to bridgeTargetCompleteFallbackUrl. Defaults to None.
46+
tag (str, optional): A custom string that will be sent with the bridgeComplete webhook and all future webhooks of the call 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.
4347
"""
4448
self.target_call = target_call
4549
self.bridge_complete_url = bridge_complete_url
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
redirect.py
3+
4+
Bandwidth's Redirect BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
10+
11+
class Redirect(TerminalVerb):
12+
13+
def __init__(
14+
self, redirect_url: str, redirect_method: str = None,
15+
redirect_fallback_url: str = None,
16+
redirect_fallback_method: str = None, username: str = None,
17+
password: str = None, fallback_username: str = None,
18+
fallback_password: str = None, tag: str = None
19+
):
20+
"""Initialize a <Redirect> verb
21+
22+
Args:
23+
redirect_url (str): URL to request new BXML from. A Redirect event will be sent to this endpoint. May be a relative URL. Defaults to None.
24+
redirect_method (str, optional): The HTTP method to use for the request to redirectUrl. GET or POST. Defaults to None.
25+
redirect_fallback_url (str, optional): A fallback url which, if provided, will be used to retry the Redirect callback delivery in case redirectUrl fails to respond. Defaults to None.
26+
redirect_fallback_method (str, optional): The HTTP method to use to deliver the Redirect callback to redirectFallbackUrl. GET or POST. Default value is POST. Defaults to None.
27+
username (str, optional): The username to send in the HTTP request to redirectUrl. Defaults to None.
28+
password (str, optional): The password to send in the HTTP request to redirectUrl. Defaults to None.
29+
fallback_username (str, optional): The username to send in the HTTP request to redirectFallbackUrl. Defaults to None.
30+
fallback_password (str, optional): The password to send in the HTTP request to redirectFallbackUrl. 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+
"""
33+
self.redirect_url = redirect_url
34+
self.redirect_method = redirect_method
35+
self.redirect_fallback_url = redirect_fallback_url
36+
self.redirect_fallback_method = redirect_fallback_method
37+
self.username = username
38+
self.password = password
39+
self.fallback_username = fallback_username
40+
self.fallback_password = fallback_password
41+
self.tag = tag
42+
super().__init__(tag="Redirect")
43+
44+
@property
45+
def _attributes(self):
46+
return {
47+
"redirectUrl": self.redirect_url,
48+
"redirectMethod": self.redirect_method,
49+
"redirectFallbackUrl": self.redirect_fallback_url,
50+
"redirectFallbackMethod": self.redirect_fallback_method,
51+
"username": self.username,
52+
"password": self.password,
53+
"fallbackUsername": self.fallback_username,
54+
"fallbackPassword": self.fallback_password,
55+
"tag": self.tag,
56+
}

test/unit/bxml/test_redirect.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
test_redirect.py
3+
4+
Unit tests for the <Record> BXML verb
5+
6+
@copyright Bandwidth Inc.
7+
"""
8+
import pytest
9+
import unittest
10+
11+
from bandwidth.model.bxml.verb import Verb
12+
from bandwidth.model.bxml.verbs.redirect import Redirect
13+
14+
15+
class TestRecord(unittest.TestCase):
16+
17+
def setUp(self):
18+
self.redirect = Redirect("https://example.com/redirect")
19+
# self.redirect.redirect_url = "https://example.com/redirect"
20+
self.test_verb = Verb(tag="test")
21+
22+
def test_to_bxml(self):
23+
expected = '<Redirect redirectUrl="https://example.com/redirect" />'
24+
assert(expected == self.redirect.to_bxml())
25+
26+
27+
def test_add_verb(self):
28+
with pytest.raises(AttributeError):
29+
self.record.add_verb(self.test_verb)
30+

0 commit comments

Comments
 (0)