本文整理匯總了Python中edx_rest_api_client.client.EdxRestApiClient.accounts方法的典型用法代碼示例。如果您正苦於以下問題:Python EdxRestApiClient.accounts方法的具體用法?Python EdxRestApiClient.accounts怎麽用?Python EdxRestApiClient.accounts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類edx_rest_api_client.client.EdxRestApiClient
的用法示例。
在下文中一共展示了EdxRestApiClient.accounts方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: account_details
# 需要導入模塊: from edx_rest_api_client.client import EdxRestApiClient [as 別名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import accounts [as 別名]
def account_details(self, request):
""" Returns the account details from LMS.
Args:
request (WSGIRequest): The request from which the LMS account API endpoint is created.
Returns:
A dictionary of account details.
Raises:
ConnectionError, SlumberBaseException and Timeout for failures in establishing a
connection with the LMS account API endpoint.
"""
try:
api = EdxRestApiClient(
request.site.siteconfiguration.build_lms_url('/api/user/v1'),
append_slash=False,
jwt=request.site.siteconfiguration.access_token
)
response = api.accounts(self.username).get()
return response
except (ConnectionError, SlumberBaseException, Timeout):
log.exception(
'Failed to retrieve account details for [%s]',
self.username
)
raise
示例2: is_verified
# 需要導入模塊: from edx_rest_api_client.client import EdxRestApiClient [as 別名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import accounts [as 別名]
def is_verified(self, site):
"""
Check if a user has verified his/her identity.
Calls the LMS verification status API endpoint and returns the verification status information.
The status information is stored in cache, if the user is verified, until the verification expires.
Args:
site (Site): The site object from which the LMS account API endpoint is created.
Returns:
True if the user is verified, false otherwise.
Raises:
ConnectionError, SlumberBaseException and Timeout for failures in
establishing a connection with the LMS verification status API endpoint.
"""
try:
cache_key = 'verification_status_{username}'.format(username=self.username)
cache_key = hashlib.md5(cache_key).hexdigest()
verification = cache.get(cache_key)
if not verification:
api = EdxRestApiClient(
site.siteconfiguration.build_lms_url('api/user/v1/'),
oauth_access_token=self.access_token
)
response = api.accounts(self.username).verification_status().get()
verification = response.get('is_verified', False)
if verification:
cache_timeout = int((parse(response.get('expiration_datetime')) - now()).total_seconds())
cache.set(cache_key, verification, cache_timeout)
return verification
except HttpNotFoundError:
log.debug('No verification data found for [%s]', self.username)
return False
except (ConnectionError, SlumberBaseException, Timeout):
msg = 'Failed to retrieve verification status details for [{username}]'.format(username=self.username)
log.exception(msg)
raise VerificationStatusError(msg)