This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
FC-0001: Remove EdxRestApiClient usage in edx-analatycis-data-api #542
Merged
dianakhuang
merged 1 commit into
openedx-unsupported:master
from
raccoongang:depr/edx-analytics-data-api
Apr 12, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import logging | ||
from urllib.parse import urljoin | ||
|
||
from edx_rest_api_client.client import EdxRestApiClient | ||
from edx_rest_api_client.exceptions import HttpClientError | ||
from django.conf import settings | ||
from edx_rest_api_client.client import OAuthAPIClient | ||
from opaque_keys import InvalidKeyError | ||
from opaque_keys.edx.keys import UsageKey | ||
from requests.exceptions import RequestException | ||
from requests.exceptions import HTTPError, RequestException | ||
|
||
from analyticsdataserver.utils import temp_log_level | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class CourseBlocksApiClient(EdxRestApiClient): | ||
class CourseBlocksApiClient(OAuthAPIClient): | ||
""" | ||
This class is a sub-class of the edX Rest API Client | ||
(https://github.com/edx/edx-rest-api-client). | ||
|
@@ -22,15 +23,28 @@ class CourseBlocksApiClient(EdxRestApiClient): | |
Currently, this client is only used for a local-only developer script (generate_fake_course_data). | ||
""" | ||
|
||
def __init__(self, url, access_token, timeout): | ||
super().__init__(url, oauth_access_token=access_token, timeout=timeout) | ||
|
||
def all_videos(self, course_id): | ||
try: | ||
logger.debug('Retrieving course video blocks for course_id: %s', course_id) | ||
response = self.blocks.get(course_id=course_id, all_blocks=True, depth='all', block_types_filter='video') | ||
|
||
try: | ||
api_base_url = urljoin(settings.LMS_BASE_URL + '/', 'api/courses/v1/') | ||
except AttributeError: | ||
logger.warning("LMS_BASE_URL is not configured! Cannot get video ids.") | ||
return None | ||
logger.info("Assuming the Course Blocks API is hosted at: %s", api_base_url) | ||
|
||
blocks_kwargs = { | ||
'course_id': course_id, | ||
'all_blocks': True, | ||
'depth': 'all', | ||
'block_types_filter': 'video' | ||
} | ||
response = self.get(urljoin(api_base_url, 'blocks/'), params=blocks_kwargs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this urljoin could just be rolled into the top urljoin which points out that it isn't really api_base_url, it is url_of_this_blocks_call |
||
response.raise_for_status() | ||
data = response.json() | ||
logger.info("Successfully authenticated with the Course Blocks API.") | ||
except HttpClientError as e: | ||
except HTTPError as e: | ||
if e.response.status_code == 401: | ||
logger.warning("Course Blocks API failed to return video ids (%s). " | ||
"See README for instructions on how to authenticate the API with your local LMS.", | ||
|
@@ -50,7 +64,7 @@ def all_videos(self, course_id): | |
# (The UsageKey utility still works despite the import errors, so I think the errors are not important). | ||
with temp_log_level('stevedore', log_level=logging.CRITICAL): | ||
videos = [] | ||
for video in response['blocks'].values(): | ||
for video in data['blocks'].values(): | ||
try: | ||
encoded_id = UsageKey.from_string(video['id']).html_id() | ||
except InvalidKeyError: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this log seems unnecessary and noisy, although to be fair there is some more untouched noisy logging in here