本文整理汇总了Python中validator.Validator.isAValidSessionRequest方法的典型用法代码示例。如果您正苦于以下问题:Python Validator.isAValidSessionRequest方法的具体用法?Python Validator.isAValidSessionRequest怎么用?Python Validator.isAValidSessionRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类validator.Validator
的用法示例。
在下文中一共展示了Validator.isAValidSessionRequest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from validator import Validator [as 别名]
# 或者: from validator.Validator import isAValidSessionRequest [as 别名]
#.........这里部分代码省略.........
self.apiRoot = self.PROD_ENDPOINT
elif (env == "test" or env == "sandbox"):
self.apiRoot = self.TEST_ENDPOINT
else:
raise ValueError('Something is wrong with your requested API Environment. Please verify it and try again.')
return
def getDefaultHttpHeaders(self):
"""Return the default Headers object common to all API calls"""
return {
'User-Agent': 'Wealthengine Python SDK',
'Content-type': 'application/json',
'Accept': 'application/json',
'Cache-control': 'none',
'Authorization': 'APIKey ' + self.apiKey
}
def returnAPIResponse(self, r):
"""Append the http status code to the response object and return to caller
:param r - <object> a handle to the last completed request
"""
return { "status_code": r.status_code, "response": r.text }
def getProfileByEmail(self, params_dict):
"""Attempt to lookup a WealthEngine Profile by email
:param params_dict - <dictionary> A dict containing the POST fields and their data
"""
#Ensure request parameters are properly formed
if (self.Validator.isValidEmailRequest(params_dict)):
endpoint = self.apiRoot + 'profile/find_one/by_email/basic'
#Make the POST Request - setting headers and POST body
r = requests.post(endpoint, headers=self.getDefaultHttpHeaders(), data=json.dumps(params_dict))
return self.returnAPIResponse(r);
else:
return self.raiseParamsException('getProfileByEmail')
def getProfileByAddress(self, params_dict):
"""Attempt to lookup a WealthEngine Profile by address
:param params_dict - <dictionary> A dict containing the POST fields and their data
"""
#Ensure request parameters are properly formed
if (self.Validator.isValidAddressRequest(params_dict)):
endpoint = self.apiRoot + 'profile/find_one/by_address/basic'
#Make the POST Request - setting headers and POST body
r = requests.post(endpoint, headers=self.getDefaultHttpHeaders(), data=json.dumps(params_dict))
return self.returnAPIResponse(r);
else:
return self.raiseParamsException('getProfileByAddress')
def getProfileByPhone(self, params_dict):
"""Attempt to lookup a WealthEngine Profile by phone
:param params_dict - <dictionary> A dict containing the POST fields and their data
"""
#Ensure request parameters are properly formed
if (self.Validator.isValidPhoneRequest(params_dict)):
endpoint = self.apiRoot + 'profile/find_one/by_phone/basic'
#Make the POST Request - setting headers and POST body
r = requests.post(endpoint, headers = self.getDefaultHttpHeaders(), data=json.dumps(params_dict))
return self.returnAPIResponse(r);
else:
return self.raiseParamsException('getProfileByPhone');
def createSession(self, params_dict):
"""Attempt to create a session to authenticate future calls to the WealthEngine API
:param params_dict - <dictionary> A dict containing the POST fields and their data
"""
#Ensure request parameters are properly formed
if (self.Validator.isAValidSessionRequest(params_dict)):
endpoint = self.apiRoot + 'session/create'
r = requests.post(endpoint, headers=self.getDefaultHttpHeaders(), data=json.dumps(params_dict))
return self.returnAPIResponse(r);
else:
return self.raiseParamsException('createSession');
def raiseParamsException(endpoint_name):
"""Raise an exception due to API call parameters being mis-configured
:param endpoint_name - <string> The name of the endpoint that is raising the exception
"""
raise ValueException('Your ' + endpoint_name + ' params were improperly formatted. Please check them and try again')