Skip to content

Commit 3f79fcb

Browse files
Version 3.3.1
## Bug Fixed - Handling Exception for NoAPIKey and NoSecretKey - Fixed some bugs and standardised SDK
1 parent f2a87ae commit 3f79fcb

File tree

6 files changed

+28
-371
lines changed

6 files changed

+28
-371
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# LoginRadius Python SDK Change Log
22

3+
# Version 3.3.1
4+
## Bug Fixed
5+
- Handling Exception for NoAPIKey and NoSecretKey
6+
- Fixed some bugs and standardised SDK
7+
38
# Version 3.3.0
49
## Enhancements
510
- Enabled Support for gzip compression

demo/LoginRadius/Exceptions.py

Lines changed: 8 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -67,165 +67,22 @@ class NoAPISecret(LoginRadiusExceptions):
6767
Raised on construction of the LoginRadius object,
6868
if no API_SECRET has been set for the class.
6969
"""
70-
71-
def __init__(self, version):
72-
self.version = str(version)
73-
70+
def __init__(self):
71+
pass
72+
7473
def __str__(self):
7574
return "No API_SECRET set. Please initialize a API_SECRET first.\n" \
7675
+ "ie. LoginRadius.API_SECRET = \"Really_Secret_Key\""
7776

7877
class NoAPIKey(LoginRadiusExceptions):
78+
7979
"""
8080
Raised on construction of the LoginRadius object,
8181
if no API_KEY has been set for the class.
8282
"""
83-
84-
def __init__(self, version):
85-
self.version = str(version)
86-
87-
def __str__(self):
88-
return "No API_KEY set. Please initialize a APP_KEY first.\n" \
89-
+ "ie. LoginRadius.API_Key = \"Really_Application_Key\""
90-
91-
class MissingJsonResponseParameter(LoginRadiusExceptions):
92-
"""
93-
Raised if construction of namedtuple would fail
94-
because missing expected response from LoginRadius API.
95-
"""
96-
97-
def __init__(self, missing_parameter, raw=None):
98-
self.missing_parameter = missing_parameter
99-
self.raw = raw
100-
101-
def __str__(self):
102-
exception_string = "Expected parameter from JSON response does not exist." + \
103-
" Expected: " + self.missing_parameter + " but was not in" + \
104-
" the dictionary."
105-
if self.raw:
106-
exception_string += " Instead, we got: " + str(self.raw)
107-
return exception_string
108-
109-
class TokenExpired(LoginRadiusExceptions):
110-
"""
111-
Raised if the request cannot be completed because the access token has expired.
112-
"""
113-
114-
def __init__(self, time):
115-
self.time = time
116-
117-
def __str__(self):
118-
return "The request cannot be completed because the token has expired. " + \
119-
"The token expired on: " + self.time
120-
121-
class FeatureNotSupported(LoginRadiusExceptions):
122-
"""
123-
Raised if the request cannot be completed because your account/API access does not include this.
124-
"""
125-
126-
def __init__(self):
127-
pass
128-
129-
def __str__(self):
130-
return "Your LoginRadius site doesn't have permission to access this endpoint, please contact " + \
131-
"LoginRadius support if you need more information."
132-
133-
class UnknownJsonError(LoginRadiusExceptions):
134-
"""
135-
Raised if cannot determine error number from Json
136-
"""
137-
138-
def __init__(self, result):
139-
self.result = result
140-
141-
def __str__(self):
142-
return str(self.result)
143-
144-
class APIKeyInvalid(LoginRadiusExceptions):
145-
"""
146-
Raised if you entered your API wrong, or not at all.
147-
"""
148-
14983
def __init__(self):
15084
pass
151-
152-
def __str__(self):
153-
return "The LoginRadius API Key is not valid, please double check your account."
154-
155-
class APISecretInvalid(LoginRadiusExceptions):
156-
"""
157-
Raised if you your API Secret is invalid.
158-
"""
159-
160-
def __init__(self):
161-
pass
162-
163-
def __str__(self):
164-
return "The LoginRadius API Secret is not valid, please double check your account."
165-
166-
class InvalidRequestToken(LoginRadiusExceptions):
167-
"""
168-
Raised if you your request token is invalid from the POST request.
169-
"""
170-
171-
def __init__(self):
172-
pass
173-
174-
def __str__(self):
175-
return "The LoginRadius Request Token is invalid, please verify the authentication response."
176-
177-
class RequestTokenExpired(LoginRadiusExceptions):
178-
"""
179-
Raised if you your request token has expired from the POST request.
180-
"""
181-
182-
def __init__(self):
183-
pass
184-
185-
def __str__(self):
186-
return "The LoginRadius Request Token has expired, please verify the authentication response."
187-
188-
class InvalidAccessToken(LoginRadiusExceptions):
189-
"""
190-
Raised if you access token is invalid.
191-
"""
192-
193-
def __init__(self):
194-
pass
195-
196-
def __str__(self):
197-
return "The LoginRadius Access Token has expired, please get a new token from the LoginRadius API."
198-
199-
class ParameterMissing(LoginRadiusExceptions):
200-
"""
201-
Raised if a parameter in the GET or POST request is missing.
202-
"""
203-
204-
def __init__(self):
205-
pass
206-
207-
def __str__(self):
208-
return "A parameter is missing in the request, please check all parameters in the API call."
209-
210-
class ParameterNotFormatted(LoginRadiusExceptions):
211-
"""
212-
Raised if a parameter in the GET or POST request is not formatted properly for the provider.
213-
"""
214-
215-
def __init__(self):
216-
pass
217-
218-
def __str__(self):
219-
return "A parameter is not formatted well in the request, please check all the parameters in the API call."
220-
221-
class EndPointNotSupported(LoginRadiusExceptions):
222-
"""
223-
Raised if a the endpoint is not supported by the provider which correlates to the token.
224-
"""
225-
226-
def __init__(self):
227-
pass
228-
229-
def __str__(self):
230-
return "The requested endpoint is not supported by the current ID provider, " + \
231-
"please check the API support page at http://www.loginradius.com/datapoints"
85+
86+
def __str__(self):
87+
return "No API_KEY set. Please initialize a APP_KEY first.\n" \
88+
+ "ie. LoginRadius.API_Key = \"Really_Application_Key\""

demo/LoginRadius/__init__.py

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# - www.LoginRadius.com #
1414
#################################################
1515
# This file is part of the LoginRadius SDK #
16-
# package. #context
16+
# package. #
1717
#################################################
1818
from LoginRadius.Exceptions import Exceptions
1919
from LoginRadius.sdk.socialLogin import SocialLogin
@@ -530,39 +530,8 @@ def _get_proxy(self):
530530
proxies = {}
531531
return proxies
532532

533-
def _process_result(self, result):
534-
"""Anything we need to parse or look for. In this case, just the ErrorCode"""
535-
if result and "ErrorCode" in result:
536-
return self._process_error(result)
537-
else:
538-
return result
539-
540-
def _process_error(self, result):
541-
"""If there is an errorCode, let's figure out which one and raise the corresponding exception."""
542-
self.error = result
543-
544-
if result['ErrorCode'] == 901:
545-
raise Exceptions.APIKeyInvalid
546-
elif result['ErrorCode'] == 902:
547-
raise Exceptions.APISecretInvalid
548-
elif result['ErrorCode'] == 903:
549-
raise Exceptions.InvalidRequestToken
550-
elif result['ErrorCode'] == 904:
551-
raise Exceptions.RequestTokenExpired
552-
elif result['ErrorCode'] == 905:
553-
raise Exceptions.InvalidAccessToken
554-
elif result['ErrorCode'] == 906:
555-
raise Exceptions.TokenExpired
556-
elif result['ErrorCode'] == 907:
557-
raise Exceptions.ParameterMissing
558-
elif result['ErrorCode'] == 908:
559-
raise Exceptions.ParameterNotFormatted
560-
elif result['ErrorCode'] == 909:
561-
raise Exceptions.FeatureNotSupported
562-
elif result['ErrorCode'] == 910:
563-
raise Exceptions.EndPointNotSupported
564-
else:
565-
return result
533+
def _process_result(self, result):
534+
return result
566535

567536
#
568537
# Public functions

0 commit comments

Comments
 (0)