This repository has been archived by the owner on Jul 17, 2023. It is now read-only.
/
attachment.R
88 lines (83 loc) · 2.93 KB
/
attachment.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Copyright (C) 2019 LINE Corporation
#
# conflr is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, version 3.
#
# conflr is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See <http://www.gnu.org/licenses/> for more details.
#' CRUD Operations for Attachments on Content
#'
#' @name confl_attachment
#' @param id
#' The ID of a page that attachments belong to.
#' @param filename
#' Filter parameter to return only the Attachment with the matching file name. Optional.
#' @param mediaType
#' Filter parameter to return only Attachments with a matching Media-Type. Optional.
#' @inheritParams confl_content
#'
#' @return
#' The API response as a list.
#'
#' @examples
#' \dontrun{
#' # Create a dummy text file
#' tmp_txt <- tempfile(fileext = ".txt")
#' cat("foo", file = tmp_txt)
#'
#' # Upload the file to a page whose ID is "123"
#' confl_post_attachment("123", tmp_txt)
#'
#' # Confirm the file is attatched to the page
#' result <- confl_list_attachments("123", filename = basename(tmp_txt))
#' length(result$results) # should be 1
#' }
#'
#' @export
confl_list_attachments <- function(id,
filename = NULL,
mediaType = NULL,
start = 0,
limit = 50,
expand = NULL) {
id <- as.character(id)
query <- list(limit = limit, start = start, filename = filename, mediaType = mediaType, expand = expand)
res <- confl_verb("GET", glue("/content/{id}/child/attachment"),
query = purrr::compact(query)
)
httr::content(res)
}
#' @rdname confl_attachment
#' @param path Path to a file to upload.
#' @export
confl_post_attachment <- function(id, path, minor_edit = FALSE) {
id <- as.character(id)
res <- confl_verb("POST", glue("/content/{id}/child/attachment"),
body = list(file = httr::upload_file(path), minorEdit = minor_edit),
httr::add_headers(`X-Atlassian-Token` = "nocheck")
)
httr::content(res)
}
#' @rdname confl_attachment
#' @param attachmentId The ID of an attachment.
#' @param ... Other arguments passed to 'query'.
#' @export
confl_update_attachment_metadata <- function(id, attachmentId, ...) {
id <- as.character(id)
res <- confl_verb("PUT", glue("/content/{id}/child/attachment/{attachmentId}"),
query = list(...)
)
httr::content(res)
}
#' @rdname confl_attachment
#' @export
confl_update_attachment_data <- function(id, attachmentId, path, ..., minor_edit = FALSE) {
id <- as.character(id)
res <- confl_verb("POST", glue("/content/{id}/child/attachment/{attachmentId}/data"),
body = list(file = httr::upload_file(path), minorEdit = minor_edit),
httr::add_headers(`X-Atlassian-Token` = "nocheck")
)
httr::content(res)
}