-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change API requests to use Moodle'sCurl Class #46
Conversation
Important Auto Review SkippedAuto reviews are disabled on base/target branches other than the default branch. Please add the base/target branch pattern to the list of additional branches to be reviewed in the settings. Please check the settings in the CodeRabbit UI or the To trigger a single review, invoke the WalkthroughThe recent modifications in the project focus on enhancing the way authentication tokens are generated and quiz details are dispatched. By transitioning to a custom Changes
Related issues
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files selected for processing (2)
- classes/observer.php (1 hunks)
- version.php (1 hunks)
Additional comments: 2
version.php (1)
- 28-30: The updates to the plugin version and release information are correctly implemented, following semantic versioning and including a build identifier. This ensures that the plugin's version accurately reflects the new changes.
classes/observer.php (1)
- 125-125: The handling of the authentication token (
$token
) and its subsequent use in sending quiz details is correctly implemented. This change not only improves the code's structure but also its security by ensuring that API requests are made with proper authentication.
classes/observer.php
Outdated
global $CFG; | ||
require_once($CFG->libdir . '/filelib.php'); | ||
$curl = new curl(); | ||
$headers = array('Content-Type: application/json'); | ||
$curl->setHeader($headers); | ||
$request_url = $api_base_url . '/auth'; | ||
$json_payload = json_encode($payload); | ||
try { | ||
$response = curl_exec($curl); | ||
$err = curl_error($curl); | ||
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); | ||
curl_close($curl); | ||
if ($err) { | ||
throw new CustomException($err); | ||
} elseif ($response && $httpcode != 200) { | ||
throw new CustomException($response); | ||
} else { | ||
return $response; | ||
$response = $curl->post($request_url, $json_payload); | ||
if ($curl->get_errno()) { | ||
$error_msg = $curl->error; | ||
throw new moodle_exception('errorapirequest', 'yourplugin', '', $error_msg); | ||
} | ||
$decoded_response = json_decode($response, true); | ||
if (!isset($decoded_response['access_token'])) { | ||
throw new CustomException("Auth Token Not generated"); | ||
} | ||
return $decoded_response; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
changed
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.
@rohansharmasitoula: Acknowledged. If you've made the suggested change, that's great! Please proceed with any further testing or reviews required for your pull request. If you have any more questions or need further assistance, feel free to ask.
classes/observer.php
Outdated
global $CFG; | ||
require_once($CFG->libdir . '/filelib.php'); | ||
$curl = new curl(); | ||
$headers = array( | ||
'Authorization: Bearer ' . $token, | ||
'Content-Type: application/json' | ||
); | ||
$curl->setHeader($headers); | ||
$request_url = $api_base_url . '/quiz'; | ||
$json_eventdata = json_encode($eventdata); | ||
try { | ||
$response = curl_exec($curl); | ||
$err = curl_error($curl); | ||
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); | ||
curl_close($curl); | ||
if ($err) { | ||
throw new CustomException($err); | ||
} elseif ($response && $httpcode != 201) { | ||
throw new CustomException($response); | ||
} else { | ||
return $response; | ||
$response = $curl->post($request_url, $json_eventdata); | ||
if ($curl->get_errno()) { | ||
$error_msg = $curl->error; | ||
throw new moodle_exception('errorapirequest', 'yourplugin', '', $error_msg); | ||
} | ||
$decoded_response = json_decode($response, true); | ||
return $decoded_response; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
changed
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.
@rohansharmasitoula: Great to hear that you've made the change! If you have any more questions or need further assistance, feel free to ask. Keep up the good work!
4f46a46
into
release/v1.3.1-proxy-support
Description
Github Issue
Checklist before requesting a review
Type of change
Summary by CodeRabbit