Skip to content

Commit bff6a86

Browse files
committed
Refactor Organizations
Apply structural changes to the RoomsAPI and ensure all parameters are up-to-date.
1 parent f300825 commit bff6a86

File tree

1 file changed

+43
-31
lines changed

1 file changed

+43
-31
lines changed

ciscosparkapi/api/organizations.py

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# -*- coding: utf-8 -*-
2-
"""Cisco Spark Organizations API wrapper.
2+
"""Cisco Spark Organizations-API wrapper.
33
44
Classes:
55
Organization: Models a Spark Organization JSON object as a native Python
66
object.
7-
OrganizationsAPI: Wraps the Cisco Spark Organizations API and exposes the
8-
API calls as Python method calls that return native Python objects.
7+
OrganizationsAPI: Wraps the Cisco Spark Organizations-API and exposes the
8+
APIs as native Python methods that return native Python objects.
99
1010
"""
1111

@@ -20,9 +20,13 @@
2020
from builtins import *
2121
from past.builtins import basestring
2222

23-
from ciscosparkapi.utils import generator_container
2423
from ciscosparkapi.restsession import RestSession
2524
from ciscosparkapi.sparkdata import SparkData
25+
from ciscosparkapi.utils import (
26+
check_type,
27+
dict_from_items_with_values,
28+
generator_container,
29+
)
2630

2731

2832
__author__ = "Chris Lunsford"
@@ -35,10 +39,10 @@ class Organization(SparkData):
3539
"""Model a Spark Organization JSON object as a native Python object."""
3640

3741
def __init__(self, json):
38-
"""Init a new Organization data object from a dict or JSON string.
42+
"""Init a Organization data object from a dictionary or JSON string.
3943
4044
Args:
41-
json(dict, basestring): Input JSON object.
45+
json(dict, basestring): Input dictionary or JSON string.
4246
4347
Raises:
4448
TypeError: If the input object is not a dictionary or string.
@@ -58,15 +62,15 @@ def displayName(self):
5862

5963
@property
6064
def created(self):
61-
"""The date and time the Organization was created."""
65+
"""Creation date and time in ISO8601 format."""
6266
return self._json.get('created')
6367

6468

6569
class OrganizationsAPI(object):
66-
"""Cisco Spark Organizations API wrapper.
70+
"""Cisco Spark Organizations-API wrapper.
6771
68-
Wraps the Cisco Spark Organizations API and exposes the API calls as Python
69-
method calls that return native Python objects.
72+
Wraps the Cisco Spark Organizations-API and exposes the APIs as native
73+
Python methods that return native Python objects.
7074
7175
"""
7276

@@ -78,15 +82,17 @@ def __init__(self, session):
7882
API calls to the Cisco Spark service.
7983
8084
Raises:
81-
AssertionError: If the parameter types are incorrect.
85+
TypeError: If the parameter types are incorrect.
8286
8387
"""
84-
assert isinstance(session, RestSession)
88+
check_type(session, RestSession, may_be_none=False)
89+
8590
super(OrganizationsAPI, self).__init__()
91+
8692
self._session = session
8793

8894
@generator_container
89-
def list(self, max=None):
95+
def list(self, max=None, **request_parameters):
9096
"""List Organizations.
9197
9298
This method supports Cisco Spark's implementation of RFC5988 Web
@@ -100,26 +106,30 @@ def list(self, max=None):
100106
container.
101107
102108
Args:
103-
max(int): Limits the maximum number of entries returned from the
104-
Spark service per request (page size; requesting additional
105-
pages is handled automatically).
109+
max(int): Limit the maximum number of items returned from the Spark
110+
service per request.
111+
**request_parameters: Additional request parameters (provides
112+
support for parameters that may be added in the future).
106113
107114
Returns:
108-
GeneratorContainer: When iterated, the GeneratorContainer, yields
109-
the objects returned from the Cisco Spark query.
115+
GeneratorContainer: A GeneratorContainer which, when iterated,
116+
yields the organizations returned by the Cisco Spark query.
110117
111118
Raises:
112-
AssertionError: If the parameter types are incorrect.
119+
TypeError: If the parameter types are incorrect.
113120
SparkApiError: If the Cisco Spark cloud returns an error.
114121
115122
"""
116-
# Process args
117-
assert max is None or isinstance(max, int)
118-
params = {}
119-
if max:
120-
params['max'] = max
123+
check_type(max, int)
124+
125+
params = dict_from_items_with_values(
126+
request_parameters,
127+
max=max,
128+
)
129+
121130
# API request - get items
122131
items = self._session.get_items('organizations', params=params)
132+
123133
# Yield Organization objects created from the returned JSON objects
124134
for item in items:
125135
yield Organization(item)
@@ -128,19 +138,21 @@ def get(self, orgId):
128138
"""Get the details of an Organization, by id.
129139
130140
Args:
131-
orgId(basestring): The id of the Organization.
141+
orgId(basestring): The ID of the Organization to be retrieved.
132142
133143
Returns:
134-
Organization: With the details of the requested Organization.
144+
Organization: An Organization object with the details of the
145+
requested organization.
135146
136147
Raises:
137-
AssertionError: If the parameter types are incorrect.
148+
TypeError: If the parameter types are incorrect.
138149
SparkApiError: If the Cisco Spark cloud returns an error.
139150
140151
"""
141-
# Process args
142-
assert isinstance(orgId, basestring)
152+
check_type(orgId, basestring, may_be_none=False)
153+
143154
# API request
144-
json_obj = self._session.get('organizations/' + orgId)
155+
json_data = self._session.get('organizations/' + orgId)
156+
145157
# Return a Organization object created from the returned JSON object
146-
return Organization(json_obj)
158+
return Organization(json_data)

0 commit comments

Comments
 (0)