|
1 | | -# -*- coding: utf-8 -*- |
2 | | -"""Webex Teams data models. |
3 | | -
|
4 | | -Copyright (c) 2016-2018 Cisco and/or its affiliates. |
5 | | -
|
6 | | -Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | | -of this software and associated documentation files (the "Software"), to deal |
8 | | -in the Software without restriction, including without limitation the rights |
9 | | -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10 | | -copies of the Software, and to permit persons to whom the Software is |
11 | | -furnished to do so, subject to the following conditions: |
12 | | -
|
13 | | -The above copyright notice and this permission notice shall be included in all |
14 | | -copies or substantial portions of the Software. |
15 | | -
|
16 | | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | | -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | | -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | | -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20 | | -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21 | | -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22 | | -SOFTWARE. |
23 | | -""" |
24 | | - |
25 | | - |
26 | | -from __future__ import ( |
27 | | - absolute_import, |
28 | | - division, |
29 | | - print_function, |
30 | | - unicode_literals, |
31 | | -) |
32 | | - |
33 | | -from collections import defaultdict |
34 | | - |
35 | | -from .access_token import AccessTokenBasicPropertiesMixin |
36 | | -from .event import EventBasicPropertiesMixin |
37 | | -from .license import LicenseBasicPropertiesMixin |
38 | | -from .membership import MembershipBasicPropertiesMixin |
39 | | -from .message import MessageBasicPropertiesMixin |
40 | | -from .organization import OrganizationBasicPropertiesMixin |
41 | | -from .person import PersonBasicPropertiesMixin |
42 | | -from .role import RoleBasicPropertiesMixin |
43 | | -from .room import RoomBasicPropertiesMixin |
44 | | -from .simple import SimpleDataModel |
45 | | -from .sparkdata import SparkData |
46 | | -from .team import TeamBasicPropertiesMixin |
47 | | -from .team_membership import TeamMembershipBasicPropertiesMixin |
48 | | -from .webhook import WebhookBasicPropertiesMixin |
49 | | -from .webhook_event import WebhookEventBasicPropertiesMixin |
50 | | -from ..utils import json_dict |
51 | | - |
52 | | - |
53 | | -class AccessToken(SparkData, AccessTokenBasicPropertiesMixin): |
54 | | - """Webex Teams Access-Token data model.""" |
55 | | - |
56 | | - |
57 | | -class Event(SparkData, EventBasicPropertiesMixin): |
58 | | - """Webex Teams Event data model.""" |
59 | | - |
60 | | - |
61 | | -class License(SparkData, LicenseBasicPropertiesMixin): |
62 | | - """Webex Teams License data model.""" |
63 | | - |
64 | | - |
65 | | -class Membership(SparkData, MembershipBasicPropertiesMixin): |
66 | | - """Webex Teams Membership data model.""" |
67 | | - |
68 | | - |
69 | | -class Message(SparkData, MessageBasicPropertiesMixin): |
70 | | - """Webex Teams Message data model.""" |
71 | | - |
72 | | - |
73 | | -class Organization(SparkData, OrganizationBasicPropertiesMixin): |
74 | | - """Webex Teams Organization data model.""" |
75 | | - |
76 | | - |
77 | | -class Person(SparkData, PersonBasicPropertiesMixin): |
78 | | - """Webex Teams Person data model.""" |
79 | | - |
80 | | - |
81 | | -class Role(SparkData, RoleBasicPropertiesMixin): |
82 | | - """Webex Teams Role data model.""" |
83 | | - |
84 | | - |
85 | | -class Room(SparkData, RoomBasicPropertiesMixin): |
86 | | - """Webex Teams Room data model.""" |
87 | | - |
88 | | - |
89 | | -class Team(SparkData, TeamBasicPropertiesMixin): |
90 | | - """Webex Teams Team data model.""" |
91 | | - |
92 | | - |
93 | | -class TeamMembership(SparkData, TeamMembershipBasicPropertiesMixin): |
94 | | - """Webex Teams Team-Membership data model.""" |
95 | | - |
96 | | - |
97 | | -class Webhook(SparkData, WebhookBasicPropertiesMixin): |
98 | | - """Webex Teams Webhook data model.""" |
99 | | - |
100 | | - |
101 | | -class WebhookEvent(SparkData, WebhookEventBasicPropertiesMixin): |
102 | | - """Webex Teams Webhook-Events data model.""" |
103 | | - |
104 | | - |
105 | | -spark_data_models = defaultdict( |
106 | | - lambda: SparkData, |
107 | | - access_token=AccessToken, |
108 | | - event=Event, |
109 | | - license=License, |
110 | | - membership=Membership, |
111 | | - message=Message, |
112 | | - organization=Organization, |
113 | | - person=Person, |
114 | | - role=Role, |
115 | | - room=Room, |
116 | | - team=Team, |
117 | | - team_membership=TeamMembership, |
118 | | - webhook=Webhook, |
119 | | - webhook_event=WebhookEvent, |
120 | | -) |
121 | | - |
122 | | - |
123 | | -def spark_data_factory(model, json_data): |
124 | | - """Factory function for creating SparkData objects. |
125 | | -
|
126 | | - Args: |
127 | | - model(basestring): The data model to use when creating the SparkData |
128 | | - object (message, room, membership, etc.). |
129 | | - json_data(basestring, dict): The JSON string or dictionary data with |
130 | | - which to initialize the object. |
131 | | -
|
132 | | - Returns: |
133 | | - SparkData: The created SparkData object. |
134 | | -
|
135 | | - Raises: |
136 | | - TypeError: If the json_data parameter is not a JSON string or |
137 | | - dictionary. |
138 | | -
|
139 | | - """ |
140 | | - return spark_data_models[model](json_data) |
141 | | - |
142 | | - |
143 | | -def simple_data_factory(model, json_data): |
144 | | - """Factory function for creating SimpleDataModel objects. |
145 | | -
|
146 | | - Args: |
147 | | - model(basestring): The data model to use when creating the SparkData |
148 | | - object (message, room, membership, etc.). |
149 | | - json_data(basestring, dict): The JSON string or dictionary data with |
150 | | - which to initialize the object. |
151 | | -
|
152 | | - Returns: |
153 | | - SimpleDataModel: The created SimpleDataModel object. |
154 | | -
|
155 | | - Raises: |
156 | | - TypeError: If the json_data parameter is not a JSON string or |
157 | | - dictionary. |
158 | | -
|
159 | | - """ |
160 | | - return SimpleDataModel(json_data) |
161 | | - |
162 | | - |
163 | | -def dict_data_factory(model, json_data): |
164 | | - """Factory function for creating SimpleDataModel objects. |
165 | | -
|
166 | | - Args: |
167 | | - model(basestring): The data model to use when creating the SparkData |
168 | | - object (message, room, membership, etc.). |
169 | | - json_data(basestring, dict): The JSON string or dictionary data with |
170 | | - which to initialize the object. |
171 | | -
|
172 | | - Returns: |
173 | | - OrderedDict: An ordered dictionary with the contents of the Spark JSON |
174 | | - object. |
175 | | -
|
176 | | - Raises: |
177 | | - TypeError: If the json_data parameter is not a JSON string or |
178 | | - dictionary. |
179 | | -
|
180 | | - """ |
181 | | - return json_dict(json_data) |
0 commit comments