當前位置: 首頁>>代碼示例>>Python>>正文


Python EdxRestApiClient.journal_bundles方法代碼示例

本文整理匯總了Python中edx_rest_api_client.client.EdxRestApiClient.journal_bundles方法的典型用法代碼示例。如果您正苦於以下問題:Python EdxRestApiClient.journal_bundles方法的具體用法?Python EdxRestApiClient.journal_bundles怎麽用?Python EdxRestApiClient.journal_bundles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在edx_rest_api_client.client.EdxRestApiClient的用法示例。


在下文中一共展示了EdxRestApiClient.journal_bundles方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: DiscoveryApiClient

# 需要導入模塊: from edx_rest_api_client.client import EdxRestApiClient [as 別名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import journal_bundles [as 別名]
class DiscoveryApiClient(object):
    """
    Class for interacting with the discovery service journals endpoint
    """
    def __init__(self):
        """
        Initialize an authenticated Discovery service API client by using the
        provided user.
        """
        catalog_integration = CatalogIntegration.current()

        # Client can't be used if there is no catalog integration
        if not (catalog_integration and catalog_integration.enabled):
            LOGGER.error("Unable to create DiscoveryApiClient because catalog integration not set up or enabled")
            return None

        try:
            user = catalog_integration.get_service_user()
        except ObjectDoesNotExist:
            LOGGER.error("Unable to retrieve catalog integration service user")
            return None

        jwt = JwtBuilder(user).build_token([])
        base_url = configuration_helpers.get_value('COURSE_CATALOG_URL_BASE', settings.COURSE_CATALOG_URL_BASE)
        self.client = EdxRestApiClient(
            '{base_url}{journals_path}'.format(base_url=base_url, journals_path=JOURNALS_API_PATH),
            jwt=jwt
        )

    def get_journals(self, orgs):
        """
        get_journals from discovery, filter on orgs is supplied
        """
        try:
            if orgs:
                response = self.client.journals.get(orgs=','.join(orgs), status='active')
            else:
                response = self.client.journals.get(status='active')
            LOGGER.debug('response is type=%s', type(response))
            return response.get('results')
        except (HttpClientError, HttpServerError) as err:
            LOGGER.exception(
                'Failed to get journals from discovery-service [%s]',
                err.content
            )
            return []

    def get_journal_bundles(self, uuid=''):
        """
        get_journal_bundles from discovery on the base of uuid (optional)
        """
        try:
            response = self.client.journal_bundles(uuid).get()
        except (HttpClientError, HttpServerError) as err:
            LOGGER.exception(
                'Failed to get journal bundles from discovery-service [%s]',
                err.content
            )
            return []
        return [response] if uuid else response.get('results')
開發者ID:cmscom,項目名稱:edx-platform,代碼行數:62,代碼來源:api.py


注:本文中的edx_rest_api_client.client.EdxRestApiClient.journal_bundles方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。