16
16
import os
17
17
18
18
from ciscosparkapi .exceptions import ciscosparkapiException , SparkApiError
19
- from ciscosparkapi .restsession import RestSession
19
+ from ciscosparkapi .restsession import (
20
+ DEFAULT_SINGLE_REQUEST_TIMEOUT ,
21
+ DEFAULT_RATE_LIMIT_TIMEOUT ,
22
+ RestSession ,
23
+ )
20
24
from ciscosparkapi .api .people import Person , PeopleAPI
21
25
from ciscosparkapi .api .rooms import Room , RoomsAPI
22
26
from ciscosparkapi .api .memberships import Membership , MembershipsAPI
45
49
del get_versions
46
50
47
51
52
+ # Package Constants
48
53
DEFAULT_BASE_URL = 'https://api.ciscospark.com/v1/'
49
- DEFAULT_TIMEOUT = 60
50
54
ACCESS_TOKEN_ENVIRONMENT_VARIABLE = 'SPARK_ACCESS_TOKEN'
51
55
52
56
@@ -91,7 +95,9 @@ class CiscoSparkAPI(object):
91
95
"""
92
96
93
97
def __init__ (self , access_token = None , base_url = DEFAULT_BASE_URL ,
94
- timeout = DEFAULT_TIMEOUT ):
98
+ timeout = None ,
99
+ single_request_timeout = DEFAULT_SINGLE_REQUEST_TIMEOUT ,
100
+ rate_limit_timeout = DEFAULT_RATE_LIMIT_TIMEOUT ):
95
101
"""Create a new CiscoSparkAPI object.
96
102
97
103
An access token must be used when interacting with the Cisco Spark API.
@@ -126,25 +132,27 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
126
132
variable.
127
133
128
134
"""
129
- # Process args
130
135
assert access_token is None or isinstance (access_token , basestring )
131
- assert isinstance (base_url , basestring )
132
- assert isinstance (timeout , int )
133
- spark_access_token = os .environ .get (ACCESS_TOKEN_ENVIRONMENT_VARIABLE )
134
- access_token = access_token if access_token else spark_access_token
136
+ env_access_token = os .environ .get (ACCESS_TOKEN_ENVIRONMENT_VARIABLE )
137
+ access_token = access_token if access_token else env_access_token
135
138
if not access_token :
136
139
error_message = "You must provide an Spark access token to " \
137
140
"interact with the Cisco Spark APIs, either via " \
138
141
"a SPARK_ACCESS_TOKEN environment variable " \
139
142
"or via the access_token argument."
140
143
raise ciscosparkapiException (error_message )
141
- session_args = {u'timeout' : timeout }
142
144
143
145
# Create the API session
144
146
# All of the API calls associated with a CiscoSparkAPI object will
145
147
# leverage a single RESTful 'session' connecting to the Cisco Spark
146
148
# cloud.
147
- self ._session = RestSession (access_token , base_url , ** session_args )
149
+ self ._session = RestSession (
150
+ access_token ,
151
+ base_url ,
152
+ timeout = timeout ,
153
+ single_request_timeout = single_request_timeout ,
154
+ rate_limit_timeout = rate_limit_timeout ,
155
+ )
148
156
149
157
# Spark API wrappers
150
158
self .people = PeopleAPI (self ._session )
@@ -170,3 +178,11 @@ def base_url(self):
170
178
@property
171
179
def timeout (self ):
172
180
return self ._session .timeout
181
+
182
+ @property
183
+ def single_request_timeout (self ):
184
+ return self ._session .single_request_timeout
185
+
186
+ @property
187
+ def rate_limit_timeout (self ):
188
+ return self ._session .rate_limit_timeout
0 commit comments