Skip to content

Commit

Permalink
make default params be an empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
chainsawriot committed Nov 29, 2022
1 parent b6aeab4 commit f16ea73
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 79 deletions.
40 changes: 10 additions & 30 deletions R/accounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
#' }
#' @export
get_account <- function(id,instance = NULL, token = NULL, anonymous = FALSE, parse = TRUE){
path <- paste0("api/v1/accounts/",id)
params <- list()

process_request(token = token,path = path,instance = instance,
params = params, anonymous = anonymous,
process_request(token = token,path = paste0("api/v1/accounts/",id), instance = instance,
anonymous = anonymous,
parse = parse, FUN = parse_account)
}

Expand All @@ -31,10 +28,8 @@ get_account <- function(id,instance = NULL, token = NULL, anonymous = FALSE, par
#' }
#' @export
search_accounts <- function(query,limit = 40, token = NULL, anonymous = FALSE, parse = TRUE){
path <- "/api/v1/accounts/search"
params <- list(q=query,limit = limit)

process_request(token = token,path = path, instance = NULL,
process_request(token = token,path = "/api/v1/accounts/search", instance = NULL,
params = params, anonymous = anonymous,
parse = parse, FUN = v(parse_account))
}
Expand Down Expand Up @@ -145,7 +140,6 @@ get_account_following <- function(id,max_id,since_id,limit = 40L,
if (!missing(since_id)) {
params$since_id <- since_id
}

process_request(token = token,path = path,
params = params,
parse = parse, FUN = v(parse_account),
Expand All @@ -163,11 +157,7 @@ get_account_following <- function(id,max_id,since_id,limit = 40L,
#' }
#' @export
get_account_featured_tags <- function(id,token = NULL, parse = TRUE){
path <- paste0("api/v1/accounts/",id,"/featured_tags")
params <- list()

process_request(token = token,path = path,
params = params,
process_request(token = token,path = paste0("api/v1/accounts/",id,"/featured_tags"),
parse = parse, FUN = v(identity))
}

Expand All @@ -181,11 +171,7 @@ get_account_featured_tags <- function(id,token = NULL, parse = TRUE){
#' }
#' @export
get_account_lists <- function(id,token = NULL, parse = TRUE){
path <- paste0("api/v1/accounts/",id,"/lists")
params <- list()

process_request(token = token,path = path,
params = params,
process_request(token = token,path = paste0("api/v1/accounts/",id,"/lists"),
parse = parse, FUN = v(identity))
}

Expand All @@ -201,12 +187,10 @@ get_account_lists <- function(id,token = NULL, parse = TRUE){
#' }
#' @export
get_account_relationships <- function(ids,token = NULL, parse = TRUE){
path <- "/api/v1/accounts/relationships"
ids_lst <- lapply(ids,identity)
names(ids_lst) <- rep("id[]",length(ids_lst))
params <- ids_lst

process_request(token = token,path = path,
process_request(token = token, path = "/api/v1/accounts/relationships",
params = params,
parse = parse, FUN = v(identity))
}
Expand All @@ -228,7 +212,6 @@ get_account_bookmarks <- function(max_id,since_id,min_id,limit = 40L,
token = NULL, parse = TRUE,
retryonratelimit = TRUE,
verbose = TRUE){
path <- paste0("api/v1/bookmarks")
n <- limit
params <- list(limit = min(limit,40L))
if (!missing(max_id)) {
Expand All @@ -241,7 +224,7 @@ get_account_bookmarks <- function(max_id,since_id,min_id,limit = 40L,
params$since_id <- min_id
}

process_request(token = token,path = path,
process_request(token = token, path = "api/v1/bookmarks",
params = params,
parse = parse, FUN = v(parse_status),n = n,
page_size = 40L,retryonratelimit = retryonratelimit,
Expand All @@ -265,7 +248,6 @@ get_account_favourites <- function(max_id,min_id,limit = 40L,
token = NULL, parse = TRUE,
retryonratelimit = TRUE,
verbose = TRUE){
path <- paste0("api/v1/favourites")
n <- limit
params <- list(limit = min(limit,40L))
if (!missing(max_id)) {
Expand All @@ -275,7 +257,7 @@ get_account_favourites <- function(max_id,min_id,limit = 40L,
params$min_id <- min_id
}

process_request(token = token,path = path,
process_request(token = token,path = "api/v1/favourites",
params = params,
parse = parse, FUN = v(parse_status),n = n,
page_size = 40L,retryonratelimit = retryonratelimit,
Expand All @@ -298,7 +280,6 @@ get_account_blocks <- function(max_id,since_id,limit = 40L,
token = NULL, parse = TRUE,
retryonratelimit = TRUE,
verbose = TRUE){
path <- paste0("api/v1/blocks")
n <- limit
params <- list(limit = min(limit,40L))
if (!missing(max_id)) {
Expand All @@ -308,7 +289,7 @@ get_account_blocks <- function(max_id,since_id,limit = 40L,
params$since_id <- since_id
}

process_request(token = token,path = path,
process_request(token = token,path = "api/v1/blocks",
params = params,
parse = parse, FUN = v(parse_account), n = n,
page_size = 40L,retryonratelimit = retryonratelimit,
Expand All @@ -331,7 +312,6 @@ get_account_mutes <- function(max_id,since_id,limit = 40L,
token = NULL, parse = TRUE,
retryonratelimit = TRUE,
verbose = TRUE){
path <- paste0("api/v1/mutes")
n <- limit
params <- list(limit = min(limit,40L))
if (!missing(max_id)) {
Expand All @@ -341,7 +321,7 @@ get_account_mutes <- function(max_id,since_id,limit = 40L,
params$since_id <- since_id
}

process_request(token = token,path = path,
process_request(token = token,path = "api/v1/mutes",
params = params,
parse = parse, FUN = v(parse_account),
n = n, page_size = 40L, retryonratelimit = retryonratelimit,
Expand Down
25 changes: 8 additions & 17 deletions R/instances.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,24 @@ get_fedi_instances <- function(n = 20) {
#' }
#' @export
get_instance_general <- function(instance = NULL,token = NULL, anonymous = TRUE){
request_results <- make_get_request(token = token,path = "/api/v1/instance",
instance = instance,params = list(),
anonymous = anonymous)
request_results #TODO:format?
make_get_request(token = token,path = "/api/v1/instance",
instance = instance,
anonymous = anonymous) #TODO:format?
}

#' @rdname get_instance
#' @export
get_instance_peers <- function(instance = NULL,token = NULL, anonymous = TRUE){
request_results <- make_get_request(token = token,path = "/api/v1/instance/peers",
instance = instance,params = list(),
anonymous = anonymous)
instance = instance, anonymous = anonymous)
unlist(request_results)
}

#' @rdname get_instance
#' @export
get_instance_activity <- function(instance = NULL,token = NULL, anonymous = TRUE){
request_results <- make_get_request(token = token,path = "/api/v1/instance/activity",
instance = instance,params = list(),
anonymous = anonymous)

instance = instance, anonymous = anonymous)
tbl <- dplyr::bind_rows(request_results)
tbl <- dplyr::mutate(tbl,dplyr::across(dplyr::everything(),as.integer))
tbl$week <- as.POSIXct(tbl$week,origin="1970-01-01",tz = "UTC")
Expand All @@ -84,8 +80,7 @@ get_instance_activity <- function(instance = NULL,token = NULL, anonymous = TRUE
#' @export
get_instance_emoji <- function(instance = NULL,token = NULL, anonymous = TRUE){
request_results <- make_get_request(token = token,path = "/api/v1/custom_emojis",
instance = instance,params = list(),
anonymous = anonymous)
instance = instance, anonymous = anonymous)
dplyr::bind_rows(request_results)
}

Expand Down Expand Up @@ -120,21 +115,17 @@ get_instance_trends <- function(instance = NULL, token = NULL, limit = 10,anonym
#' @rdname get_instance
#' @export
get_instance_rules <- function(instance = NULL, token = NULL, anonymous = TRUE){
params <- list()
request_results <- make_get_request(token = token,path = "/api/v1/instance/rules",
instance = instance, params = params,
anonymous = anonymous)
instance = instance, anonymous = anonymous)
tbl <- dplyr::bind_rows(request_results)
tbl
}

#' @rdname get_instance
#' @export
get_instance_blocks <- function(instance = NULL, token = NULL, anonymous = TRUE){
params <- list()
request_results <- make_get_request(token = token,path = "api/v1/instance/domain_blocks",
instance = instance, params = params,
anonymous = anonymous)
instance = instance, anonymous = anonymous)
tbl <- dplyr::bind_rows(request_results)
tbl
}
Expand Down
38 changes: 8 additions & 30 deletions R/timelines_statuses.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,21 @@
#' }
#' @export
get_status <- function(id, instance = NULL, token = NULL, anonymous = FALSE, parse = TRUE) {

path <- paste0("/api/v1/statuses/", id)
params <- list()

process_request(token = token,path = path,instance = instance,params = params,
process_request(token = token,path = paste0("/api/v1/statuses/", id),instance = instance,
anonymous = anonymous,parse = parse,FUN = parse_status)
}

#' @rdname get_status
#' @export
get_reblogged_by <- function(id, instance = NULL, token = NULL, anonymous = FALSE, parse = TRUE) {
path <- paste0("/api/v1/statuses/", id, "/reblogged_by")
params <- list()

process_request(token = token,path = path,instance = instance,params = params,
process_request(token = token,path = paste0("/api/v1/statuses/", id, "/reblogged_by"),instance = instance,
anonymous = anonymous,parse = parse,FUN = v(parse_account))
}

#' @rdname get_status
#' @export
get_favourited_by <- function(id, instance = NULL, token = NULL, anonymous = FALSE, parse = TRUE) {
path <- paste0("/api/v1/statuses/", id, "/favourited_by")
params <- list()

process_request(token = token,path = path,instance = instance,params = params,
process_request(token = token,path = paste0("/api/v1/statuses/", id, "/favourited_by"),instance = instance,
anonymous = anonymous,parse = parse,FUN = v(parse_account))
}

Expand All @@ -57,12 +47,8 @@ get_favourited_by <- function(id, instance = NULL, token = NULL, anonymous = FAL
#' get_context(id = "109294719267373593", instance = "mastodon.social")
#' }
get_context <- function(id, instance = NULL, token = NULL, anonymous = FALSE, parse = TRUE) {
path <- paste0("/api/v1/statuses/", id, "/context")
params <- list()

process_request(token = token,path = path,instance = instance,params = params,
process_request(token = token,path = paste0("/api/v1/statuses/", id, "/context"),instance = instance,
anonymous = anonymous,parse = parse,FUN = parse_context)

}

#' View a poll
Expand All @@ -77,9 +63,7 @@ get_context <- function(id, instance = NULL, token = NULL, anonymous = FALSE, pa
#' get_poll(id = "105976")
#' }
get_poll <- function(id, instance = NULL, token = NULL, anonymous = FALSE, parse = TRUE) {
path <- paste0("/api/v1/polls/", id)

process_request(token = token,path = path,instance = instance,params = list(),
process_request(token = token,path = path <- paste0("/api/v1/polls/", id), instance = instance,
anonymous = anonymous,parse = parse,FUN = parse_poll)
}

Expand Down Expand Up @@ -124,9 +108,7 @@ get_timeline_public <- function(local = FALSE, remote = FALSE, only_media = FALS
if (!missing(min_id)) {
params$min_id <- min_id
}
path = "/api/v1/timelines/public"

process_request(token = token,path = path,instance = instance,params = params,
process_request(token = token,path = "/api/v1/timelines/public",instance = instance,params = params,
anonymous = anonymous,parse = parse,FUN = v(parse_status),
n = n, page_size = 40L,
retryonratelimit = retryonratelimit,
Expand Down Expand Up @@ -191,9 +173,7 @@ get_timeline_home <- function(local = FALSE, max_id, since_id, min_id, limit = 2
if (!missing(min_id)) {
params$min_id <- min_id
}
path = "/api/v1/timelines/home"

process_request(token = token,path = path,params = params,
process_request(token = token,path = "/api/v1/timelines/home", params = params,
parse = parse,FUN = v(parse_status),
n = n, page_size = 40L,
retryonratelimit = retryonratelimit,
Expand All @@ -220,9 +200,7 @@ get_timeline_list <- function(list_id, max_id, since_id, min_id,
if (!missing(min_id)) {
params$min_id <- min_id
}
path <- paste0("/api/v1/timelines/list/", list_id)

process_request(token = token,path = path,params = params,
process_request(token = token,path = paste0("/api/v1/timelines/list/", list_id), params = params,
parse = parse,FUN = v(parse_status),
n = n, page_size = 40L,
retryonratelimit = retryonratelimit,
Expand Down
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ print.rtoot_bearer <- function(x,...){
## https://docs.joinmastodon.org/methods/statuses/
## https://docs.joinmastodon.org/methods/timelines/

make_get_request <- function(token, path, params, instance = NULL, anonymous = FALSE, ...) {
make_get_request <- function(token, path, params = list(), instance = NULL, anonymous = FALSE, ...) {
if (is.null(instance) && anonymous) {
stop("provide either an instance or a token")
}
Expand Down Expand Up @@ -74,7 +74,7 @@ parse_header <- function(header){
process_request <- function(token = NULL,
path,
instance = NULL,
params,
params = list(),
anonymous = FALSE,
parse = TRUE,
FUN = identity,
Expand Down

0 comments on commit f16ea73

Please sign in to comment.