Crates.io | canvas_lms_connector |
lib.rs | canvas_lms_connector |
version | 0.1.7 |
source | src |
created_at | 2023-11-15 17:28:24.625568 |
updated_at | 2024-09-22 17:23:35.404253 |
description | This library provides a range of functionalities for interacting with the Canvas Learning Management System API. |
homepage | |
repository | https://github.com/afmiguel/canvas_lms_connector |
max_upload_size | |
id | 1036599 |
size | 116,078 |
This documentation introduces the Canvas LMS Connector, a Rust library designed to facilitate interaction with the Canvas Learning Management System (LMS) API. Crafted to integrate Rust applications with the features of Canvas, this library offers an effective solution for data manipulation in educational environments.
The focus of Canvas LMS Connector (canvas_lms_connector
) is to provide an accessible interface for developers seeking to interact with the Canvas API, encompassing everything from automating administrative processes to supporting educational initiatives. The library caters to various needs, ranging from course management to the development of customized applications.
The purpose of this documentation is to provide detailed information on installation, usage, and examples of canvas_lms_connector
application. It is intended to be an informative resource for efficiently utilizing the Canvas API across various development contexts.
This section outlines the conventions used throughout this documentation for the Canvas LMS Connector. Understanding these conventions will help in effectively utilizing this guide and interpreting the information as intended.
monospaced font
.<angle brackets>
indicates a placeholder that should be replaced with the relevant value by the user.By adhering to these conventions, this documentation aims to provide a clear and consistent guide for users of the canvas_lms_connector
. Should there be any ambiguity or questions regarding the conventions, users are encouraged to seek clarification through the support channels provided.
Before beginning to work with the "Canvas LMS Connector", ensure that the following prerequisites are met:
Meeting these prerequisites will facilitate a smooth initial setup and an effective use of the "Canvas LMS Connector".
To install the "Canvas LMS Connector" in your Rust project, follow these steps:
Add the Dependency:
Cargo.toml
file and add canvas_lms_connector
to the [dependencies]
section:
[dependencies]
canvas_lms_connector = "latest_version"
Update Your Project:
cargo update
Build the Project:
cargo build
To configure the "Canvas LMS Connector" for first-time use, follow these steps:
Obtain the Canvas API URL:
https://[your-institution].instructure.com
./api/v1
to the end of this URL. For example, https://[your-institution].instructure.com/api/v1
.Generate an API Token:
Account
> Settings
.Approved Integrations
and click on + New Access Token
.Generate Token
to create a new API token.After obtaining the API URL and token, you can test these credentials using the test_canvas_credentials
function provided by the CanvasCredentials
struct. This function helps verify the validity of the API URL and token.
Example usage:
use canvas_lms_connector::credentials::{CanvasCredentials, test_canvas_credentials};
let api_url = "https://your-institution.instructure.com/api/v1";
let access_token = "your_api_token";
let test_result = test_canvas_credentials(api_url, access_token);
match test_result {
Ok(status_code) => println!("Credentials are valid! Status code: {}", status_code),
Err(error_code) => eprintln!("Failed to validate credentials. Error code: {}", error_code),
}
With the API URL and token, you can now set up the "Canvas LMS Connector" in your project. Typically, these values are set as environment variables or configured in a settings file for security and ease of management.
The authentication process in the "Canvas LMS Connector" begins with obtaining a CanvasCredentials
struct, which contains the necessary credentials acquired in the previous steps. This struct plays a crucial role in establishing a secure connection with the Canvas LMS API. The following subsections detail the methods available for obtaining and securely storing these credentials.
Interactive Authentication via CLI (Preferred Method):
credentials
method first attempts to retrieve credentials stored in the system's key store.use canvas_lms_connector::credentials::{CanvasCredentials, credentials};
let credentials = credentials();
credentials
method to access credentials from the system's key store, the system may prompt for the user's password. This is a standard security measure to ensure authorized access to sensitive information. It's important to be prepared for this prompt, especially when running the application for the first time or on a new device.use_file_credentials
feature in Cargo.toml
:[features]
use_file_credentials = []
credentials()
checks for a file config.json
in the 'Downloads' directory that contains the following:
{
"url_canvas": "https://your-institution.instructure.com/api/v1",
"token_canvas": "your_api_token"
}
use_file_credentials
) is convenient, particularly for development purposes, it poses significant security risks and is not recommended for production environments. Storing credentials in a file, such as config.json
, can make them vulnerable to unauthorized access. This method should be used with extreme caution and only for development and testing purposes, ensuring that production credentials are managed in a more secure manner.Using the CanvasCredentials
Structure (For Development Purposes Only):
use canvas_lms_connector::credentials::CanvasCredentials;
let credentials = CanvasCredentials {
url_canvas: "https://your-institution.instructure.com/api/v1".to_string(),
token_canvas: "your_api_token".to_string(),
};
These methods ensure authentication with the Canvas LMS for API interactions.
Retrieving courses from the Canvas LMS using the "Canvas LMS Connector" involves two methods returning distinct result types: CanvasResultCourses
for multiple courses and CanvasResultSingleCourse
for a single course.
CanvasResultCourses
Structure:
Ok(Vec<Course>)
: Success with a list of courses.ErrConnection(String)
: Error related to connection issues.ErrCredentials(String)
: Error related to authentication or credentials.CanvasResultSingleCourse
Structure:
Ok(Course)
: Success with a single course.ErrConnection(String)
: Error related to connection issues.ErrCredentials(String)
: Error related to authentication or credentials.use canvas_lms_connector::{Canvas, CanvasCredentials, CanvasResultCourses};
let credentials = CanvasCredentials { ... }; // Initialize with your credentials
match Canvas::fetch_courses_with_credentials(&credentials) {
CanvasResultCourses::Ok(courses) => println!("Courses: {:?}", courses),
CanvasResultCourses::ErrConnection(err) => eprintln!("Connection error: {}", err),
CanvasResultCourses::ErrCredentials(err) => eprintln!("Credentials error: {}", err),
}
use canvas_lms_connector::{Canvas, CanvasCredentials, CanvasResultSingleCourse};
let credentials = CanvasCredentials { ... }; // Initialize with your credentials
let course_id: u64 = 123; // Your course ID
match Canvas::fetch_single_course_with_credentials(&credentials, course_id) {
CanvasResultSingleCourse::Ok(course) => println!("Course: {:?}", course),
CanvasResultSingleCourse::ErrConnection(err) => eprintln!("Connection error: {}", err),
CanvasResultSingleCourse::ErrCredentials(err) => eprintln!("Credentials error: {}", err),
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The "Canvas LMS Connector" is now installed and ready for use in your Rust project.
For detailed documentation on how to use Canvas Learning, refer to the official documentation.
This project is licensed under the MIT License