Skip to content

Commit

Permalink
feat: delete and edit sections
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomeriko96 committed Jan 6, 2024
1 parent e655441 commit 79d057c
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 30 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export(create_course_section)
export(create_folder)
export(create_group_category)
export(create_page)
export(delete_course_section)
export(download_course_file)
export(edit_section)
export(get_accounts)
export(get_all_courses)
export(get_assignment_data)
Expand Down Expand Up @@ -39,6 +41,7 @@ export(get_group_users)
export(get_module_items)
export(get_modules)
export(get_page_content)
export(get_section_information)
export(get_student_summaries)
export(get_user_course_assignment_data)
export(get_user_course_messaging_data)
Expand Down
26 changes: 26 additions & 0 deletions R/delete_course_section.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#' Delete a Course Section in Canvas LMS
#'
#' Deletes an existing course section using the Canvas LMS API.
#'
#' @param canvas A list containing the 'api_key' and 'base_url' for authentication.
#' @param section_id The ID of the section to delete.
#'
#' @return A confirmation message that the section has been deleted.
#' @export
#'
delete_course_section <- function(canvas, section_id) {
# Construct the API endpoint URL
url <- paste0(canvas$base_url, "/api/v1/sections/", section_id)

# Make the API request
response <- httr::DELETE(url,
httr::add_headers(Authorization = paste("Bearer", canvas$api_key)))

# Check the response status code
if (httr::status_code(response) != 200) {
stop("Failed to delete course section. Please check your authentication and API endpoint.")
}

# Return a confirmation message
return("The course section has been deleted.")
}
45 changes: 45 additions & 0 deletions R/edit_section.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#' Edit a Course Section in Canvas LMS
#'
#' Modifies an existing course section using the Canvas LMS API.
#'
#' @param canvas A list containing the 'api_key' and 'base_url' for authentication.
#' @param section_id The ID of the section to edit.
#' @param section_name The new name of the section (optional).
#' @param sis_section_id The new SIS ID of the section (optional).
#' @param integration_id The new integration ID of the section (optional).
#' @param section_start_date The new start date of the section (optional).
#' @param section_end_date The new end date of the section (optional).
#' @param restrict_enrollments_to_section_dates Whether to restrict user enrollments to the start and end dates of the section (optional).
#' @param override_sis_stickiness Whether to override SIS stickiness (optional).
#'
#' @return A confirmation message that the section has been edited.
#' @export
#'
edit_section <- function(canvas, section_id, section_name = NULL, sis_section_id = NULL, integration_id = NULL, section_start_date = NULL, section_end_date = NULL, restrict_enrollments_to_section_dates = NULL, override_sis_stickiness = NULL) {
# Construct the API endpoint URL
url <- paste0(canvas$base_url, "/api/v1/sections/", section_id)

# Create the request payload
payload <- list()
if (!is.null(section_name)) payload$course_section$name <- section_name
if (!is.null(sis_section_id)) payload$course_section$sis_section_id <- sis_section_id
if (!is.null(integration_id)) payload$course_section$integration_id <- integration_id
if (!is.null(section_start_date)) payload$course_section$start_at <- section_start_date
if (!is.null(section_end_date)) payload$course_section$end_at <- section_end_date
if (!is.null(restrict_enrollments_to_section_dates)) payload$course_section$restrict_enrollments_to_section_dates <- restrict_enrollments_to_section_dates
if (!is.null(override_sis_stickiness)) payload$override_sis_stickiness <- override_sis_stickiness

# Make the API request
response <- httr::PUT(url,
httr::add_headers(Authorization = paste("Bearer", canvas$api_key)),
body = payload,
encode = "json")

# Check the response status code
if (httr::status_code(response) != 200) {
stop("Failed to edit course section. Please check your authentication and API endpoint.")
}

# Return a confirmation message
return("The course section has been edited.")
}
32 changes: 32 additions & 0 deletions R/get_section_information.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' Get Section Information in Canvas LMS
#'
#' Retrieves information about a specific course section using the Canvas LMS API.
#'
#' @param canvas A list containing the 'api_key' and 'base_url' for authentication.
#' @param course_id The ID of the course.
#' @param section_id The ID of the section.
#'
#' @return The information about the section.
#' @export
#'
get_section_information <- function(canvas, course_id, section_id) {
# Construct the API endpoint URL
url <- paste0(canvas$base_url, "/api/v1/courses/", course_id, "/sections/", section_id)

# Make the API request
response <- httr::GET(url,
httr::add_headers(Authorization = paste("Bearer", canvas$api_key)))

# Check the response status code
if (httr::status_code(response) != 200) {
stop("Failed to retrieve section information. Please check your authentication and API endpoint.")
}

# Parse the response
section_info <- httr::content(response, "text", encoding = "UTF-8") %>%
jsonlite::fromJSON(flatten = TRUE) %>%
dplyr::bind_rows()

# Return the section information
return(section_info)
}
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2386,10 +2386,10 @@
- [ ] Get section information SectionsController#show ;
GET /api/v1/courses/:course_id/sections/:id

- [ ] Get section information SectionsController#show ;
- [x] Get section information SectionsController#show ;
GET /api/v1/sections/:id

- [ ] Delete a section SectionsController#destroy ;
- [x] Delete a section SectionsController#destroy ;
DELETE /api/v1/sections/:id

