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

Add API coverage for LTI resource links #662

Open
jonespm opened this issue Aug 14, 2024 · 1 comment
Open

Add API coverage for LTI resource links #662

jonespm opened this issue Aug 14, 2024 · 1 comment

Comments

@jonespm
Copy link
Contributor

jonespm commented Aug 14, 2024

What resource needs additional coverage?
Courses lti_resource links, which is a new API which is in beta and will be released soon.

What endpoints need to be covered?
Add support for these https://canvas.instructure.com/doc/api/lti_resource_links.html

GET /api/v1/courses/:course_id/lti_resource_links
GET /api/v1/courses/:course_id/lti_resource_links/:id
PUT /api/v1/courses/:course_id/lti_resource_links/:id
@jonespm
Copy link
Contributor Author

jonespm commented Aug 14, 2024

I tested this for the first GET call and looks to work

import json
import argparse
import os
from canvasapi import Canvas
from canvasapi.canvas_object import CanvasObject
from canvasapi.paginated_list import PaginatedList
from canvasapi.util import combine_kwargs
from canvasapi.course import Course

class LTIResourceLink(CanvasObject):
    def __init__(self, requester, attributes):
        # Initialize an LTIResourceLink object.
        super(LTIResourceLink, self).__init__(requester, attributes)

class ExtendedCourse(Course):
    def get_lti_resource_links(self, **kwargs):
        """
        Retrieve LTI resource links for this course as a PaginatedList.

        :return: A PaginatedList of LTI resource links.
        :rtype: :class:`canvasapi.paginated_list.PaginatedList`
        """
        endpoint = f"courses/{self.id}/lti_resource_links"
        
        return PaginatedList(
            LTIResourceLink,
            self._requester,
            "GET",
            endpoint,
            kwargs=combine_kwargs(**kwargs)
        )

API_URL = os.getenv('CANVAS_API_URL')
API_KEY = os.getenv('CANVAS_API_KEY')

if not API_URL or not API_KEY:
    print("Error: Please set the CANVAS_API_URL and CANVAS_API_KEY environment variables.")
    exit(1)

# Step 3: Initialize the Canvas API
canvas = Canvas(API_URL, API_KEY)

# Usage example, set the course_id you want
course_id = 123456
course = ExtendedCourse(canvas._Canvas__requester, {'id': course_id})

lti_resource_links = course.get_lti_resource_links()
for link in lti_resource_links:
    print(link)urce links: {response.status_code}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant