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

View discussion thread comments #45

Open
coatless opened this issue Feb 5, 2020 · 0 comments
Open

View discussion thread comments #45

coatless opened this issue Feb 5, 2020 · 0 comments

Comments

@coatless
Copy link

coatless commented Feb 5, 2020

Any interest in a contributed function that queries discussion threads to obtain all responses and they're author, e.g. get the full topic?

remove_html_tags <- function(x) {
  gsub("<.*?>", "", x)
}

get_discussion_thread = function (discussion_id, object_id, object_type = "courses")  
{
  stopifnot(object_type %in% c("courses", "groups"))
  url <- paste0(rcanvas:::canvas_url(), paste(object_type, object_id, 
                                    "discussion_topics", discussion_id, "view", sep = "/"))
  args <- list(per_page = 100)
  include <- rcanvas:::iter_args_list(NULL, "include[]")
  args <- c(args, include)

  # Workaround for process_request issue.
  resp <- rcanvas:::canvas_query(url, args, "GET")
  resp = rcanvas:::paginate(resp) %>% purrr::map(httr::content, "text") %>% 
    purrr::map(jsonlite::fromJSON, flatten = TRUE)
  
  # Merge two responses together
  msg_data = dplyr::inner_join(resp[[1]]$view, resp[[1]]$participants, by = c("user_id" = "id"))

  # Remove html formatting for text
  msg_data$message = remove_html_tags(msg_data$message)
  
  # Release discussion thread information
  msg_data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant