Skip to content

Commit b4cf840

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

File tree

1 file changed

+50
-40
lines changed

1 file changed

+50
-40
lines changed

ciscosparkapi/api/licenses.py

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# -*- coding: utf-8 -*-
2-
"""Cisco Spark Licenses API wrapper.
2+
"""Cisco Spark Licenses-API wrapper.
33
44
Classes:
55
License: Models a Spark License JSON object as a native Python object.
6-
LicensesAPI: Wraps the Cisco Spark Licenses API and exposes the
7-
API calls as Python method calls that return native Python objects.
6+
LicensesAPI: Wraps the Cisco Spark Licenses-API and exposes the APIs as
7+
native Python methods that return native Python objects.
88
99
"""
1010

@@ -19,9 +19,13 @@
1919
from builtins import *
2020
from past.builtins import basestring
2121

22-
from ciscosparkapi.utils import generator_container
2322
from ciscosparkapi.restsession import RestSession
2423
from ciscosparkapi.sparkdata import SparkData
24+
from ciscosparkapi.utils import (
25+
check_type,
26+
dict_from_items_with_values,
27+
generator_container,
28+
)
2529

2630

2731
__author__ = "Chris Lunsford"
@@ -34,10 +38,10 @@ class License(SparkData):
3438
"""Model a Spark License JSON object as a native Python object."""
3539

3640
def __init__(self, json):
37-
"""Init a new License data object from a dict or JSON string.
41+
"""Initialize a License data object from a dictionary or JSON string.
3842
3943
Args:
40-
json(dict, basestring): Input JSON object.
44+
json(dict, basestring): Input dictionary or JSON string.
4145
4246
Raises:
4347
TypeError: If the input object is not a dictionary or string.
@@ -67,33 +71,36 @@ def consumedUnits(self):
6771

6872

6973
class LicensesAPI(object):
70-
"""Cisco Spark Licenses API wrapper.
74+
"""Cisco Spark Licenses-API wrapper.
7175
72-
Wraps the Cisco Spark Licenses API and exposes the API calls as Python
73-
method calls that return native Python objects.
76+
Wraps the Cisco Spark Licenses-API and exposes the APIs as native Python
77+
methods that return native Python objects.
7478
7579
"""
7680

7781
def __init__(self, session):
78-
"""Init a new LicensesAPI object with the provided RestSession.
82+
"""Initialize a new LicensesAPI object with the provided RestSession.
7983
8084
Args:
8185
session(RestSession): The RESTful session object to be used for
8286
API calls to the Cisco Spark service.
8387
8488
Raises:
85-
AssertionError: If the parameter types are incorrect.
89+
TypeError: If the input object is not a dictionary or string.
8690
8791
"""
88-
assert isinstance(session, RestSession)
92+
check_type(session, RestSession, may_be_none=False)
93+
8994
super(LicensesAPI, self).__init__()
95+
9096
self._session = session
9197

9298
@generator_container
93-
def list(self, orgId=None, max=None):
94-
"""List Licenses.
99+
def list(self, orgId=None, max=None, **request_parameters):
100+
"""List all licenses for a given organization.
95101
96-
Optionally filtered by Organization (orgId parameter).
102+
If no orgId is specified, the default is the organization of the
103+
authenticated user.
97104
98105
This method supports Cisco Spark's implementation of RFC5988 Web
99106
Linking to provide pagination support. It returns a generator
@@ -106,53 +113,56 @@ def list(self, orgId=None, max=None):
106113
container.
107114
108115
Args:
109-
orgId(basestring): Filters the returned licenses to only include
110-
those liceses associated with the specified Organization
111-
(orgId).
112-
max(int): Limits the maximum number of entries returned from the
113-
Spark service per request (page size; requesting additional
114-
pages is handled automatically).
116+
orgId(basestring): Specify the organization, by ID.
117+
max(int): Limit the maximum number of items returned from the Spark
118+
service per request.
119+
**request_parameters: Additional request parameters (provides
120+
support for parameters that may be added in the future).
115121
116122
Returns:
117-
GeneratorContainer: When iterated, the GeneratorContainer, yields
118-
the objects returned from the Cisco Spark query.
123+
GeneratorContainer: A GeneratorContainer which, when iterated,
124+
yields the licenses returned by the Cisco Spark query.
119125
120126
Raises:
121-
AssertionError: If the parameter types are incorrect.
127+
TypeError: If the parameter types are incorrect.
122128
SparkApiError: If the Cisco Spark cloud returns an error.
123129
124130
"""
125-
# Process args
126-
assert orgId is None or isinstance(orgId, basestring)
127-
assert max is None or isinstance(max, int)
128-
params = {}
129-
if orgId:
130-
params['orgId'] = orgId
131-
if max:
132-
params['max'] = max
131+
check_type(orgId, basestring)
132+
check_type(max, int)
133+
134+
params = dict_from_items_with_values(
135+
request_parameters,
136+
orgId=orgId,
137+
max=max,
138+
)
139+
133140
# API request - get items
134141
items = self._session.get_items('licenses', params=params)
142+
135143
# Yield License objects created from the returned JSON objects
136144
for item in items:
137145
yield License(item)
138146

139147
def get(self, licenseId):
140-
"""Get the details of a License, by id.
148+
"""Get the details of a License, by ID.
141149
142150
Args:
143-
licenseId(basestring): The id of the License.
151+
licenseId(basestring): The ID of the License to be retrieved.
144152
145153
Returns:
146-
License: With the details of the requested License.
154+
License: A License object with the details of the requested
155+
License.
147156
148157
Raises:
149-
AssertionError: If the parameter types are incorrect.
158+
TypeError: If the parameter types are incorrect.
150159
SparkApiError: If the Cisco Spark cloud returns an error.
151160
152161
"""
153-
# Process args
154-
assert isinstance(licenseId, basestring)
162+
check_type(licenseId, basestring, may_be_none=False)
163+
155164
# API request
156-
json_obj = self._session.get('licenses/' + licenseId)
165+
json_data = self._session.get('licenses/' + licenseId)
166+
157167
# Return a License object created from the returned JSON object
158-
return License(json_obj)
168+
return License(json_data)

0 commit comments

Comments
 (0)