11# -*- coding: utf-8 -*-
2- """Cisco Spark Roles API wrapper.
2+ """Cisco Spark Roles- API wrapper.
33
44Classes:
55 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.
88
99"""
1010
1919from builtins import *
2020from past .builtins import basestring
2121
22- from ciscosparkapi .utils import generator_container
2322from ciscosparkapi .restsession import RestSession
2423from 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 Role(SparkData):
3438 """Model a Spark Role JSON object as a native Python object."""
3539
3640 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.
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.
@@ -57,31 +61,33 @@ def name(self):
5761
5862
5963class RolesAPI (object ):
60- """Cisco Spark Roles API wrapper.
64+ """Cisco Spark Roles- API wrapper.
6165
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.
6468
6569 """
6670
6771 def __init__ (self , session ):
68- """Init a new RolesAPI object with the provided RestSession.
72+ """Initialize a new RolesAPI object with the provided RestSession.
6973
7074 Args:
7175 session(RestSession): The RESTful session object to be used for
7276 API calls to the Cisco Spark service.
7377
7478 Raises:
75- AssertionError : If the parameter types are incorrect.
79+ TypeError : If the parameter types are incorrect.
7680
7781 """
78- assert isinstance (session , RestSession )
82+ check_type (session , RestSession , may_be_none = False )
83+
7984 super (RolesAPI , self ).__init__ ()
85+
8086 self ._session = session
8187
8288 @generator_container
83- def list (self , max = None ):
84- """List Roles .
89+ def list (self , max = None , ** request_parameters ):
90+ """List all roles .
8591
8692 This method supports Cisco Spark's implementation of RFC5988 Web
8793 Linking to provide pagination support. It returns a generator
@@ -94,47 +100,52 @@ def list(self, max=None):
94100 container.
95101
96102 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).
100107
101108 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.
104111
105112 Raises:
106- AssertionError : If the parameter types are incorrect.
113+ TypeError : If the parameter types are incorrect.
107114 SparkApiError: If the Cisco Spark cloud returns an error.
108115
109116 """
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+
115124 # API request - get items
116125 items = self ._session .get_items ('roles' , params = params )
126+
117127 # Yield Role objects created from the returned JSON objects
118128 for item in items :
119129 yield Role (item )
120130
121131 def get (self , roleId ):
122- """Get the details of a Role, by id .
132+ """Get the details of a Role, by ID .
123133
124134 Args:
125- roleId(basestring): The id of the Role.
135+ roleId(basestring): The ID of the Role to be retrieved .
126136
127137 Returns:
128- Role: With the details of the requested Role.
138+ Role: A Role object with the details of the requested Role.
129139
130140 Raises:
131- AssertionError : If the parameter types are incorrect.
141+ TypeError : If the parameter types are incorrect.
132142 SparkApiError: If the Cisco Spark cloud returns an error.
133143
134144 """
135- # Process args
136- assert isinstance ( roleId , basestring )
145+ check_type ( roleId , basestring , may_be_none = False )
146+
137147 # API request
138- json_obj = self ._session .get ('roles/' + roleId )
148+ json_data = self ._session .get ('roles/' + roleId )
149+
139150 # Return a Role object created from the returned JSON object
140- return Role (json_obj )
151+ return Role (json_data )
0 commit comments