Skip to content

Commit

Permalink
Version 3.3.1
Browse files Browse the repository at this point in the history
## Bug Fixed
  - Handling Exception for NoAPIKey and NoSecretKey
  - Fixed some bugs and standardised SDK
  • Loading branch information
Agarwal-Sudhanshu committed May 24, 2019
1 parent f2a87ae commit 3f79fcb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 371 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# LoginRadius Python SDK Change Log

# Version 3.3.1
## Bug Fixed
- Handling Exception for NoAPIKey and NoSecretKey
- Fixed some bugs and standardised SDK

# Version 3.3.0
## Enhancements
- Enabled Support for gzip compression
Expand Down
159 changes: 8 additions & 151 deletions demo/LoginRadius/Exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,165 +67,22 @@ class NoAPISecret(LoginRadiusExceptions):
Raised on construction of the LoginRadius object,
if no API_SECRET has been set for the class.
"""

def __init__(self, version):
self.version = str(version)

def __init__(self):
pass

def __str__(self):
return "No API_SECRET set. Please initialize a API_SECRET first.\n" \
+ "ie. LoginRadius.API_SECRET = \"Really_Secret_Key\""

class NoAPIKey(LoginRadiusExceptions):

"""
Raised on construction of the LoginRadius object,
if no API_KEY has been set for the class.
"""

def __init__(self, version):
self.version = str(version)

def __str__(self):
return "No API_KEY set. Please initialize a APP_KEY first.\n" \
+ "ie. LoginRadius.API_Key = \"Really_Application_Key\""

class MissingJsonResponseParameter(LoginRadiusExceptions):
"""
Raised if construction of namedtuple would fail
because missing expected response from LoginRadius API.
"""

def __init__(self, missing_parameter, raw=None):
self.missing_parameter = missing_parameter
self.raw = raw

def __str__(self):
exception_string = "Expected parameter from JSON response does not exist." + \
" Expected: " + self.missing_parameter + " but was not in" + \
" the dictionary."
if self.raw:
exception_string += " Instead, we got: " + str(self.raw)
return exception_string

class TokenExpired(LoginRadiusExceptions):
"""
Raised if the request cannot be completed because the access token has expired.
"""

def __init__(self, time):
self.time = time

def __str__(self):
return "The request cannot be completed because the token has expired. " + \
"The token expired on: " + self.time

class FeatureNotSupported(LoginRadiusExceptions):
"""
Raised if the request cannot be completed because your account/API access does not include this.
"""

def __init__(self):
pass

def __str__(self):
return "Your LoginRadius site doesn't have permission to access this endpoint, please contact " + \
"LoginRadius support if you need more information."

class UnknownJsonError(LoginRadiusExceptions):
"""
Raised if cannot determine error number from Json
"""

def __init__(self, result):
self.result = result

def __str__(self):
return str(self.result)

class APIKeyInvalid(LoginRadiusExceptions):
"""
Raised if you entered your API wrong, or not at all.
"""

def __init__(self):
pass

def __str__(self):
return "The LoginRadius API Key is not valid, please double check your account."

class APISecretInvalid(LoginRadiusExceptions):
"""
Raised if you your API Secret is invalid.
"""

def __init__(self):
pass

def __str__(self):
return "The LoginRadius API Secret is not valid, please double check your account."

class InvalidRequestToken(LoginRadiusExceptions):
"""
Raised if you your request token is invalid from the POST request.
"""

def __init__(self):
pass

def __str__(self):
return "The LoginRadius Request Token is invalid, please verify the authentication response."

class RequestTokenExpired(LoginRadiusExceptions):
"""
Raised if you your request token has expired from the POST request.
"""

def __init__(self):
pass

def __str__(self):
return "The LoginRadius Request Token has expired, please verify the authentication response."

class InvalidAccessToken(LoginRadiusExceptions):
"""
Raised if you access token is invalid.
"""

def __init__(self):
pass

def __str__(self):
return "The LoginRadius Access Token has expired, please get a new token from the LoginRadius API."

class ParameterMissing(LoginRadiusExceptions):
"""
Raised if a parameter in the GET or POST request is missing.
"""

def __init__(self):
pass

def __str__(self):
return "A parameter is missing in the request, please check all parameters in the API call."

class ParameterNotFormatted(LoginRadiusExceptions):
"""
Raised if a parameter in the GET or POST request is not formatted properly for the provider.
"""

def __init__(self):
pass

def __str__(self):
return "A parameter is not formatted well in the request, please check all the parameters in the API call."

class EndPointNotSupported(LoginRadiusExceptions):
"""
Raised if a the endpoint is not supported by the provider which correlates to the token.
"""

def __init__(self):
pass

def __str__(self):
return "The requested endpoint is not supported by the current ID provider, " + \
"please check the API support page at http://www.loginradius.com/datapoints"

def __str__(self):
return "No API_KEY set. Please initialize a APP_KEY first.\n" \
+ "ie. LoginRadius.API_Key = \"Really_Application_Key\""
37 changes: 3 additions & 34 deletions demo/LoginRadius/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# - www.LoginRadius.com #
#################################################
# This file is part of the LoginRadius SDK #
# package. #context
# package. #
#################################################
from LoginRadius.Exceptions import Exceptions
from LoginRadius.sdk.socialLogin import SocialLogin
Expand Down Expand Up @@ -530,39 +530,8 @@ def _get_proxy(self):
proxies = {}
return proxies

def _process_result(self, result):
"""Anything we need to parse or look for. In this case, just the ErrorCode"""
if result and "ErrorCode" in result:
return self._process_error(result)
else:
return result

def _process_error(self, result):
"""If there is an errorCode, let's figure out which one and raise the corresponding exception."""
self.error = result

if result['ErrorCode'] == 901:
raise Exceptions.APIKeyInvalid
elif result['ErrorCode'] == 902:
raise Exceptions.APISecretInvalid
elif result['ErrorCode'] == 903:
raise Exceptions.InvalidRequestToken
elif result['ErrorCode'] == 904:
raise Exceptions.RequestTokenExpired
elif result['ErrorCode'] == 905:
raise Exceptions.InvalidAccessToken
elif result['ErrorCode'] == 906:
raise Exceptions.TokenExpired
elif result['ErrorCode'] == 907:
raise Exceptions.ParameterMissing
elif result['ErrorCode'] == 908:
raise Exceptions.ParameterNotFormatted
elif result['ErrorCode'] == 909:
raise Exceptions.FeatureNotSupported
elif result['ErrorCode'] == 910:
raise Exceptions.EndPointNotSupported
else:
return result
def _process_result(self, result):
return result

#
# Public functions
Expand Down
Loading

0 comments on commit 3f79fcb

Please sign in to comment.