Skip to content

Commit 036b2c3

Browse files
committed
Refactor existing verbs for changes to attributes
1 parent 9c4367d commit 036b2c3

File tree

8 files changed

+42
-36
lines changed

8 files changed

+42
-36
lines changed

bandwidth/model/bxml/terminal_verb.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ class TerminalVerb(Verb):
1212
"""Base class for BXML verbs
1313
"""
1414

15-
def __init__(self, tag: str, content: str = None, attributes: dict = None):
15+
def __init__(self, tag: str, content: str = None):
1616
"""Initialize the verb model
1717
1818
Args:
1919
tag (str): Name of the XML element
2020
content (str, optional): XML element content. Defaults to None.
21-
attributes (dict, optional): XML element attributes. Defaults to None.
2221
"""
23-
super().__init__(tag=tag, content=content, attributes=attributes, nested_verbs=None)
22+
super().__init__(tag=tag, content=content, nested_verbs=None)
2423

2524
def add_verb(self, verb: Verb):
2625
"""Adding verbs is not allowed for this class

bandwidth/model/bxml/verb.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ class Verb:
1313
"""Base class for BXML verbs
1414
"""
1515

16-
def __init__(self, tag: str, content: str = None, attributes: dict = None, nested_verbs: list[Verb] = None):
16+
def __init__(self, tag: str, content: str = None, nested_verbs: list[Verb] = None):
1717
"""Initialize the verb model
1818
1919
Args:
2020
tag (str): Name of the XML element
2121
content (str, optional): XML element content. Defaults to None.
22-
attributes (dict, optional): XML element attributes. Defaults to None.
2322
nested_verbs (list[BxmlVerb], optional): XML element children. Defaults to None.
2423
"""
2524
self._tag = tag
@@ -29,8 +28,8 @@ def __init__(self, tag: str, content: str = None, attributes: dict = None, neste
2928
self._nested_verbs = []
3029

3130
@property
32-
def attributes():
33-
return {}
31+
def attributes(self):
32+
return None
3433

3534
def __len__(self) -> int:
3635
"""Override default len method. Returns length of _nested_verbs array
@@ -57,7 +56,7 @@ def _set_attributes(self, root: ET.Element):
5756
Args:
5857
root (ET.Element): XML Element to add attributes to
5958
"""
60-
if self.attributes:
59+
if self.attributes is not None:
6160
for key, value in self.attributes.items():
6261
if value is not None:
6362
root.set(key, value)

bandwidth/model/bxml/verbs/bridge.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@ def __init__(
5555
self.fallback_username = fallback_username
5656
self.fallback_password = fallback_password
5757
self.tag = tag
58-
self.attributes = {
58+
super().__init__(
59+
tag="Bridge",
60+
content=self.target_call,
61+
)
62+
63+
@property
64+
def attributes(self):
65+
return {
5966
"bridgeCompleteUrl": self.bridge_complete_url,
6067
"bridgeCompleteMethod": self.bridge_complete_method,
6168
"bridgeCompleteFallbackUrl": self.bridge_complete_fallback_url,
@@ -70,8 +77,3 @@ def __init__(
7077
"fallbackPassword": self.fallback_password,
7178
"tag": self.tag
7279
}
73-
super().__init__(
74-
tag="Bridge",
75-
content=self.target_call,
76-
attributes=self.attributes
77-
)

bandwidth/model/bxml/verbs/phone_number.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ def __init__(
4444
self.fallback_username = fallback_username
4545
self.fallback_password = fallback_password
4646
self.tag = tag
47-
self.attributes = {
47+
super().__init__(
48+
tag="PhoneNumber",
49+
content=self.number
50+
)
51+
52+
@property
53+
def attributes(self):
54+
return {
4855
"transferAnswerUrl": self.transfer_answer_url,
4956
"transferAnswerMethod": self.transfer_answer_method,
5057
"transferAnswerFallbackUrl": self.transfer_answer_fallback_url,
@@ -57,8 +64,3 @@ def __init__(
5764
"fallbackPassword": self.fallback_password,
5865
"tag": self.tag
5966
}
60-
super().__init__(
61-
tag="PhoneNumber",
62-
content=self.number,
63-
attributes=self.attributes
64-
)

bandwidth/model/bxml/verbs/record.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(
6464
self.max_duration = max_duration
6565
self.silence_timeout = silence_timeout
6666
self.file_format = file_format
67-
super().__init__(tag="Record", content=None, attributes=self.attributes)
67+
super().__init__(tag="Record", content=None)
6868

6969
@property
7070
def attributes(self):

bandwidth/model/bxml/verbs/sip_uri.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ def __init__(
4646
self.fallback_username = fallback_username
4747
self.fallback_password = fallback_password
4848
self.tag = tag
49-
self.attributes = {
50-
"uui": uui,
49+
super().__init__(
50+
tag="SipUri",
51+
content=self.uri,
52+
)
53+
54+
@property
55+
def attributes(self):
56+
return {
57+
"uui": self.uui,
5158
"transferAnswerUrl": self.transfer_answer_url,
5259
"transferAnswerMethod": self.transfer_answer_method,
5360
"transferAnswerFallbackUrl": self.transfer_answer_fallback_url,
@@ -60,8 +67,3 @@ def __init__(
6067
"fallbackPassword": self.fallback_password,
6168
"tag": self.tag
6269
}
63-
super().__init__(
64-
tag="SipUri",
65-
content=self.uri,
66-
attributes=self.attributes
67-
)

bandwidth/model/bxml/verbs/tag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ def __init__(self, content=""):
1717
content (str, optional): Custom tag value. Defaults to "".
1818
"""
1919
self.content = content
20-
super().__init__(tag="Tag", content=self.content, attributes=None)
20+
super().__init__(tag="Tag", content=self.content)

bandwidth/model/bxml/verbs/transfer.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,15 @@ def __init__(
7575
self.tag = tag
7676
self.diversion_treatment = diversion_treatment
7777
self.diversion_reason = diversion_reason
78-
self.attributes = {
78+
super().__init__(
79+
tag="Transfer",
80+
content=None,
81+
nested_verbs=self.transfer_to
82+
)
83+
84+
@property
85+
def attributes(self):
86+
return {
7987
"transferCallerId": self.transfer_caller_id,
8088
"callTimeout": self.call_timeout,
8189
"transferCompleteUrl": self.transfer_complete_url,
@@ -90,12 +98,6 @@ def __init__(
9098
"diversionTreatment": self.diversion_treatment,
9199
"diversionReason": self.diversion_reason
92100
}
93-
super().__init__(
94-
tag="Transfer",
95-
content=None,
96-
attributes=self.attributes,
97-
nested_verbs=self.transfer_to
98-
)
99101

100102
def add_transfer_recipient(self, recipient: Union[PhoneNumber, SipUri]):
101103
super().add_verb(recipient)

0 commit comments

Comments
 (0)