当前位置: 首页>>代码示例>>Python>>正文


Python Validator.isValidApiKey方法代码示例

本文整理汇总了Python中validator.Validator.isValidApiKey方法的典型用法代码示例。如果您正苦于以下问题:Python Validator.isValidApiKey方法的具体用法?Python Validator.isValidApiKey怎么用?Python Validator.isValidApiKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在validator.Validator的用法示例。


在下文中一共展示了Validator.isValidApiKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from validator import Validator [as 别名]
# 或者: from validator.Validator import isValidApiKey [as 别名]
class WealthEngineClient: 
	"""Abstracts interaction with the WealthEngine Public API

		Attributes: 
			PROD_ENDPOINT The url base for the WealthEngine API production environment
			TEST_ENDPOINT The url base for the WealthEngine API test environment
			apiKey The user's APIKey obtained from dev.wealthengine.com
			apiRoot The base API URL to use in API calls, as determined by user's requested 
			Validator An instance of the Validator class, which checks POST params for correctness

	"""

	#The url base for the WealthEngine API production environment
	PROD_ENDPOINT = 'https://api.wealthengine.com/v1/'

	#The url base for the WealthEngine API test environment
	TEST_ENDPOINT = 'https://api-sandbox.wealthengine.com/v1/'

	#User's API Key from dev.wealthengine.com
	apiKey = None

	#The API root depending upon the requested environment
	apiRoot = None

	#The Validation helper
	Validator = None

	def __init__(self, apiKey, env):
		self.Validator = Validator()
		self.setApiKey(apiKey)
		self.setEnvironment(env)	
		
	def setApiKey(self, apiKey):
		"""Set the user's WealthEngine API key for use in Authorization header

			:param apiKey - <string> the user's APIKey from dev.wealthengine.com

		"""
		if (self.Validator.isValidApiKey(apiKey)): 
			self.apiKey = apiKey 
			return
		else: 
			raise ValueError('Something is wrong with your API Key please verify it and try again.')	

	def setEnvironment(self, env):
		"""Set the WealthEngine API environment - used in all API calls

			:param env - <string> the user's desired WealthEngine API environment

		"""
		if (self.Validator.isValidEnvironment(env)):
			if (env == "prod" or env == "production"): 
				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

		"""
#.........这里部分代码省略.........
开发者ID:Eagles0607,项目名称:WealthEngine-Python-SDK,代码行数:103,代码来源:__init__.py


注:本文中的validator.Validator.isValidApiKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。