Skip to content

Commit 59ddc6e

Browse files
committed
added docstrings to abstract components and card
1 parent 4f3c798 commit 59ddc6e

File tree

2 files changed

+62
-11
lines changed

2 files changed

+62
-11
lines changed

webexteamssdk/cards/abstract_components.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,43 @@
22
import json
33

44
class Serializable:
5-
"""Parent class to
5+
"""Parent class for all components of adaptive cards.
66
7+
Each component should inherit from this class and then specify, from
8+
its properties, which fall into the following two categories:
9+
10+
* Simple properties are text properties like "type" or "id"
11+
* Serializable properties are properties that can themselfes be serilized.
12+
This includes lists of items (i.e. the 'body' field of the adaptive card) or
13+
single objects that also inherit from Serializable
714
"""
815
def __init__(self, serializable_properties, simple_properties):
16+
"""Creates a serializable object.
17+
18+
See class docstring for an explanation what the different types of
19+
properties are.
20+
21+
Args:
22+
serializable_properties(list): List of all serializable properties
23+
simple_properties(list): List of all simple properties.
24+
"""
925
self.serializable_properties = serializable_properties
1026
self.simple_properties = simple_properties
1127

1228
def to_json(self, pretty=False):
29+
"""Create json from a serializable component
30+
31+
This function is used to render the json from a component. While all
32+
components do support this operation it is mainly used on the
33+
AdaptiveCard to generate the json for the attachment.
34+
35+
Args:
36+
pretty(boolean): If true, the returned json will be sorted by keys
37+
and indented with 4 spaces to make it more human-readable
38+
39+
Returns:
40+
A Json representation of this component
41+
"""
1342
ret = None
1443
if pretty:
1544
ret = json.dumps(self.to_dict(), indent=4, sort_keys=True)
@@ -26,6 +55,10 @@ def to_dict(self):
2655
(i.e. {'version': "1.2"}) while a serializable property is another
2756
subcomponent that also implements a to_dict() method.
2857
58+
The to_dict() method is used to recursively create a dict representation
59+
of the adaptive card. This dictionary representation can then be
60+
converted into json for usage with the API.
61+
2962
Returns:
3063
dict: Dictionary representation of this component.
3164
"""
@@ -53,10 +86,3 @@ def to_dict(self):
5386
export[cp] = l
5487

5588
return export
56-
57-
class Component:
58-
def __init__(self, component_type):
59-
self.component_type = component_type
60-
61-
def get_type(self):
62-
return self.component_type

webexteamssdk/cards/card.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
1-
from .abstract_components import Serializable, Component
1+
from .abstract_components import Serializable
22

33
class AdaptiveCard(Serializable):
4+
"""AdaptiveCard class that represents a adaptive card python object.
5+
6+
Note:
7+
Webex Teams currently supports version 1.1 of adaptive cards and thus
8+
only features from that release are supported in this abstraction.
9+
"""
410
def __init__(self, body=None,
511
actions=None,
612
selectAction=None,
713
style=None,
814
fallbackText=None,
915
lang=None):
10-
super().__init__(serializable_properties=['body', 'actions', 'selectAction', 'style'],
11-
simple_properties=['version', 'fallbackText', 'lang', 'schema', 'type'])
16+
"""Creates a new adaptive card object.
17+
18+
Args:
19+
body(list): The list of components and containers making up the
20+
body of this adaptive card.
21+
actions(list): The list of actions this adaptive card should contain
22+
selectAction(action): The action that should be invoked when this
23+
adaptive card is selected. Can be any action other then
24+
'ShowCard'
25+
fallbackText(str): The text that should be displayed on clients that
26+
can't render adaptive cards
27+
lang(str): The 2-letter ISO-639-1 language used in the card. This is
28+
used for localization of date/time functions
29+
30+
"""
31+
super().__init__(serializable_properties=[
32+
'body', 'actions', 'selectAction', 'style'
33+
],
34+
simple_properties=[
35+
'version', 'fallbackText', 'lang', 'schema', 'type'
36+
])
1237

1338
# Set properties
1439
self.type = "AdaptiveCard"

0 commit comments

Comments
 (0)