1+ # -*- coding: utf-8 -*-
12"""Cisco Spark Access-Tokens-API wrapper classes.
23
34Classes:
910"""
1011
1112
12- from __future__ import unicode_literals
1313from future import standard_library
1414standard_library .install_aliases ()
15- from past .builtins import basestring
1615from builtins import object
16+ from six import string_types
1717
1818import urllib .parse
1919
2020import requests
2121
22- from ciscosparkapi .helper import utf8 , ERC , validate_base_url , \
22+ from ciscosparkapi .helper import ERC , validate_base_url , \
2323 check_response_code , extract_and_parse_json
2424from ciscosparkapi .sparkdata import SparkData
2525
2626
27- API_ENDPOINT = u "access_token"
27+ API_ENDPOINT = "access_token"
2828
2929
3030class AccessToken (SparkData ):
@@ -34,7 +34,7 @@ def __init__(self, json):
3434 """Init a new AccessToken data object from a JSON dictionary or string.
3535
3636 Args:
37- json(dict, unicode, str ): Input JSON object.
37+ json(dict, string_types ): Input JSON object.
3838
3939 Raises:
4040 TypeError: If the input object is not a dictionary or string.
@@ -45,22 +45,22 @@ def __init__(self, json):
4545 @property
4646 def access_token (self ):
4747 """Cisco Spark access_token."""
48- return self ._json .get (u 'access_token' )
48+ return self ._json .get ('access_token' )
4949
5050 @property
5151 def expires_in (self ):
5252 """Access token expires_in number of seconds."""
53- return self ._json .get (u 'expires_in' )
53+ return self ._json .get ('expires_in' )
5454
5555 @property
5656 def refresh_token (self ):
5757 """refresh_token used to request a new/refreshed access_token."""
58- return self ._json .get (u 'refresh_token' )
58+ return self ._json .get ('refresh_token' )
5959
6060 @property
6161 def refresh_token_expires_in (self ):
6262 """refresh_token_expires_in number of seconds."""
63- return self ._json .get (u 'refresh_token_expires_in' )
63+ return self ._json .get ('refresh_token_expires_in' )
6464
6565
6666class AccessTokensAPI (object ):
@@ -75,21 +75,21 @@ def __init__(self, base_url, timeout=None):
7575 """Init a new AccessTokensAPI object with the provided RestSession.
7676
7777 Args:
78- base_url(unicode, str ): The base URL the API endpoints.
78+ base_url(string_types ): The base URL the API endpoints.
7979 timeout(int): Timeout in seconds for the API requests.
8080
8181 Raises:
8282 AssertionError: If the parameter types are incorrect.
8383
8484 """
85- assert isinstance (base_url , basestring )
85+ assert isinstance (base_url , string_types )
8686 assert timeout is None or isinstance (timeout , int )
8787 super (AccessTokensAPI , self ).__init__ ()
88- self ._base_url = validate_base_url (base_url )
88+ self ._base_url = str ( validate_base_url (base_url ) )
8989 self ._timeout = timeout
9090 self ._endpoint_url = urllib .parse .urljoin (self .base_url , API_ENDPOINT )
9191 self ._request_kwargs = {}
92- self ._request_kwargs [u "timeout" ] = timeout
92+ self ._request_kwargs ["timeout" ] = timeout
9393
9494 @property
9595 def base_url (self ):
@@ -106,13 +106,13 @@ def get(self, client_id, client_secret, code, redirect_uri):
106106 invoke the APIs.
107107
108108 Args:
109- client_id(unicode, str ): Provided when you created your
109+ client_id(string_types ): Provided when you created your
110110 integration.
111- client_secret(unicode, str ): Provided when you created your
111+ client_secret(string_types ): Provided when you created your
112112 integration.
113- code(unicode, str ): The Authorization Code provided by the user
113+ code(string_types ): The Authorization Code provided by the user
114114 OAuth process.
115- redirect_uri(unicode, str ): The redirect URI used in the user OAuth
115+ redirect_uri(string_types ): The redirect URI used in the user OAuth
116116 process.
117117
118118 Returns:
@@ -125,17 +125,17 @@ def get(self, client_id, client_secret, code, redirect_uri):
125125
126126 """
127127 # Process args
128- assert isinstance (client_id , basestring )
129- assert isinstance (client_secret , basestring )
130- assert isinstance (code , basestring )
131- assert isinstance (redirect_uri , basestring )
128+ assert isinstance (client_id , string_types )
129+ assert isinstance (client_secret , string_types )
130+ assert isinstance (code , string_types )
131+ assert isinstance (redirect_uri , string_types )
132132 # Build request parameters
133133 data = {}
134- data [u "grant_type" ] = u "authorization_code"
135- data [u "client_id" ] = utf8 ( client_id )
136- data [u "client_secret" ] = utf8 ( client_secret )
137- data [u "code" ] = utf8 ( code )
138- data [u "redirect_uri" ] = utf8 ( redirect_uri )
134+ data ["grant_type" ] = "authorization_code"
135+ data ["client_id" ] = client_id
136+ data ["client_secret" ] = client_secret
137+ data ["code" ] = code
138+ data ["redirect_uri" ] = redirect_uri
139139 # API request
140140 response = requests .post (self ._endpoint_url , data = data ,
141141 ** self ._request_kwargs )
@@ -148,11 +148,11 @@ def refresh(self, client_id, client_secret, refresh_token):
148148 """Return a refreshed Access Token via the provided refresh_token.
149149
150150 Args:
151- client_id(unicode, str ): Provided when you created your
151+ client_id(string_types ): Provided when you created your
152152 integration.
153- client_secret(unicode, str ): Provided when you created your
153+ client_secret(string_types ): Provided when you created your
154154 integration.
155- refresh_token(unicode, str ): Provided when you requested the Access
155+ refresh_token(string_types ): Provided when you requested the Access
156156 Token.
157157
158158 Returns:
@@ -165,15 +165,15 @@ def refresh(self, client_id, client_secret, refresh_token):
165165
166166 """
167167 # Process args
168- assert isinstance (client_id , basestring )
169- assert isinstance (client_secret , basestring )
170- assert isinstance (refresh_token , basestring )
168+ assert isinstance (client_id , string_types )
169+ assert isinstance (client_secret , string_types )
170+ assert isinstance (refresh_token , string_types )
171171 # Build request parameters
172172 data = {}
173- data [u "grant_type" ] = u "refresh_token"
174- data [u "client_id" ] = utf8 ( client_id )
175- data [u "client_secret" ] = utf8 ( client_secret )
176- data [u "refresh_token" ] = utf8 ( refresh_token )
173+ data ["grant_type" ] = "refresh_token"
174+ data ["client_id" ] = client_id
175+ data ["client_secret" ] = client_secret
176+ data ["refresh_token" ] = refresh_token
177177 # API request
178178 response = requests .post (self ._endpoint_url , data = data ,
179179 ** self ._request_kwargs )
0 commit comments