1
1
# -*- coding: utf-8 -*-
2
- """Cisco Spark Roles API wrapper.
2
+ """Cisco Spark Roles- API wrapper.
3
3
4
4
Classes:
5
5
Role: Models a Spark Role JSON object as a native Python object.
6
- RolesAPI: Wraps the Cisco Spark Roles API and exposes the
7
- API calls as Python method calls that return native Python objects.
6
+ RolesAPI: Wraps the Cisco Spark Roles- API and exposes the APIs as native
7
+ 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 Role(SparkData):
34
38
"""Model a Spark Role JSON object as a native Python object."""
35
39
36
40
def __init__ (self , json ):
37
- """Init a new Role data object from a dict or JSON string.
41
+ """Initialize a new Role 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.
@@ -57,31 +61,33 @@ def name(self):
57
61
58
62
59
63
class RolesAPI (object ):
60
- """Cisco Spark Roles API wrapper.
64
+ """Cisco Spark Roles- API wrapper.
61
65
62
- Wraps the Cisco Spark Roles API and exposes the API calls as Python
63
- method calls that return native Python objects.
66
+ Wraps the Cisco Spark Roles- API and exposes the APIs as native Python
67
+ methods that return native Python objects.
64
68
65
69
"""
66
70
67
71
def __init__ (self , session ):
68
- """Init a new RolesAPI object with the provided RestSession.
72
+ """Initialize a new RolesAPI object with the provided RestSession.
69
73
70
74
Args:
71
75
session(RestSession): The RESTful session object to be used for
72
76
API calls to the Cisco Spark service.
73
77
74
78
Raises:
75
- AssertionError : If the parameter types are incorrect.
79
+ TypeError : If the parameter types are incorrect.
76
80
77
81
"""
78
- assert isinstance (session , RestSession )
82
+ check_type (session , RestSession , may_be_none = False )
83
+
79
84
super (RolesAPI , self ).__init__ ()
85
+
80
86
self ._session = session
81
87
82
88
@generator_container
83
- def list (self , max = None ):
84
- """List Roles .
89
+ def list (self , max = None , ** request_parameters ):
90
+ """List all roles .
85
91
86
92
This method supports Cisco Spark's implementation of RFC5988 Web
87
93
Linking to provide pagination support. It returns a generator
@@ -94,47 +100,52 @@ def list(self, max=None):
94
100
container.
95
101
96
102
Args:
97
- max(int): Limits the maximum number of entries returned from the
98
- Spark service per request (page size; requesting additional
99
- pages is handled automatically).
103
+ max(int): Limit the maximum number of items returned from the Spark
104
+ service per request.
105
+ **request_parameters: Additional request parameters (provides
106
+ support for parameters that may be added in the future).
100
107
101
108
Returns:
102
- GeneratorContainer: When iterated, the GeneratorContainer, yields
103
- the objects returned from the Cisco Spark query.
109
+ GeneratorContainer: A GeneratorContainer which, when iterated,
110
+ yields the roles returned by the Cisco Spark query.
104
111
105
112
Raises:
106
- AssertionError : If the parameter types are incorrect.
113
+ TypeError : If the parameter types are incorrect.
107
114
SparkApiError: If the Cisco Spark cloud returns an error.
108
115
109
116
"""
110
- # Process args
111
- assert max is None or isinstance (max , int )
112
- params = {}
113
- if max :
114
- params ['max' ] = max
117
+ check_type (max , int )
118
+
119
+ params = dict_from_items_with_values (
120
+ request_parameters ,
121
+ max = max ,
122
+ )
123
+
115
124
# API request - get items
116
125
items = self ._session .get_items ('roles' , params = params )
126
+
117
127
# Yield Role objects created from the returned JSON objects
118
128
for item in items :
119
129
yield Role (item )
120
130
121
131
def get (self , roleId ):
122
- """Get the details of a Role, by id .
132
+ """Get the details of a Role, by ID .
123
133
124
134
Args:
125
- roleId(basestring): The id of the Role.
135
+ roleId(basestring): The ID of the Role to be retrieved .
126
136
127
137
Returns:
128
- Role: With the details of the requested Role.
138
+ Role: A Role object with the details of the requested Role.
129
139
130
140
Raises:
131
- AssertionError : If the parameter types are incorrect.
141
+ TypeError : If the parameter types are incorrect.
132
142
SparkApiError: If the Cisco Spark cloud returns an error.
133
143
134
144
"""
135
- # Process args
136
- assert isinstance ( roleId , basestring )
145
+ check_type ( roleId , basestring , may_be_none = False )
146
+
137
147
# API request
138
- json_obj = self ._session .get ('roles/' + roleId )
148
+ json_data = self ._session .get ('roles/' + roleId )
149
+
139
150
# Return a Role object created from the returned JSON object
140
- return Role (json_obj )
151
+ return Role (json_data )
0 commit comments