2020from past .builtins import basestring
2121
2222from 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+ )
2428from ciscosparkapi .restsession import RestSession
2529from ciscosparkapi .sparkdata import SparkData
2630
@@ -90,28 +94,31 @@ def teamId(self):
9094class RoomsAPI (object ):
9195 """Cisco Spark Rooms-API wrapper class.
9296
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.
9599
96100 """
97101
98102 def __init__ (self , session ):
99- """Init a new RoomsAPI object with the provided RestSession.
103+ """Initialize a new RoomsAPI object with the provided RestSession.
100104
101105 Args:
102106 session(RestSession): The RESTful session object to be used for
103107 API calls to the Cisco Spark service.
104108
105109 Raises:
106- AssertionError : If the parameter types are incorrect.
110+ TypeError : If the parameter types are incorrect.
107111
108112 """
109- assert isinstance (session , RestSession )
113+ check_type (session , RestSession , may_be_none = False )
114+
110115 super (RoomsAPI , self ).__init__ ()
116+
111117 self ._session = session
112118
113119 @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 ):
115122 """List rooms.
116123
117124 By default, lists rooms to which the authenticated user belongs.
@@ -127,38 +134,49 @@ def list(self, max=None, **query_params):
127134 container.
128135
129136 Args:
130- max(int): Limits the maximum number of rooms returned from the
131- Spark service per request.
132137 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).
137149
138150 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.
141153
142154 Raises:
143- AssertionError : If the parameter types are incorrect.
155+ TypeError : If the parameter types are incorrect.
144156 SparkApiError: If the Cisco Spark cloud returns an error.
145157
146158 """
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+
155172 # API request - get items
156173 items = self ._session .get_items ('rooms' , params = params )
174+
157175 # Yield Room objects created from the returned items JSON objects
158176 for item in items :
159177 yield Room (item )
160178
161- def create (self , title , teamId = None ):
179+ def create (self , title , teamId = None , ** request_parameters ):
162180 """Create a room.
163181
164182 The authenticated user is automatically added as a member of the room.
@@ -167,88 +185,97 @@ def create(self, title, teamId=None):
167185 title(basestring): A user-friendly name for the room.
168186 teamId(basestring): The team ID with which this room is
169187 associated.
188+ **request_parameters: Additional request parameters (provides
189+ support for parameters that may be added in the future).
170190
171191 Returns:
172- Room: With the details of the created room.
192+ Room: A Room with the details of the created room.
173193
174194 Raises:
175- AssertionError : If the parameter types are incorrect.
195+ TypeError : If the parameter types are incorrect.
176196 SparkApiError: If the Cisco Spark cloud returns an error.
177197
178198 """
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+
186208 # API request
187- json_obj = self ._session .post ('rooms' , json = post_data )
209+ json_data = self ._session .post ('rooms' , json = post_data )
210+
188211 # Return a Room object created from the response JSON data
189- return Room (json_obj )
212+ return Room (json_data )
190213
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.
193216
194217 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).
196222
197223 Returns:
198- Room: With the details of the requested room.
224+ Room: A Room object with the updated Spark room details .
199225
200226 Raises:
201- AssertionError : If the parameter types are incorrect.
227+ TypeError : If the parameter types are incorrect.
202228 SparkApiError: If the Cisco Spark cloud returns an error.
203229
204230 """
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+
207239 # API request
208- json_obj = self ._session .get ('rooms/' + roomId )
240+ json_data = self ._session .put ('rooms/' + roomId , json = put_data )
241+
209242 # Return a Room object created from the response JSON data
210- return Room (json_obj )
243+ return Room (json_data )
211244
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 .
214247
215248 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.
218250
219251 Returns:
220- Room: With the updated Spark room details.
252+ Room: A Room object with the details of the requested room .
221253
222254 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.
225256 SparkApiError: If the Cisco Spark cloud returns an error.
226257
227258 """
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+
235261 # API request
236- json_obj = self ._session .put ('rooms/' + roomId , json = update_attributes )
262+ json_data = self ._session .get ('rooms/' + roomId )
263+
237264 # Return a Room object created from the response JSON data
238- return Room (json_obj )
265+ return Room (json_data )
239266
240267 def delete (self , roomId ):
241268 """Delete a room.
242269
243270 Args:
244- roomId(basestring): The roomId of the room to be deleted.
271+ roomId(basestring): The ID of the room to be deleted.
245272
246273 Raises:
247- AssertionError : If the parameter types are incorrect.
274+ TypeError : If the parameter types are incorrect.
248275 SparkApiError: If the Cisco Spark cloud returns an error.
249276
250277 """
251- # Process args
252- assert isinstance ( roomId , basestring )
278+ check_type ( roomId , basestring , may_be_none = False )
279+
253280 # API request
254281 self ._session .delete ('rooms/' + roomId )
0 commit comments