1
1
# -*- coding: utf-8 -*-
2
- """Cisco Spark Organizations API wrapper.
2
+ """Cisco Spark Organizations- API wrapper.
3
3
4
4
Classes:
5
5
Organization: Models a Spark Organization JSON object as a native Python
6
6
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.
9
9
10
10
"""
11
11
20
20
from builtins import *
21
21
from past .builtins import basestring
22
22
23
- from ciscosparkapi .utils import generator_container
24
23
from ciscosparkapi .restsession import RestSession
25
24
from ciscosparkapi .sparkdata import SparkData
25
+ from ciscosparkapi .utils import (
26
+ check_type ,
27
+ dict_from_items_with_values ,
28
+ generator_container ,
29
+ )
26
30
27
31
28
32
__author__ = "Chris Lunsford"
@@ -35,10 +39,10 @@ class Organization(SparkData):
35
39
"""Model a Spark Organization JSON object as a native Python object."""
36
40
37
41
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.
39
43
40
44
Args:
41
- json(dict, basestring): Input JSON object .
45
+ json(dict, basestring): Input dictionary or JSON string .
42
46
43
47
Raises:
44
48
TypeError: If the input object is not a dictionary or string.
@@ -58,15 +62,15 @@ def displayName(self):
58
62
59
63
@property
60
64
def created (self ):
61
- """The date and time the Organization was created ."""
65
+ """Creation date and time in ISO8601 format ."""
62
66
return self ._json .get ('created' )
63
67
64
68
65
69
class OrganizationsAPI (object ):
66
- """Cisco Spark Organizations API wrapper.
70
+ """Cisco Spark Organizations- API wrapper.
67
71
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.
70
74
71
75
"""
72
76
@@ -78,15 +82,17 @@ def __init__(self, session):
78
82
API calls to the Cisco Spark service.
79
83
80
84
Raises:
81
- AssertionError : If the parameter types are incorrect.
85
+ TypeError : If the parameter types are incorrect.
82
86
83
87
"""
84
- assert isinstance (session , RestSession )
88
+ check_type (session , RestSession , may_be_none = False )
89
+
85
90
super (OrganizationsAPI , self ).__init__ ()
91
+
86
92
self ._session = session
87
93
88
94
@generator_container
89
- def list (self , max = None ):
95
+ def list (self , max = None , ** request_parameters ):
90
96
"""List Organizations.
91
97
92
98
This method supports Cisco Spark's implementation of RFC5988 Web
@@ -100,26 +106,30 @@ def list(self, max=None):
100
106
container.
101
107
102
108
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).
106
113
107
114
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.
110
117
111
118
Raises:
112
- AssertionError : If the parameter types are incorrect.
119
+ TypeError : If the parameter types are incorrect.
113
120
SparkApiError: If the Cisco Spark cloud returns an error.
114
121
115
122
"""
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
+
121
130
# API request - get items
122
131
items = self ._session .get_items ('organizations' , params = params )
132
+
123
133
# Yield Organization objects created from the returned JSON objects
124
134
for item in items :
125
135
yield Organization (item )
@@ -128,19 +138,21 @@ def get(self, orgId):
128
138
"""Get the details of an Organization, by id.
129
139
130
140
Args:
131
- orgId(basestring): The id of the Organization.
141
+ orgId(basestring): The ID of the Organization to be retrieved .
132
142
133
143
Returns:
134
- Organization: With the details of the requested Organization.
144
+ Organization: An Organization object with the details of the
145
+ requested organization.
135
146
136
147
Raises:
137
- AssertionError : If the parameter types are incorrect.
148
+ TypeError : If the parameter types are incorrect.
138
149
SparkApiError: If the Cisco Spark cloud returns an error.
139
150
140
151
"""
141
- # Process args
142
- assert isinstance ( orgId , basestring )
152
+ check_type ( orgId , basestring , may_be_none = False )
153
+
143
154
# API request
144
- json_obj = self ._session .get ('organizations/' + orgId )
155
+ json_data = self ._session .get ('organizations/' + orgId )
156
+
145
157
# Return a Organization object created from the returned JSON object
146
- return Organization (json_obj )
158
+ return Organization (json_data )
0 commit comments