File: ids.R

package info (click to toggle)
r-cran-rtweet 2.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,068 kB
  • sloc: sh: 13; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,063 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#' Extract the ids
#'
#' Extract the ids of the rtweet data if present.
#' Depending on the object type it returns either users ids,  tweet ids or rules ids.
#' @param x An object of the rtweet package.
#' @param ... Other arguments currently unused.
#' @export
ids <- function(x, ...) {
  UseMethod("ids")
}

#' @export
ids.default <- function(x, ...) {
  out <- x[["id_str"]]
  if (is.null(out)) {
    stop("Ids are not present. Are you sure this is a rtweet object?",
         call = caller_call())
  }
  out
}


#' @export
ids.rules <- function(x, ...) {
  rules(x)$id
}

#' @export
ids.users <- function(x, ...) {
  x$id_str
}

#' @export
ids.tweets <- function(x, ...) {
  x$id_str
}

#' @export
ids.followers <- function(x, ...) {
  x$from_id
}

#' @export
ids.friends <- function(x, ...) {
  x$to_id
}

#' @export
ids.page <- function(x, ...) {
  x$id
}

#' @export
ids.post_tweet <- function(x, ...) {
  if (httr::status_code(x) != 200L) {
    abort("Your message has not been posted!", call = caller_call())
  }
  cpt <- httr::content(x)
  cpt$id_str
}