Skip to content
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

Use new_quizzes and graphql keywords #653

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion canvasapi/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ def graphql(self, query, variables=None, **kwargs):
_kwargs=combine_kwargs(**kwargs)
+ [("query", query), ("variables", variables)],
# Needs to call special endpoint without api/v1
_url=self.__requester.original_url + "/api/graphql",
_url="graphql",
json=True,
)

Expand Down
6 changes: 3 additions & 3 deletions canvasapi/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def create_new_quiz(self, **kwargs):
response = self._requester.request(
"POST",
endpoint,
_url=self._requester.original_url + "/api/quiz/v1/" + endpoint,
_url="new_quizzes",
_kwargs=combine_kwargs(**kwargs),
)
response_json = response.json()
Expand Down Expand Up @@ -1758,7 +1758,7 @@ def get_new_quiz(self, assignment, **kwargs):
response = self._requester.request(
"GET",
endpoint,
_url=self._requester.original_url + "/api/quiz/v1/" + endpoint,
_url="new_quizzes",
_kwargs=combine_kwargs(**kwargs),
)
response_json = response.json()
Expand All @@ -1783,7 +1783,7 @@ def get_new_quizzes(self, **kwargs):
self._requester,
"GET",
endpoint,
_url_override=self._requester.original_url + "/api/quiz/v1/" + endpoint,
_url_override="new_quizzes",
_kwargs=combine_kwargs(**kwargs),
)

Expand Down
4 changes: 2 additions & 2 deletions canvasapi/new_quiz.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def delete(self, **kwargs):
response = self._requester.request(
"DELETE",
endpoint,
_url=self._requester.original_url + "/api/quiz/v1/" + endpoint,
_url="new_quizzes",
_kwargs=combine_kwargs(**kwargs),
)
response_json = response.json()
Expand All @@ -44,7 +44,7 @@ def update(self, **kwargs):
response = self._requester.request(
"PATCH",
endpoint,
_url=self._requester.original_url + "/api/quiz/v1/" + endpoint,
_url="new_quizzes",
_kwargs=combine_kwargs(**kwargs),
)
response_json = response.json()
Expand Down
27 changes: 22 additions & 5 deletions canvasapi/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def __init__(self, base_url, access_token):
# Preserve the original base url and add "/api/v1" to it
self.original_url = base_url
self.base_url = base_url + "/api/v1/"
self.new_quizzes_url = base_url + "/api/quiz/v1/"
self.graphql = base_url + "/api/graphql"
self.access_token = access_token
self._session = requests.Session()
self._cache = []
Expand Down Expand Up @@ -145,10 +147,16 @@ def request(
:param use_auth: Optional flag to remove the authentication
header from the request.
:type use_auth: bool
:param _url: Optional argument to send a request to a URL
outside of the Canvas API. If this is selected and an
endpoint is provided, the endpoint will be ignored and
only the _url argument will be used.
:param _url: Optional argument to specify a request type to Canvas
or to send a request to a URL outside of the Canvas API.
If set to "new_quizzes", the new quizzes endpoint will be used.
If set to "graphql", a graphql POST request will be sent.
If any string URL is provided, it will be used instead of the
base REST URL.
If omitted or set to None, the base_url for the instance REST
endpoint will be used.
If this is selected and an endpoint is provided, the endpoint
will be ignored and only the `_url` argument will be used..
:type _url: str
:param _kwargs: A list of 2-tuples representing processed
keyword arguments to be sent to Canvas as params or data.
Expand All @@ -159,7 +167,16 @@ def request(
:type json: `bool`
:rtype: :class:`requests.Response`
"""
full_url = _url if _url else "{}{}".format(self.base_url, endpoint)
# Check for specific URL endpoints available from Canvas. If not
# specified, pass the given URL and move on.
if _url == "new_quizzes":
request_url = "{}{}".format(self.new_quizzes_url, endpoint)
elif _url == "graphql":
request_url = self.graphql
else:
request_url = _url

full_url = request_url if _url else "{}{}".format(self.base_url, endpoint)
bennettscience marked this conversation as resolved.
Show resolved Hide resolved

if not headers:
headers = {}
Expand Down
Loading