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

Additional create functions? #9

Open
nelis73 opened this issue Aug 26, 2024 · 4 comments
Open

Additional create functions? #9

nelis73 opened this issue Aug 26, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@nelis73
Copy link
Collaborator

nelis73 commented Aug 26, 2024

The Possibility to create new modules.

To improve the package's control over Canvas elements it would be great to be able to create new Modules. A sketch of a function allowing for that would be:

create_module <- function(canvas, course_id, module_name, position = NULL)
{
    url <- paste0(canvas$base_url, "/api/v1/courses/", course_id,
        "/modules")
    payload <- list(module = list(name = module_name, position = position))
    response <- httr::POST(url, httr::add_headers(Authorization = paste("Bearer",
        canvas$api_key)), body = payload, encode = "json")
    if (httr::status_code(response) != 200) {
        stop("Failed to create module. Please check your authentication and API endpoint.")
    }
    return("The module has been created.")
}

The possibility to create new items within modules

Also it would be nice to create new Items within a module. Below you find a sketch of a function allowing for adding content:

create_module_item <- function(canvas, course_id, module_id, item_title, item_type = "Page",
                               position = NULL, page_url = NULL, page_id = NULL)
{
    if(item_type == "Page"){
        url <- paste0(canvas$base_url, "/api/v1/courses/", course_id,
            "/pages/", page_id)
        page <- httr::GET(url, httr::add_headers(Authorization = paste("Bearer", canvas$api_key)))
        page_url <- httr::content(page)$url
    }
    url <- paste0(canvas$base_url, "/api/v1/courses/", course_id,
        "/modules/", module_id, "/items/")
    payload <- list(module_item = list(title = item_title, type = item_type,
        position = position, page_url = page_url))
    response <- httr::POST(url, httr::add_headers(Authorization = paste("Bearer",
        canvas$api_key)), body = payload, encode = "json")
    if (httr::status_code(response) != 200) {
        stop("Failed to create module item. Please check your authentication and API endpoint.")
    }
    return("The module item has been created.")
}

This function now has a focus on adding existing pages to a module and for other item types tailored arguments may have to be added.

The possibility to update or delete created elements

Not only for the two suggested functions above, but also for an existing function like create_page() it seems useful to add functions to either delete or update existing elements. This is also convenient for publishing newly created elements as Canvas does not seem to allow for setting these published argument while creating, but needs an additional update step.

@nelis73 nelis73 added the enhancement New feature or request label Aug 26, 2024
@tin900
Copy link
Contributor

tin900 commented Aug 27, 2024

Hi @nelis73 ,

Given that you provide (working?) functions, would you be willing to open pull requests to incorporate your functions?

@nelis73
Copy link
Collaborator Author

nelis73 commented Aug 27, 2024

Hi @tin900,

Sure, I could do that. As I am not used to working in github, I will have to set up things and learn how stuff may be added, so it may take a while (R/exams' version control is done in https://r-forge.r-project.org).

Best,

Niels

@tin900
Copy link
Contributor

tin900 commented Aug 28, 2024

@nelis73
First off, awesome that you are willing to learn! If need be, I can hop on a call to work through a request together.

@tin900
Copy link
Contributor

tin900 commented Sep 4, 2024

@nelis73 has created the functions to create modules and create module items in the merged PR #11

I believe the latter part of the initial issue text should be its own issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants