File: post-block.R

package info (click to toggle)
r-cran-rtweet 1.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 18,224 kB
  • sloc: sh: 13; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,159 bytes parent folder | download
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
#' Blocking or unblocking twitter users
#'
#' `user_block(...)` blocks or unblocks a target twitter user.
#' `user_unblock(...)` is synonymous to `user_block(..., unblock=TRUE)`.
#'
#' @inheritParams get_timeline
#' @param unblock Logical indicating whether to unblock the intended
#'   friend.
#' @aliases user_unblock
#' @examples
#' if (auth_has_default()) {
#'   user_block("rtweet")
#'   user_unblock("rtweet")
#'   user_block("rtweet", unblock=TRUE) #<-same as the above
#' }
#' @export
#' @references
#' Block: <https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/post-blocks-create>
user_block <- function(user,
                      unblock = FALSE,
                      token = NULL) {

  stopifnot(is.atomic(user), is.logical(unblock))

  if (!unblock) {
    query <- "/1.1/blocks/create"
    params <- list()
  } else {
    query <- "/1.1/blocks/destroy"
    params <- list()
  }
  params[[user_type(user)]] <- user

  TWIT_post(token, query, params)
}


#' @rdname user_block
#' @export
user_unblock <- function(user, token = NULL) {
  user_block(user, unblock = TRUE, token = token)
}