20
20
from past .builtins import basestring
21
21
22
22
from ciscosparkapi .exceptions import ciscosparkapiException
23
- from ciscosparkapi .utils import generator_container
23
+ from ciscosparkapi .utils import (
24
+ check_type ,
25
+ dict_from_items_with_values ,
26
+ generator_container ,
27
+ )
24
28
from ciscosparkapi .restsession import RestSession
25
29
from ciscosparkapi .sparkdata import SparkData
26
30
@@ -90,28 +94,31 @@ def teamId(self):
90
94
class RoomsAPI (object ):
91
95
"""Cisco Spark Rooms-API wrapper class.
92
96
93
- Wrappers the Cisco Spark Rooms-API and exposes the API calls as Python
94
- method calls that return native Python objects.
97
+ Wraps the Cisco Spark Rooms-API and exposes the APIs as native Python
98
+ methods that return native Python objects.
95
99
96
100
"""
97
101
98
102
def __init__ (self , session ):
99
- """Init a new RoomsAPI object with the provided RestSession.
103
+ """Initialize a new RoomsAPI object with the provided RestSession.
100
104
101
105
Args:
102
106
session(RestSession): The RESTful session object to be used for
103
107
API calls to the Cisco Spark service.
104
108
105
109
Raises:
106
- AssertionError : If the parameter types are incorrect.
110
+ TypeError : If the parameter types are incorrect.
107
111
108
112
"""
109
- assert isinstance (session , RestSession )
113
+ check_type (session , RestSession , may_be_none = False )
114
+
110
115
super (RoomsAPI , self ).__init__ ()
116
+
111
117
self ._session = session
112
118
113
119
@generator_container
114
- def list (self , max = None , ** query_params ):
120
+ def list (self , teamId = None , type = None , sortBy = None , max = None ,
121
+ ** request_parameters ):
115
122
"""List rooms.
116
123
117
124
By default, lists rooms to which the authenticated user belongs.
@@ -127,38 +134,49 @@ def list(self, max=None, **query_params):
127
134
container.
128
135
129
136
Args:
130
- max(int): Limits the maximum number of rooms returned from the
131
- Spark service per request.
132
137
teamId(basestring): Limit the rooms to those associated with a
133
- team.
134
- type(basestring):
135
- 'direct': returns all 1-to-1 rooms.
136
- 'group': returns all group rooms.
138
+ team, by ID.
139
+ type(basestring): 'direct' returns all 1-to-1 rooms. `group`
140
+ returns all group rooms. If not specified or values not
141
+ matched, will return all room types.
142
+ sortBy(basestring): Sort results by room ID (`id`), most recent
143
+ activity (`lastactivity`), or most recently created
144
+ (`created`).
145
+ max(int): Limit the maximum number of rooms in the response from
146
+ the Spark service.
147
+ **request_parameters: Additional request parameters (provides
148
+ support for parameters that may be added in the future).
137
149
138
150
Returns:
139
- GeneratorContainer: When iterated, the GeneratorContainer, yields
140
- the rooms returned from the Cisco Spark query.
151
+ GeneratorContainer: A GeneratorContainer which, when iterated,
152
+ yields the rooms returned by the Cisco Spark query.
141
153
142
154
Raises:
143
- AssertionError : If the parameter types are incorrect.
155
+ TypeError : If the parameter types are incorrect.
144
156
SparkApiError: If the Cisco Spark cloud returns an error.
145
157
146
158
"""
147
- # Process args
148
- assert max is None or isinstance (max , int )
149
- params = {}
150
- if max :
151
- params ['max' ] = max
152
- # Process query_param keyword arguments
153
- if query_params :
154
- params .update (query_params )
159
+ check_type (teamId , basestring )
160
+ check_type (type , basestring )
161
+ check_type (sortBy , basestring )
162
+ check_type (max , int )
163
+
164
+ params = dict_from_items_with_values (
165
+ request_parameters ,
166
+ teamId = teamId ,
167
+ type = type ,
168
+ sortBy = sortBy ,
169
+ max = max ,
170
+ )
171
+
155
172
# API request - get items
156
173
items = self ._session .get_items ('rooms' , params = params )
174
+
157
175
# Yield Room objects created from the returned items JSON objects
158
176
for item in items :
159
177
yield Room (item )
160
178
161
- def create (self , title , teamId = None ):
179
+ def create (self , title , teamId = None , ** request_parameters ):
162
180
"""Create a room.
163
181
164
182
The authenticated user is automatically added as a member of the room.
@@ -167,88 +185,97 @@ def create(self, title, teamId=None):
167
185
title(basestring): A user-friendly name for the room.
168
186
teamId(basestring): The team ID with which this room is
169
187
associated.
188
+ **request_parameters: Additional request parameters (provides
189
+ support for parameters that may be added in the future).
170
190
171
191
Returns:
172
- Room: With the details of the created room.
192
+ Room: A Room with the details of the created room.
173
193
174
194
Raises:
175
- AssertionError : If the parameter types are incorrect.
195
+ TypeError : If the parameter types are incorrect.
176
196
SparkApiError: If the Cisco Spark cloud returns an error.
177
197
178
198
"""
179
- # Process args
180
- assert isinstance (title , basestring )
181
- assert teamId is None or isinstance (teamId , basestring )
182
- post_data = {}
183
- post_data ['title' ] = title
184
- if teamId :
185
- post_data ['teamId' ] = teamId
199
+ check_type (title , basestring )
200
+ check_type (teamId , basestring )
201
+
202
+ post_data = dict_from_items_with_values (
203
+ request_parameters ,
204
+ title = title ,
205
+ teamId = teamId ,
206
+ )
207
+
186
208
# API request
187
- json_obj = self ._session .post ('rooms' , json = post_data )
209
+ json_data = self ._session .post ('rooms' , json = post_data )
210
+
188
211
# Return a Room object created from the response JSON data
189
- return Room (json_obj )
212
+ return Room (json_data )
190
213
191
- def get (self , roomId ):
192
- """Get the details of a room, by ID.
214
+ def update (self , roomId , title = None , ** request_parameters ):
215
+ """Update details for a room, by ID.
193
216
194
217
Args:
195
- roomId(basestring): The roomId of the room.
218
+ roomId(basestring): The ID of the room to be updated.
219
+ title(basestring): A user-friendly name for the room.
220
+ **request_parameters: Additional request parameters (provides
221
+ support for parameters that may be added in the future).
196
222
197
223
Returns:
198
- Room: With the details of the requested room.
224
+ Room: A Room object with the updated Spark room details .
199
225
200
226
Raises:
201
- AssertionError : If the parameter types are incorrect.
227
+ TypeError : If the parameter types are incorrect.
202
228
SparkApiError: If the Cisco Spark cloud returns an error.
203
229
204
230
"""
205
- # Process args
206
- assert isinstance (roomId , basestring )
231
+ check_type (roomId , basestring , may_be_none = False )
232
+ check_type (roomId , basestring )
233
+
234
+ put_data = dict_from_items_with_values (
235
+ request_parameters ,
236
+ title = title ,
237
+ )
238
+
207
239
# API request
208
- json_obj = self ._session .get ('rooms/' + roomId )
240
+ json_data = self ._session .put ('rooms/' + roomId , json = put_data )
241
+
209
242
# Return a Room object created from the response JSON data
210
- return Room (json_obj )
243
+ return Room (json_data )
211
244
212
- def update (self , roomId , ** update_attributes ):
213
- """Update details for a room.
245
+ def get (self , roomId ):
246
+ """Get the details of a room, by ID .
214
247
215
248
Args:
216
- roomId(basestring): The roomId of the room to be updated.
217
- title(basestring): A user-friendly name for the room.
249
+ roomId(basestring): The ID of the room to be retrieved.
218
250
219
251
Returns:
220
- Room: With the updated Spark room details.
252
+ Room: A Room object with the details of the requested room .
221
253
222
254
Raises:
223
- AssertionError: If the parameter types are incorrect.
224
- ciscosparkapiException: If an update attribute is not provided.
255
+ TypeError: If the parameter types are incorrect.
225
256
SparkApiError: If the Cisco Spark cloud returns an error.
226
257
227
258
"""
228
- # Process args
229
- assert isinstance (roomId , basestring )
230
- # Process update_attributes keyword arguments
231
- if not update_attributes :
232
- error_message = "At least one **update_attributes keyword " \
233
- "argument must be specified."
234
- raise ciscosparkapiException (error_message )
259
+ check_type (roomId , basestring , may_be_none = False )
260
+
235
261
# API request
236
- json_obj = self ._session .put ('rooms/' + roomId , json = update_attributes )
262
+ json_data = self ._session .get ('rooms/' + roomId )
263
+
237
264
# Return a Room object created from the response JSON data
238
- return Room (json_obj )
265
+ return Room (json_data )
239
266
240
267
def delete (self , roomId ):
241
268
"""Delete a room.
242
269
243
270
Args:
244
- roomId(basestring): The roomId of the room to be deleted.
271
+ roomId(basestring): The ID of the room to be deleted.
245
272
246
273
Raises:
247
- AssertionError : If the parameter types are incorrect.
274
+ TypeError : If the parameter types are incorrect.
248
275
SparkApiError: If the Cisco Spark cloud returns an error.
249
276
250
277
"""
251
- # Process args
252
- assert isinstance ( roomId , basestring )
278
+ check_type ( roomId , basestring , may_be_none = False )
279
+
253
280
# API request
254
281
self ._session .delete ('rooms/' + roomId )
0 commit comments