3
3
4
4
Classes:
5
5
Team: Models a Spark 'team' JSON object as a native Python object.
6
- TeamsAPI: Wrappers the Cisco Spark Teams-API and exposes the API calls as
7
- Python method calls that return native Python objects.
6
+ TeamsAPI: Wraps the Cisco Spark Teams-API and exposes the APIs as native
7
+ Python methods that return native Python objects.
8
8
9
9
"""
10
10
19
19
from builtins import *
20
20
from past .builtins import basestring
21
21
22
- from ciscosparkapi .exceptions import ciscosparkapiException
23
- from ciscosparkapi .utils import generator_container
24
22
from ciscosparkapi .restsession import RestSession
25
23
from ciscosparkapi .sparkdata import SparkData
24
+ from ciscosparkapi .utils import (
25
+ check_type ,
26
+ dict_from_items_with_values ,
27
+ generator_container ,
28
+ )
26
29
27
30
28
31
__author__ = "Chris Lunsford"
@@ -35,10 +38,10 @@ class Team(SparkData):
35
38
"""Model a Spark 'team' JSON object as a native Python object."""
36
39
37
40
def __init__ (self , json ):
38
- """Init a new Team data object from a JSON dictionary or string.
41
+ """Initialize a new Team data object from a dictionary or JSON string.
39
42
40
43
Args:
41
- json(dict, basestring): Input JSON object.
44
+ json(dict, basestring): Input dictionary or JSON object.
42
45
43
46
Raises:
44
47
TypeError: If the input object is not a dictionary or string.
@@ -48,47 +51,57 @@ def __init__(self, json):
48
51
49
52
@property
50
53
def id (self ):
51
- return self ._json ['id' ]
54
+ """The team's unique ID."""
55
+ return self ._json .get ('id' )
52
56
53
57
@property
54
58
def name (self ):
55
- return self ._json ['name' ]
59
+ """A user-friendly name for the team."""
60
+ return self ._json .get ('name' )
56
61
57
62
@property
58
63
def created (self ):
59
- return self ._json ['created' ]
64
+ """The date and time the team was created."""
65
+ return self ._json .get ('created' )
66
+
67
+ @property
68
+ def creatorId (self ):
69
+ """The ID of the person who created the team."""
70
+ return self ._json .get ('creatorId' )
60
71
61
72
62
73
class TeamsAPI (object ):
63
74
"""Cisco Spark Teams-API wrapper class.
64
75
65
- Wrappers the Cisco Spark Teams-API and exposes the API calls as Python
66
- method calls that return native Python objects.
76
+ Wraps the Cisco Spark Teams-API and exposes the APIs as native Python
77
+ methods that return native Python objects.
67
78
68
79
"""
69
80
70
81
def __init__ (self , session ):
71
- """Init a new TeamsAPI object with the provided RestSession.
82
+ """Initialize a new TeamsAPI object with the provided RestSession.
72
83
73
84
Args:
74
85
session(RestSession): The RESTful session object to be used for
75
86
API calls to the Cisco Spark service.
76
87
77
88
Raises:
78
- AssertionError : If the parameter types are incorrect.
89
+ TypeError : If the parameter types are incorrect.
79
90
80
91
"""
81
- assert isinstance (session , RestSession )
92
+ check_type (session , RestSession , may_be_none = False )
93
+
82
94
super (TeamsAPI , self ).__init__ ()
95
+
83
96
self ._session = session
84
97
85
98
@generator_container
86
- def list (self , max = None ):
99
+ def list (self , max = None , ** request_parameters ):
87
100
"""List teams to which the authenticated user belongs.
88
101
89
102
This method supports Cisco Spark's implementation of RFC5988 Web
90
103
Linking to provide pagination support. It returns a generator
91
- container that incrementally yield all teams returned by the
104
+ container that incrementally yields all teams returned by the
92
105
query. The generator will automatically request additional 'pages' of
93
106
responses from Spark as needed until all responses have been returned.
94
107
The container makes the generator safe for reuse. A new API call will
@@ -97,116 +110,130 @@ def list(self, max=None):
97
110
container.
98
111
99
112
Args:
100
- max(int): Limits the maximum number of teams returned from the
101
- Spark service per request.
113
+ max(int): Limit the maximum number of items returned from the Spark
114
+ service per request.
115
+ **request_parameters: Additional request parameters (provides
116
+ support for parameters that may be added in the future).
102
117
103
118
Returns:
104
- GeneratorContainer: When iterated, the GeneratorContainer, yields
105
- the teams returned by the Cisco Spark query.
119
+ GeneratorContainer: A GeneratorContainer which, when iterated,
120
+ yields the teams returned by the Cisco Spark query.
106
121
107
122
Raises:
108
- AssertionError : If the parameter types are incorrect.
123
+ TypeError : If the parameter types are incorrect.
109
124
SparkApiError: If the Cisco Spark cloud returns an error.
110
125
111
126
"""
112
- # Process args
113
- assert max is None or isinstance (max , int )
114
- params = {}
115
- if max :
116
- params ['max' ] = max
127
+ check_type (max , int )
128
+
129
+ params = dict_from_items_with_values (
130
+ request_parameters ,
131
+ max = max ,
132
+ )
133
+
117
134
# API request - get items
118
135
items = self ._session .get_items ('teams' , params = params )
136
+
119
137
# Yield Team objects created from the returned items JSON objects
120
138
for item in items :
121
139
yield Team (item )
122
140
123
- def create (self , name ):
141
+ def create (self , name , ** request_parameters ):
124
142
"""Create a team.
125
143
126
144
The authenticated user is automatically added as a member of the team.
127
145
128
146
Args:
129
147
name(basestring): A user-friendly name for the team.
148
+ **request_parameters: Additional request parameters (provides
149
+ support for parameters that may be added in the future).
130
150
131
151
Returns:
132
- Team: With the details of the created team.
152
+ Team: A Team object with the details of the created team.
133
153
134
154
Raises:
135
- AssertionError : If the parameter types are incorrect.
155
+ TypeError : If the parameter types are incorrect.
136
156
SparkApiError: If the Cisco Spark cloud returns an error.
137
157
138
158
"""
139
- # Process args
140
- assert isinstance (name , basestring )
141
- post_data = {}
142
- post_data ['name' ] = name
159
+ check_type (name , basestring , may_be_none = False )
160
+
161
+ post_data = dict_from_items_with_values (
162
+ request_parameters ,
163
+ name = name ,
164
+ )
165
+
143
166
# API request
144
- json_obj = self ._session .post ('teams' , json = post_data )
167
+ json_data = self ._session .post ('teams' , json = post_data )
168
+
145
169
# Return a Team object created from the response JSON data
146
- return Team (json_obj )
170
+ return Team (json_data )
147
171
148
172
def get (self , teamId ):
149
173
"""Get the details of a team, by ID.
150
174
151
175
Args:
152
- teamId(basestring): The teamId of the team.
176
+ teamId(basestring): The ID of the team to be retrieved .
153
177
154
178
Returns:
155
- Team: With the details of the requested team.
179
+ Team: A Team object with the details of the requested team.
156
180
157
181
Raises:
158
- AssertionError : If the parameter types are incorrect.
182
+ TypeError : If the parameter types are incorrect.
159
183
SparkApiError: If the Cisco Spark cloud returns an error.
160
184
161
185
"""
162
- # Process args
163
- assert isinstance ( teamId , basestring )
186
+ check_type ( teamId , basestring , may_be_none = False )
187
+
164
188
# API request
165
- json_obj = self ._session .get ('teams/' + teamId )
189
+ json_data = self ._session .get ('teams/' + teamId )
190
+
166
191
# Return a Team object created from the response JSON data
167
- return Team (json_obj )
192
+ return Team (json_data )
168
193
169
- def update (self , teamId , ** update_attributes ):
170
- """Update details for a team.
194
+ def update (self , teamId , name = None , ** request_parameters ):
195
+ """Update details for a team, by ID .
171
196
172
197
Args:
173
- teamId(basestring): The teamId of the team to be updated .
198
+ teamId(basestring): The team ID .
174
199
name(basestring): A user-friendly name for the team.
200
+ **request_parameters: Additional request parameters (provides
201
+ support for parameters that may be added in the future).
175
202
176
203
Returns:
177
- Team: With the updated Spark team details.
204
+ Team: A Team object with the updated Spark team details.
178
205
179
206
Raises:
180
- AssertionError: If the parameter types are incorrect.
181
- ciscosparkapiException: If an update attribute is not provided.
207
+ TypeError: If the parameter types are incorrect.
182
208
SparkApiError: If the Cisco Spark cloud returns an error.
183
209
184
210
"""
185
- # Process args
186
- assert isinstance (teamId , basestring )
187
- # Process update_attributes keyword arguments
188
- if not update_attributes :
189
- error_message = "At least one **update_attributes keyword " \
190
- "argument must be specified."
191
- raise ciscosparkapiException (error_message )
211
+ check_type (teamId , basestring , may_be_none = False )
212
+ check_type (name , basestring )
213
+
214
+ put_data = dict_from_items_with_values (
215
+ request_parameters ,
216
+ name = name ,
217
+ )
218
+
192
219
# API request
193
- json_obj = self ._session .put ('teams/' + teamId ,
194
- json = update_attributes )
220
+ json_data = self ._session .put ('teams/' + teamId , json = put_data )
221
+
195
222
# Return a Team object created from the response JSON data
196
- return Team (json_obj )
223
+ return Team (json_data )
197
224
198
225
def delete (self , teamId ):
199
226
"""Delete a team.
200
227
201
228
Args:
202
- teamId(basestring): The teamId of the team to be deleted.
229
+ teamId(basestring): The ID of the team to be deleted.
203
230
204
231
Raises:
205
- AssertionError : If the parameter types are incorrect.
232
+ TypeError : If the parameter types are incorrect.
206
233
SparkApiError: If the Cisco Spark cloud returns an error.
207
234
208
235
"""
209
- # Process args
210
- assert isinstance ( teamId , basestring )
236
+ check_type ( teamId , basestring , may_be_none = False )
237
+
211
238
# API request
212
239
self ._session .delete ('teams/' + teamId )
0 commit comments