Пример #1
0
    def create_submission(self, poll_submissions, **kwargs):
        """
        Create a new poll submission for this poll session.

        :calls: `POST /api/v1/polls/:poll_id/poll_sessions/:poll_session_id/poll_submissions \
        <https://canvas.instructure.com/doc/api/poll_submissions.html#method.polling/poll_submissions.create>`_

        :param poll_submissions: List of arguments. poll_choice_id (required int): Chosen poll \
        choice for this submission.
        :type poll_submissions: list

        :rtype: :class:`canvasapi.poll_submission.PollSubmission`
        """
        if (isinstance(poll_submissions, list)
                and isinstance(poll_submissions[0], dict)
                and "poll_choice_id" in poll_submissions[0]):
            kwargs["poll_submissions"] = poll_submissions
        else:
            raise RequiredFieldMissing(
                "Dictionary with key 'poll_choice_id is required.")

        response = self._requester.request(
            "POST",
            "polls/{}/poll_sessions/{}/poll_submissions".format(
                self.poll_id, self.id),
            _kwargs=combine_kwargs(**kwargs),
        )
        return PollSubmission(self._requester,
                              response.json()["poll_submissions"][0])
Пример #2
0
    def get_submission(self, poll_submission, **kwargs):
        """
        Returns the poll submission with the given id.

        :calls: `GET /api/v1/polls/:poll_id/poll_sessions/:poll_session_id/poll_submissions/:id \
        <https://canvas.instructure.com/doc/api/poll_submissions.html#method.polling/poll_submissions.show>`_

        :param poll_submission: Takes a poll submission id (int) or object.
        :type poll_submission: int or :class:`canvasapi.poll_submission.PollSubmission`

        :rtype: :class:`canvasapi.poll_submission.PollSubmission`
        """
        poll_submission_id = obj_or_id(poll_submission, "poll_submission",
                                       (PollSubmission, ))

        response = self._requester.request(
            'GET',
            'polls/{}/poll_sessions/{}/poll_submissions/{}'.format(
                self.poll_id, self.id, poll_submission_id),
            _kwargs=combine_kwargs(**kwargs))
        return PollSubmission(self._requester,
                              response.json()['poll_submissions'][0])