1
1
# -*- coding: utf-8 -*-
2
- """Cisco Spark Licenses API wrapper.
2
+ """Cisco Spark Licenses- API wrapper.
3
3
4
4
Classes:
5
5
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.
8
8
9
9
"""
10
10
19
19
from builtins import *
20
20
from past .builtins import basestring
21
21
22
- from ciscosparkapi .utils import generator_container
23
22
from ciscosparkapi .restsession import RestSession
24
23
from ciscosparkapi .sparkdata import SparkData
24
+ from ciscosparkapi .utils import (
25
+ check_type ,
26
+ dict_from_items_with_values ,
27
+ generator_container ,
28
+ )
25
29
26
30
27
31
__author__ = "Chris Lunsford"
@@ -34,10 +38,10 @@ class License(SparkData):
34
38
"""Model a Spark License JSON object as a native Python object."""
35
39
36
40
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.
38
42
39
43
Args:
40
- json(dict, basestring): Input JSON object .
44
+ json(dict, basestring): Input dictionary or JSON string .
41
45
42
46
Raises:
43
47
TypeError: If the input object is not a dictionary or string.
@@ -67,33 +71,36 @@ def consumedUnits(self):
67
71
68
72
69
73
class LicensesAPI (object ):
70
- """Cisco Spark Licenses API wrapper.
74
+ """Cisco Spark Licenses- API wrapper.
71
75
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.
74
78
75
79
"""
76
80
77
81
def __init__ (self , session ):
78
- """Init a new LicensesAPI object with the provided RestSession.
82
+ """Initialize a new LicensesAPI object with the provided RestSession.
79
83
80
84
Args:
81
85
session(RestSession): The RESTful session object to be used for
82
86
API calls to the Cisco Spark service.
83
87
84
88
Raises:
85
- AssertionError : If the parameter types are incorrect .
89
+ TypeError : If the input object is not a dictionary or string .
86
90
87
91
"""
88
- assert isinstance (session , RestSession )
92
+ check_type (session , RestSession , may_be_none = False )
93
+
89
94
super (LicensesAPI , self ).__init__ ()
95
+
90
96
self ._session = session
91
97
92
98
@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 .
95
101
96
- Optionally filtered by Organization (orgId parameter).
102
+ If no orgId is specified, the default is the organization of the
103
+ authenticated user.
97
104
98
105
This method supports Cisco Spark's implementation of RFC5988 Web
99
106
Linking to provide pagination support. It returns a generator
@@ -106,53 +113,56 @@ def list(self, orgId=None, max=None):
106
113
container.
107
114
108
115
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).
115
121
116
122
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.
119
125
120
126
Raises:
121
- AssertionError : If the parameter types are incorrect.
127
+ TypeError : If the parameter types are incorrect.
122
128
SparkApiError: If the Cisco Spark cloud returns an error.
123
129
124
130
"""
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
+
133
140
# API request - get items
134
141
items = self ._session .get_items ('licenses' , params = params )
142
+
135
143
# Yield License objects created from the returned JSON objects
136
144
for item in items :
137
145
yield License (item )
138
146
139
147
def get (self , licenseId ):
140
- """Get the details of a License, by id .
148
+ """Get the details of a License, by ID .
141
149
142
150
Args:
143
- licenseId(basestring): The id of the License.
151
+ licenseId(basestring): The ID of the License to be retrieved .
144
152
145
153
Returns:
146
- License: With the details of the requested License.
154
+ License: A License object with the details of the requested
155
+ License.
147
156
148
157
Raises:
149
- AssertionError : If the parameter types are incorrect.
158
+ TypeError : If the parameter types are incorrect.
150
159
SparkApiError: If the Cisco Spark cloud returns an error.
151
160
152
161
"""
153
- # Process args
154
- assert isinstance ( licenseId , basestring )
162
+ check_type ( licenseId , basestring , may_be_none = False )
163
+
155
164
# API request
156
- json_obj = self ._session .get ('licenses/' + licenseId )
165
+ json_data = self ._session .get ('licenses/' + licenseId )
166
+
157
167
# Return a License object created from the returned JSON object
158
- return License (json_obj )
168
+ return License (json_data )
0 commit comments