-
Notifications
You must be signed in to change notification settings - Fork 179
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
New Quizzes #612
Merged
Merged
New Quizzes #612
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from canvasapi.canvas_object import CanvasObject | ||
from canvasapi.util import combine_kwargs | ||
|
||
|
||
class NewQuiz(CanvasObject): | ||
def __str__(self): | ||
return "{} ({})".format(self.title, self.id) | ||
|
||
def delete(self, **kwargs): | ||
""" | ||
Delete a single new quiz. | ||
|
||
:calls: `DELETE /api/quiz/v1/courses/:course_id/quizzes/:assignment_id \ | ||
<https://canvas.instructure.com/doc/api/new_quizzes.html#method.new_quizzes/quizzes_api.destroy>`_ | ||
|
||
:returns: The deleted New Quiz object | ||
:rtype: :class:`canvasapi.new_quiz.NewQuiz` | ||
""" | ||
endpoint = "courses/{}/quizzes/{}".format(self.course_id, self.id) | ||
|
||
response = self._requester.request( | ||
"DELETE", | ||
endpoint, | ||
_url=self._requester.original_url + "/api/quiz/v1/" + endpoint, | ||
_kwargs=combine_kwargs(**kwargs), | ||
) | ||
response_json = response.json() | ||
response_json.update({"course_id": self.course_id}) | ||
|
||
return NewQuiz(self._requester, response_json) | ||
|
||
def update(self, **kwargs): | ||
""" | ||
Update a single New Quiz for the course. | ||
|
||
:calls: `PATCH /api/quiz/v1/courses/:course_id/quizzes/:assignment_id \ | ||
<https://canvas.instructure.com/doc/api/new_quizzes.html#method.new_quizzes/quizzes_api.update>`_ | ||
|
||
:returns: The updated New Quiz object | ||
:rtype: :class:`canvasapi.new_quiz.NewQuiz` | ||
""" | ||
endpoint = "courses/{}/quizzes/{}".format(self.course_id, self.id) | ||
|
||
response = self._requester.request( | ||
"PATCH", | ||
endpoint, | ||
_url=self._requester.original_url + "/api/quiz/v1/" + endpoint, | ||
_kwargs=combine_kwargs(**kwargs), | ||
) | ||
response_json = response.json() | ||
response_json.update({"course_id": self.course_id}) | ||
|
||
return NewQuiz(self._requester, response_json) |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"create_new_quiz": { | ||
"method": "POST", | ||
"endpoint": "courses/1/quizzes", | ||
"data": { | ||
"id": 1, | ||
"title": "New Quiz One", | ||
"instructions": "<p>This is the first New Quiz. Good luck!</p>" | ||
}, | ||
"status_code": 200 | ||
}, | ||
"delete_new_quiz": { | ||
"method": "DELETE", | ||
"endpoint": "courses/1/quizzes/1", | ||
"data": { | ||
"id": 1, | ||
"title": "New Quiz One", | ||
"instructions": "<p>This is the first New Quiz. Good luck!</p>" | ||
}, | ||
"status_code": 200 | ||
}, | ||
"get_new_quiz": { | ||
"method": "GET", | ||
"endpoint": "courses/1/quizzes/1", | ||
"data": { | ||
"id": 1, | ||
"title": "New Quiz One", | ||
"instructions": "<p>This is the first New Quiz. Good luck!</p>" | ||
}, | ||
"status_code": 200 | ||
}, | ||
"get_new_quizzes": { | ||
"method": "GET", | ||
"endpoint": "courses/1/quizzes", | ||
"data": [ | ||
{ | ||
"id": 1, | ||
"title": "New Quiz One", | ||
"instructions": "<p>This is the first New Quiz. Good luck!</p>" | ||
}, | ||
{ | ||
"id": 2, | ||
"title": "New Quiz Two", | ||
"instructions": "<p>This is the second New Quiz. Good luck!</p>" | ||
} | ||
], | ||
"status_code": 200 | ||
}, | ||
"update_new_quiz": { | ||
"method": "PATCH", | ||
"endpoint": "courses/1/quizzes/1", | ||
"data": { | ||
"id": 1, | ||
"title": "New Quiz One - Updated!", | ||
"instructions": "<p>This is the updated New Quiz. You got this!</p>" | ||
}, | ||
"status_code": 200 | ||
} | ||
} |
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
Oops, something went wrong.
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.
I wonder if instead of defining the
_url
on all these calls we could modifyrequester.py
to handle both of these patterns? Would eliminate a little redundancy. Would probably need likeAnd then in
requester.request
would have to have some way of determining if it's a new quiz. I feel like there will be more methods so having this a a little cleaner now could be of benefit.I'm not sure the best way to handle that though. The easy solution might be to re-use url? Just an idea, not sure if it makes it significantly better.
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.
That's a good point. The same could be done for the
graphql
endpoint in the requester.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.
Right, I thought about that a little when implementing that method but that was only a single call. This is repeated a few times for each endpoint. But that could also be made to use this method.
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 could also be done on a separate issue just to get this in quicker, but I think it should be improved before future new_quizzes get added.
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.
I'm going to merge this in for now, but have spun this comment off into its own issue: #619. Will seek to complete that issue before doing a full release.