예제 #1
0
    def add_favorite_group(self, group, use_sis_id=False, **kwargs):
        """
        Add a group to the current user's favorites. If the group is already
        in the user's favorites, nothing happens.

        :calls: `POST /api/v1/users/self/favorites/groups/:id \
        <https://canvas.instructure.com/doc/api/favorites.html#method.favorites.add_favorite_groups>`_

        :param group: The ID or SIS ID of the group.
        :type group: :class:`canvasapi.group.Group` or int

        :param use_sis_id: Whether or not `group` is an sis ID.
            Defaults to `False`.
        :type use_sis_id: bool

        :rtype: :class:`canvasapi.favorite.Favorite`
        """
        if use_sis_id:
            group_id = group
            uri_str = "users/self/favorites/groups/sis_group_id:{}"
        else:
            group_id = obj_or_id(group, "group", (Group, ))
            uri_str = "users/self/favorites/groups/{}"

        response = self._requester.request("POST",
                                           uri_str.format(group_id),
                                           _kwargs=combine_kwargs(**kwargs))
        return Favorite(self._requester, response.json())
예제 #2
0
    def add_favorite_course(self, course, use_sis_id=False, **kwargs):
        """
        Add a course to the current user's favorites. If the course is already
        in the user's favorites, nothing happens.

        :calls: `POST /api/v1/users/self/favorites/courses/:id \
        <https://canvas.instructure.com/doc/api/favorites.html#method.favorites.add_favorite_course>`_

        :param course: The course or ID/SIS ID of the course.
        :type course: :class:`canvasapi.course.Course` or int

        :param use_sis_id: Whether or not `course` is an sis ID.
            Defaults to `False`.
        :type use_sis_id: bool

        :rtype: :class:`canvasapi.favorite.Favorite`
        """
        if use_sis_id:
            course_id = course
            uri_str = "users/self/favorites/courses/sis_course_id:{}"
        else:
            course_id = obj_or_id(course, "course", (Course, ))
            uri_str = "users/self/favorites/courses/{}"

        response = self._requester.request("POST",
                                           uri_str.format(course_id),
                                           _kwargs=combine_kwargs(**kwargs))
        return Favorite(self._requester, response.json())