- [ ] Get Kaltura config ServicesApiController#show_kaltura_config ;
Expand Down
55 changes: 27 additions & 28 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ reference:
# - update_global_notification
# - title: Account Reports
# desc: >
# RMethods for account reports.
# Methods for account reports.
# contents:
# - list_available_reports
# - start_a_report
Expand All @@ -52,7 +52,7 @@ reference:
# - delete_a_report
- title: Accounts
desc: >
RMethods for accounts.
Methods for accounts.
contents:
- get_accounts
# - get_accounts_admins_can_manage
Expand Down Expand Up @@ -92,25 +92,25 @@ reference:
- get_user_course_messaging_data
# - title: Announcement External Feeds
# desc: >
# Retrieve the list of external feeds.
# Methods for annoucements through external feeds.
# contents:
# - list_external_feeds
# - create_external_feed
# - delete_external_feed
- title: Announcements
desc: >
Retrieve the list of announcements.
Methods for announcements.
contents:
- get_course_announcements
# - title: API Token Scopes
# desc: >
# Retrieve the list of API token scopes.
# Methods for API Token scopes.
# contents:
# - list_scopes
#
# - title: Appointment Groups
# desc: >
# Retrieve the list of appointment groups.
# Methods for appointment groups.
# contents:
# - list_appointment_groups
# - create_appointment_group
Expand All @@ -122,12 +122,12 @@ reference:
# - get_next_appointment
# - title: Assignment Extensions
# desc: >
# Set extensions for student assignment submissions.
# Methods for assignment extensions.
# contents:
# - set_assignment_extensions
- title: Assignment Groups
desc: >
Retrieve the list of assignment groups.
Methos for assignment groups.
contents:
# - list_assignment_groups
# - get_assignment_group
Expand All @@ -136,7 +136,7 @@ reference:
# - destroy_assignment_group
- title: Assignments
desc: >
Delete an assignment.
Methods for assignments.
contents:
# - delete_assignment
# - list_assignments
Expand All @@ -151,7 +151,7 @@ reference:
# - bulk_update_assignment_dates
# - title: Assignment Overrides
# desc: >
# Retrieve the list of assignment overrides.
# Methods for assignment overrides
# contents:
# - list_assignment_overrides
# - get_single_assignment_override
Expand All @@ -165,7 +165,7 @@ reference:
# - batch_update_overrides_in_course
# - title: Authentication Providers
# desc: >
# Retrieve the list of authentication providers.
# Methods for authentication providers.
# contents:
# - list_authentication_providers
# - add_authentication_provider
Expand All @@ -176,14 +176,14 @@ reference:
# - update_account_auth_settings
# - title: Authentications Log
# desc: >
# Query authentications by login.
# Methods for authentications log.
# contents:
# - query_by_login
# - query_by_account
# - query_by_user
# - title: Blackout Dates
# desc: >
# Retrieve the list of blackout dates.
# Methods for blackout dates.
# contents:
# - list_blackout_dates
# - get_single_blackout_date
Expand Down Expand Up @@ -361,7 +361,7 @@ reference:
#
- title: Courses
desc: >
Retrieve the list of courses.
Methods for courses.
contents:
# - list_courses
- get_course_details
Expand Down Expand Up @@ -409,7 +409,7 @@ reference:
#
- title: Discussion Topics
desc: >
Retrieve the list of discussion topics.
Methods for discussion topics.
contents:
# - list_discussion_topics
- get_discussions
Expand Down Expand Up @@ -441,7 +441,7 @@ reference:
# - retrieve_enrollment_term
- title: Enrollments
desc: >
Retrieve the list of enrollments.
Methods for enrollments.
contents:
- get_course_enrollments
# - enrollment_by_id
Expand Down Expand Up @@ -510,7 +510,7 @@ reference:
# - remove_feature_flag
- title: Files
desc: >
Retrieve the list of files and quota information.
Methods for files.
contents:
# - get_quota_information
- get_course_files
Expand All @@ -524,7 +524,7 @@ reference:
# - reset_link_verifier
- title: Folders
desc: >
Retrieve the list of all folders.
Methods for folders.
contents:
# - list_all_folders
- get_course_folders
Expand Down Expand Up @@ -576,7 +576,7 @@ reference:
# - get_a_single_grading_standard_in_a_context
- title: Group Categories
desc: >
Retrieve the list of group categories for a given context.
Methods for group categories.
contents:
# - list_group_categories_for_a_context
# - get_a_single_group_category
Expand All @@ -592,7 +592,7 @@ reference:
# - assign_unassigned_members
- title: Groups
desc: >
Retrieve the list of groups available in a context.
Methods for groups.
contents:
# - list_groups
# - get_a_single_group
Expand Down Expand Up @@ -702,7 +702,7 @@ reference:
# - show_provisional_grade_status_for_a_student
- title: Modules
desc: >
Retrieve the list of modules for a specific course.
Methods for modules.
contents:
# - list_modules
- get_modules
Expand All @@ -713,7 +713,7 @@ reference:
# - re_lock_module_progressions
- title: Module Items
desc: >
Retrieve the list of module items for a specific module.
Methods for module items.
contents:
- get_module_items
# - show_module_item
Expand Down Expand Up @@ -829,7 +829,7 @@ reference:
#
- title: Pages
desc: >
Duplicate a page, update or create front page, list pages, and revert to a revision.
Methods for pages.
contents:
- get_course_pages
# - show_front_page
Expand Down Expand Up @@ -1032,7 +1032,7 @@ reference:
#
- title: Quizzes
desc: >
Manage quizzes.
Methods for quizzes.
contents:
- get_course_quizzes
# - create_quiz
Expand Down Expand Up @@ -1104,14 +1104,13 @@ reference:
desc: >
Manage course sections.
contents:
# - list_course_sections
- get_course_sections
- create_course_section
# - edit_course_section
# - delete_course_section
- edit_section
- delete_course_section
# - cross_list_section
# - decross_list_section
# - get_section_information
- get_section_information
# - delete_section
#
# title: Services
Expand Down
19 changes: 19 additions & 0 deletions man/delete_course_section.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 79d057c

Please sign in to comment.