From c86928c570acf23af6533fee37d3f37381fe7c61 Mon Sep 17 00:00:00 2001 From: AJ Rice <53190766+ajrice6713@users.noreply.github.com> Date: Mon, 3 Oct 2022 15:36:29 -0400 Subject: [PATCH 1/3] DX-2904 `` BXML --- bandwidth/model/bxml/verbs/__init__.py | 1 + bandwidth/model/bxml/verbs/pause_recording.py | 2 +- bandwidth/model/bxml/verbs/redirect.py | 56 +++++++++++++++++++ test/unit/bxml/test_redirect.py | 30 ++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 bandwidth/model/bxml/verbs/redirect.py create mode 100644 test/unit/bxml/test_redirect.py diff --git a/bandwidth/model/bxml/verbs/__init__.py b/bandwidth/model/bxml/verbs/__init__.py index c29ce144..8896dbdf 100644 --- a/bandwidth/model/bxml/verbs/__init__.py +++ b/bandwidth/model/bxml/verbs/__init__.py @@ -2,6 +2,7 @@ from .pause_recording import PauseRecording from .phone_number import PhoneNumber from .record import Record +from .redirect import Redirect from .sip_uri import SipUri from .tag import Tag from .transfer import Transfer diff --git a/bandwidth/model/bxml/verbs/pause_recording.py b/bandwidth/model/bxml/verbs/pause_recording.py index dffc73ab..e18e8314 100644 --- a/bandwidth/model/bxml/verbs/pause_recording.py +++ b/bandwidth/model/bxml/verbs/pause_recording.py @@ -13,4 +13,4 @@ class PauseRecording(TerminalVerb): def __init__(self): """Initialize a verb """ - super().__init__(tag="PauseRecording", content=None, attributes=None) + super().__init__(tag="PauseRecording", content=None) diff --git a/bandwidth/model/bxml/verbs/redirect.py b/bandwidth/model/bxml/verbs/redirect.py new file mode 100644 index 00000000..1b49a742 --- /dev/null +++ b/bandwidth/model/bxml/verbs/redirect.py @@ -0,0 +1,56 @@ +""" +redirect.py + +Bandwidth's Redirect BXML verb + +@copyright Bandwidth INC +""" +from ..terminal_verb import TerminalVerb + + +class Redirect(TerminalVerb): + + def __init__( + self, redirect_url: str, redirect_method: str = None, + redirect_fallback_url: str = None, + redirect_fallback_method: str = None, username: str = None, + password: str = None, fallback_username: str = None, + fallback_password: str = None, tag: str = None + ): + """Initialize a verb + + Args: + 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. + redirect_method (str, optional): The HTTP method to use for the request to redirectUrl. GET or POST. Defaults to None. + 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. + 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. + username (str, optional): The username to send in the HTTP request to redirectUrl. Defaults to None. + password (str, optional): The password to send in the HTTP request to redirectUrl. Defaults to None. + fallback_username (str, optional): The username to send in the HTTP request to redirectFallbackUrl. Defaults to None. + fallback_password (str, optional): The password to send in the HTTP request to redirectFallbackUrl. Defaults to None. + tag (str, optional): A custom string that will be sent with this and all future callbacks unless overwritten by a future tag attribute or verb, or cleared. May be cleared by setting tag="". Max length 256 characters. Defaults to None. + """ + self.redirect_url = redirect_url + self.redirect_method = redirect_method + self.redirect_fallback_url = redirect_fallback_url + self.redirect_fallback_method = redirect_fallback_method + self.username = username + self.password = password + self.fallback_username = fallback_username + self.fallback_password = fallback_password + self.tag = tag + super().__init__(tag="Redirect") + + @property + def _attributes(self): + return { + "redirectUrl": self.redirect_url, + "redirectMethod": self.redirect_method, + "redirectFallbackUrl": self.redirect_fallback_url, + "redirectFallbackMethod": self.redirect_fallback_method, + "username": self.username, + "password": self.password, + "fallbackUsername": self.fallback_username, + "fallbackPassword": self.fallback_password, + "tag": self.tag, + } diff --git a/test/unit/bxml/test_redirect.py b/test/unit/bxml/test_redirect.py new file mode 100644 index 00000000..ec68b66b --- /dev/null +++ b/test/unit/bxml/test_redirect.py @@ -0,0 +1,30 @@ +""" +test_redirect.py + +Unit tests for the BXML verb + +@copyright Bandwidth Inc. +""" +import pytest +import unittest + +from bandwidth.model.bxml.verb import Verb +from bandwidth.model.bxml.verbs.redirect import Redirect + + +class TestRecord(unittest.TestCase): + + def setUp(self): + self.redirect = Redirect("https://example.com/redirect") + # self.redirect.redirect_url = "https://example.com/redirect" + self.test_verb = Verb(tag="test") + + def test_to_bxml(self): + expected = '' + assert(expected == self.redirect.to_bxml()) + + + def test_add_verb(self): + with pytest.raises(AttributeError): + self.record.add_verb(self.test_verb) + From 791587b5d5dd568b1d0c63d6d679c600f32336a5 Mon Sep 17 00:00:00 2001 From: AJ Rice <53190766+ajrice6713@users.noreply.github.com> Date: Mon, 3 Oct 2022 15:37:53 -0400 Subject: [PATCH 2/3] Trigger Tests From 8e1194b30400da9de17f4df1d8b59296644ab4c7 Mon Sep 17 00:00:00 2001 From: AJ Rice <53190766+ajrice6713@users.noreply.github.com> Date: Wed, 5 Oct 2022 14:11:07 -0400 Subject: [PATCH 3/3] Add param descriptions for `bridge.py` constructor --- bandwidth/model/bxml/verbs/bridge.py | 32 ++++++++++++++++------------ 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/bandwidth/model/bxml/verbs/bridge.py b/bandwidth/model/bxml/verbs/bridge.py index 38ad8c1e..1c3b52c0 100644 --- a/bandwidth/model/bxml/verbs/bridge.py +++ b/bandwidth/model/bxml/verbs/bridge.py @@ -26,20 +26,24 @@ def __init__( """Initialize a verb Args: - target_call (str): _description_ - bridge_complete_url (str, optional): _description_. Defaults to None. - bridge_complete_method (str, optional): _description_. Defaults to None. - bridge_complete_fallback_url (str, optional): _description_. Defaults to None. - bridge_complete_fallback_method (str, optional): _description_. Defaults to None. - bridge_target_complete_url (str, optional): _description_. Defaults to None. - bridge_target_complete_method (str, optional): _description_. Defaults to None. - bridge_target_complete_fallback_url (str, optional): _description_. Defaults to None. - bridge_target_complete_fallback_method (str, optional): _description_. Defaults to None. - username (str, optional): _description_. Defaults to None. - password (str, optional): _description_. Defaults to None. - fallback_username (str, optional): _description_. Defaults to None. - fallback_password (str, optional): _description_. Defaults to None. - tag (str, optional): _description_. Defaults to None. + target_call (str): String containing the callId of the call to be bridged. + bridge_complete_url (str, optional): URL to send the Bridge Complete event to and request new BXML. + If this attribute is specified, then Verbs following the verb will be ignored and the BXML returned in this webhook is executed on the call. + If this attribute is not specified then no webhook will be sent, and execution of the verbs following the verb continues. May be a relative URL. Defaults to None. + bridge_complete_method (str, optional): The HTTP method to use for the request to bridgeCompleteUrl. GET or POST. Default value is POST. + 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. + 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. + bridge_target_complete_url (str, optional):URL to send the Bridge Target Complete event to and request new BXML. + If this attribute is specified, then the BXML returned in this webhook is executed on the target call. + 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. + bridge_target_complete_method (str, optional): The HTTP method to use for the request to bridgeTargetCompleteUrl. GET or POST. Default value is POST. + 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. + 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. + username (str, optional): The username to send in the HTTP request to bridgeCompleteUrl and to bridgeTargetCompleteUrl. Defaults to None. + password (str, optional): The password to send in the HTTP request to bridgeCompleteUrl and to bridgeTargetCompleteUrl. Defaults to None. + fallback_username (str, optional): The username to send in the HTTP request to bridgeCompleteFallbackUrl and to bridgeTargetCompleteFallbackUrl. Defaults to None. + fallback_password (str, optional): The password to send in the HTTP request to bridgeCompleteFallbackUrl and to bridgeTargetCompleteFallbackUrl. Defaults to None. + 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 verb, or cleared. May be cleared by setting tag="". Max length 256 characters. Defaults to None. """ self.target_call = target_call self.bridge_complete_url = bridge_complete_url