Skip to content

Commit

Permalink
Vectorized version of osm_delete_gpx()
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaspons committed Jun 13, 2024
1 parent dbb3a3f commit 8401ef1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
37 changes: 37 additions & 0 deletions R/osm_delete_note.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Vectorized version of .osm_delete_note()

#' Delete notes
#'
#' Hide (delete) notes. This request needs to be done as an authenticated user with moderator role.
#'
#' @param note_id Note ids represented by a numeric or a character vector.
#' @param text A non-mandatory comment as text.
#'
#' @details Use [osm_reopen_note()] to make the note visible again.
#'
#' @return Returns a data frame with the hided map notes (same format as [osm_get_notes()] with `format = "R"`).
#' @family edit notes' functions
#' @family functions for moderators
#' @export
#'
#' @examples
#' \dontrun{
#' set_osmapi_connection("testing") # use the testing server
#' note <- osm_create_note(lat = "40.7327375", lon = "0.1702526", text = "Test note to delete.")
#' del_note <- osm_delete_note(note_id = note$id, text = "Hide note")
#' del_note
#' }
osm_delete_note <- function(note_id, text) { # TODO: , format = c("R", "xml", "json")
if (missing(text)) {
out <- lapply(note_id, function(id) .osm_delete_note(note_id = id))
} else {
if (length(text) != 1 || length(text) != length(note_id)) {
stop("`text` must have the same length as `note_id` or a length of 1 (the same message for all notes).")
}
out <- .mapply(.osm_delete_note, dots = list(note_id = note_id, text = text), MoreArgs = NULL)
}

out <- do.call(rbind, out)

return(out)
}
8 changes: 4 additions & 4 deletions R/osmapi_map_notes.R
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,9 @@ osm_create_comment_note <- function(note_id, text) { # TODO: , format = c("R", "
#' @details Use [osm_reopen_note()] to make the note visible again.
#'
#' @return Returns a data frame with the hided map note (same format as [osm_get_notes()] with `format = "R"`).
#' @family edit notes' functions
#' @family functions for moderators
#' @export
# @family edit notes' functions
# @family functions for moderators
#' @noRd
#'
#' @examples
#' \dontrun{
Expand All @@ -565,7 +565,7 @@ osm_create_comment_note <- function(note_id, text) { # TODO: , format = c("R", "
#' del_note <- osm_delete_note(note_id = note$id, text = "Hide note")
#' del_note
#' }
osm_delete_note <- function(note_id, text) { # TODO: , format = c("R", "xml", "json")
.osm_delete_note <- function(note_id, text) { # TODO: , format = c("R", "xml", "json")
req <- osmapi_request(authenticate = TRUE)
req <- httr2::req_method(req, "DELETE")
req <- httr2::req_url_path_append(req, "notes", note_id)
Expand Down
10 changes: 5 additions & 5 deletions man/osm_delete_note.Rd

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

0 comments on commit 8401ef1

Please sign in to comment.