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

Add cu_token arg to api functions #20

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions R/api-attachments.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#' deduced from `attachment` when not provided (`NULL`).
#' @param ... Can be used to pass mime `type` argument to [httr::upload_file()],
#' mime type is guessed otherwise.
#' @param cu_token ClickUp personal access token or an access token from the OAuth flow.
#' The `CU_PAT` environment variable is used when `NULL`.
#'
#' @examples
#' \dontrun{
Expand Down
15 changes: 9 additions & 6 deletions R/api-authorization.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#' @param client_id Oauth app client id.
#' @param client_secret Oauth app client secret.
#' @param code Code given in redirect URL.
#' @param cu_token ClickUp personal access token or an access token from the OAuth flow.
#' The `CU_PAT` environment variable is used when `NULL`.
#'
#' @return
#'
Expand All @@ -32,20 +34,21 @@ NULL
## code
## Code given in redirect url
## String
cu_get_access_token <- function(client_id, client_secret, code) {
cu_get_access_token <- function(client_id, client_secret, code, cu_token = NULL) {
.cu_post("oauth", "token",
query=list(client_id=client_id,
client_secret=client_secret,
code=code))
code=code),
cu_token = cu_token)
}


#' @export
#' @rdname api-authorization
## Authorization / Get Authorized User
## GET https://api.clickup.com/api/v2/user
cu_get_authorized_user <- function() {
.cu_get("user")
cu_get_authorized_user <- function(cu_token = NULL) {
.cu_get("user", cu_token = cu_token)
}


Expand All @@ -56,6 +59,6 @@ cu_get_authorized_user <- function() {
##
## Note: this is the same endpoint as for cu_get_teams
##
cu_get_authorized_teams <- function() {
.cu_get("team")
cu_get_authorized_teams <- function(cu_token = NULL) {
.cu_get("team", cu_token = cu_token)
}
30 changes: 18 additions & 12 deletions R/api-checklists.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#' @param checklist_item_id Checklist item ID.
#' @param ... Named arguments to be passed to API request body,
#' see the ClickUp API documentation (<https://clickup.com/api>).
#' @param cu_token ClickUp personal access token or an access token from the OAuth flow.
#' The `CU_PAT` environment variable is used when `NULL`.
#'
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -49,10 +51,11 @@ NULL
## Checklists / Create Checklist
## POST https://api.clickup.com/api/v2/task/task_id/checklist
## task_id Example: 9hz. String
cu_create_checklist <- function(task_id, name) {
cu_create_checklist <- function(task_id, name, cu_token = NULL) {
task_id <- cu_task_id(task_id)
.cu_post("task", task_id, "checklist",
body=list(name = name))
body=list(name = name),
cu_token = cu_token)
}
#cu_create_checklist("8ach57", "New checklist")

Expand All @@ -68,9 +71,10 @@ cu_create_checklist <- function(task_id, name) {
## position is the zero-based index of the order you want the checklist
## to exist on the task. If you want the checklist to be in the first
## position, pass '{ "position": 0 }'
cu_edit_checklist <- function(checklist_id, position) {
cu_edit_checklist <- function(checklist_id, position, cu_token = NULL) {
.cu_put("checklist", checklist_id,
body=list(position = position))
body=list(position = position),
cu_token = cu_token)
}
#cu_edit_checklist("4bc57892-a1a6-44f4-894d-d98de71f4054", 0)

Expand All @@ -82,8 +86,8 @@ cu_edit_checklist <- function(checklist_id, position) {
## checklist_id
## b8a8-48d8-a0c6-b4200788a683 (uuid)
## Example: b955c4dc. String
cu_delete_checklist <- function(checklist_id) {
.cu_delete("checklist", checklist_id)
cu_delete_checklist <- function(checklist_id, cu_token = NULL) {
.cu_delete("checklist", checklist_id, cu_token = cu_token)
}
#cu_delete_checklist("4bc57892-a1a6-44f4-894d-d98de71f4054")

Expand All @@ -104,9 +108,10 @@ cu_delete_checklist <- function(checklist_id) {
## "resolved": true,
## "parent": null
## }
cu_create_checklist_item <- function(checklist_id, name, ...) {
cu_create_checklist_item <- function(checklist_id, name, ..., cu_token = NULL) {
.cu_post("checklist", checklist_id, "checklist_item",
body=list(name = name, ...))
body=list(name = name, ...),
cu_token = cu_token)
}
#cu_create_checklist_item("40146d1e-efe5-4140-a0ba-ad39c9dec18c",
# name="New item 1")
Expand All @@ -133,9 +138,10 @@ cu_create_checklist_item <- function(checklist_id, name, ...) {
##
## parent is another checklist item that you want to nest the
## target checklist item underneath.
cu_edit_checklist_item <- function(checklist_id, checklist_item_id, ...) {
cu_edit_checklist_item <- function(checklist_id, checklist_item_id, ..., cu_token = NULL) {
.cu_put("checklist", checklist_id, "checklist_item", checklist_item_id,
body=list(...))
body=list(...),
cu_token = cu_token)
}
#cu_put_edit_checklist_item("40146d1e-efe5-4140-a0ba-ad39c9dec18c",
# "8849fcba-9db4-4400-a78e-cfced2ae6ce0",
Expand All @@ -155,8 +161,8 @@ cu_edit_checklist_item <- function(checklist_id, checklist_item_id, ...) {
## e491-47f5-9fd8-d1dc4cedcc6f (uuid)
## Example: 21e08dc8.
## String
cu_delete_checklist_item <- function(checklist_id, checklist_item_id) {
.cu_delete("checklist", checklist_id, "checklist_item", checklist_item_id)
cu_delete_checklist_item <- function(checklist_id, checklist_item_id, cu_token = NULL) {
.cu_delete("checklist", checklist_id, "checklist_item", checklist_item_id, cu_token = cu_token)
}
#cu_delete_checklist_item("40146d1e-efe5-4140-a0ba-ad39c9dec18c",
# "8849fcba-9db4-4400-a78e-cfced2ae6ce0")
Expand Down
38 changes: 22 additions & 16 deletions R/api-comments.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' @param comment_id Comment ID.
#' @param ... Named arguments to be passed to API request body,
#' see the ClickUp API documentation (<https://clickup.com/api>).
#' @param cu_token ClickUp personal access token or an access token from the OAuth flow.
#' The `CU_PAT` environment variable is used when `NULL`.
#'
#' @return
#'
Expand Down Expand Up @@ -35,10 +37,11 @@ NULL
## "assignee": 183,
## "notify_all": true
## }
cu_post_task_comment <- function(task_id, ...) {
cu_post_task_comment <- function(task_id, ..., cu_token = NULL) {
task_id <- cu_task_id(task_id)
.cu_post("task", task_id, "comment",
body=list(...))
body=list(...),
cu_token = cu_token)
}


Expand All @@ -60,9 +63,10 @@ cu_post_task_comment <- function(task_id, ...) {
## "comment_text": "View comment content",
## "notify_all": true
## }
cu_post_view_comment <- function(view_id, ...) {
cu_post_view_comment <- function(view_id, ..., cu_token = NULL) {
.cu_post("view", view_id, "comment",
body=list(...))
body=list(...),
cu_token = cu_token)
}


Expand All @@ -84,9 +88,10 @@ cu_post_view_comment <- function(view_id, ...) {
## "assignee": 183,
## "notify_all": true
## }
cu_post_list_comment <- function(list_id, ...) {
cu_post_list_comment <- function(list_id, ..., cu_token = NULL) {
.cu_post("list", list_id, "comment",
body=list(...))
body=list(...),
cu_token = cu_token)
}


Expand All @@ -97,9 +102,9 @@ cu_post_list_comment <- function(list_id, ...) {
## task_id
## Example: 9hz.
## String
cu_get_task_comments <- function(task_id) {
cu_get_task_comments <- function(task_id, cu_token = NULL) {
task_id <- cu_task_id(task_id)
.cu_get("task", task_id, "comment")
.cu_get("task", task_id, "comment", cu_token = cu_token)
}


Expand All @@ -111,8 +116,8 @@ cu_get_task_comments <- function(task_id) {
## 105 (string)
## Example: 3c.
## String
cu_get_view_comments <- function(view_id) {
.cu_get("view", view_id, "comment")
cu_get_view_comments <- function(view_id, cu_token = NULL) {
.cu_get("view", view_id, "comment", cu_token = cu_token)
}


Expand All @@ -123,8 +128,8 @@ cu_get_view_comments <- function(view_id) {
## list_id
## Example: 124.
## Number
cu_get_list_comments <- function(list_id) {
.cu_get("list", list_id, "comment")
cu_get_list_comments <- function(list_id, cu_token = NULL) {
.cu_get("list", list_id, "comment", cu_token = cu_token)
}


Expand All @@ -143,9 +148,10 @@ cu_get_list_comments <- function(list_id) {
## "assignee": 183,
## "resolved": true
## }
cu_put_update_comment <- function(comment_id, ...) {
cu_put_update_comment <- function(comment_id, ..., cu_token = NULL) {
.cu_put("comment", comment_id,
body=list(...))
body=list(...),
cu_token = cu_token)
}


Expand All @@ -156,6 +162,6 @@ cu_put_update_comment <- function(comment_id, ...) {
## comment_id
## Example: 456.
## Number
cu_delete_comment <- function(comment_id) {
.cu_delete("comment", comment_id)
cu_delete_comment <- function(comment_id, cu_token = NULL) {
.cu_delete("comment", comment_id, cu_token = cu_token)
}
15 changes: 9 additions & 6 deletions R/api-customfields.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#' The accessible fields can be found on the task object from the
#' [cu_get_task()] route. This is where you can retrieve the `field_id`.
#' see the ClickUp API documentation (<https://clickup.com/api>).
#' @param cu_token ClickUp personal access token or an access token from the OAuth flow.
#' The `CU_PAT` environment variable is used when `NULL`.
#'
#' @return
#'
Expand All @@ -26,8 +28,8 @@ NULL
## list_id
## Example: 123.
## Number
cu_get_accessible_custom_fields <- function(list_id) {
.cu_get("list", list_id, "field")
cu_get_accessible_custom_fields <- function(list_id, cu_token = NULL) {
.cu_get("list", list_id, "field", cu_token = cu_token)
}


Expand All @@ -54,10 +56,11 @@ cu_get_accessible_custom_fields <- function(list_id) {
## "value": 80
## }
#cu_set_custom_field_value
cu_set_custom_field_value <- function(task_id, field_id, ...) {
cu_set_custom_field_value <- function(task_id, field_id, ..., cu_token = NULL) {
task_id <- cu_task_id(task_id)
.cu_post("task", task_id, "field", field_id,
body=list(...))
body=list(...),
cu_token = cu_token)
}


Expand All @@ -77,7 +80,7 @@ cu_set_custom_field_value <- function(task_id, field_id, ...) {
##
## The accessible fields can be found on the task object from the
## get task route. This is where you can retrieve the field_id
cu_remove_field_value <- function(task_id, field_id) {
cu_remove_field_value <- function(task_id, field_id, cu_token = NULL) {
task_id <- cu_task_id(task_id)
.cu_delete("task", task_id, "field", field_id)
.cu_delete("task", task_id, "field", field_id, cu_token = cu_token)
}
18 changes: 10 additions & 8 deletions R/api-dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' @param dependency_of A blocking dependency of the task.
#' One and only one of `depends_on` or `dependency_of` must be passed.
#' @param links_to Link to another task.
#' @param cu_token ClickUp personal access token or an access token from the OAuth flow.
#' The `CU_PAT` environment variable is used when `NULL`.
#'
#' @return
#'
Expand All @@ -34,7 +36,7 @@ NULL
## {
## "depends_on": "9hw"
## }
cu_add_dependency <- function(task_id, depends_on, dependency_of) {
cu_add_dependency <- function(task_id, depends_on, dependency_of, cu_token = NULL) {
task_id <- cu_task_id(task_id)
if (missing(depends_on) && missing(dependency_of))
stop("Provide one of depends_on or dependency_of", call.=FALSE)
Expand All @@ -45,7 +47,7 @@ cu_add_dependency <- function(task_id, depends_on, dependency_of) {
if (missing(depends_on) && !missing(dependency_of))
body <- list(dependency_of=dependency_of)
.cu_post("task", task_id, "dependency",
body=body)
body=body, cu_token = cu_token)
}


Expand All @@ -68,7 +70,7 @@ cu_add_dependency <- function(task_id, depends_on, dependency_of) {
##
## One and only one of depends_on or dependency_of must be passed in the
## query params.
cu_delete_dependency <- function(task_id, depends_on, dependency_of) {
cu_delete_dependency <- function(task_id, depends_on, dependency_of, cu_token = NULL) {
task_id <- cu_task_id(task_id)
if (missing(depends_on) && missing(dependency_of))
stop("Provide one of depends_on or dependency_of", call.=FALSE)
Expand All @@ -79,7 +81,7 @@ cu_delete_dependency <- function(task_id, depends_on, dependency_of) {
if (missing(depends_on) && !missing(dependency_of))
query <- list(dependency_of=dependency_of)
.cu_delete("task", task_id, "dependency",
query=query)
query=query, cu_token = cu_token)
}


Expand All @@ -95,9 +97,9 @@ cu_delete_dependency <- function(task_id, depends_on, dependency_of) {
## links_to
## Example: 9hz.
## String
cu_add_task_link <- function(task_id, links_to) {
cu_add_task_link <- function(task_id, links_to, cu_token = NULL) {
task_id <- cu_task_id(task_id)
.cu_post("task", task_id, "link", links_to)
.cu_post("task", task_id, "link", links_to, cu_token = cu_token)
}


Expand All @@ -113,7 +115,7 @@ cu_add_task_link <- function(task_id, links_to) {
## links_to
## Example: 9hz.
## String
cu_delete_task_link <- function(task_id, links_to) {
cu_delete_task_link <- function(task_id, links_to, cu_token = NULL) {
task_id <- cu_task_id(task_id)
.cu_delete("task", task_id, "link", links_to)
.cu_delete("task", task_id, "link", links_to, cu_token = cu_token)
}
Loading
Loading