File: direct_messages.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 (100 lines) | stat: -rw-r--r-- 3,262 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
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
89
90
91
92
93
94
95
96
97
98
99
100
#' Get direct messages sent to and received by the authenticating user from the
#' past 30 days
#'
#' Returns all Direct Message events (both sent and received) within the last 30
#' days. Sorted in reverse-chronological order. Includes detailed information 
#' about the sender and recipient. 
#'
#' @inheritParams TWIT_paginate_cursor
#' @param next_cursor `r lifecycle::badge("deprecated")` Use `cursor` instead.
#' @return A list with one element for each page of results.
#' @examples
#' \dontrun{
#'
#' ## get my direct messages
#' dms <- direct_messages()
#'
#' ## inspect data structure
#' str(dms)
#'
#' }
#' @export
#' @references <https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/list-events>
direct_messages <- function(n = 50,
                            cursor = NULL,
                            next_cursor = NULL,
                            parse = TRUE,
                            token = NULL,
                            retryonratelimit = NULL,
                            verbose = TRUE) {
  
  if (!is.null(next_cursor)) {
    lifecycle::deprecate_warn("1.0.0", 
      "direct_messages(next_cursor)", 
      "direct_messages(cursor)"
    )
    cursor <- next_cursor
  }
  
  TWIT_paginate_cursor(token, "/1.1/direct_messages/events/list", list(), 
    n = n,
    cursor = cursor,
    retryonratelimit = retryonratelimit,
    verbose = verbose,
    page_size = if (n >= 50) 50 else n,
    get_id = function(x) x$events$id
  )
}

#' (DEPRECATED) Get the most recent direct messages sent to the authenticating user.
#'
#' Retrieves up to 200 of the most recently received direct messages
#' by the authenticating (home) user. This function requires access
#' token with read, write, and direct messages access.
#'
#' @return Return object converted to nested list. If status code of
#'   response object is not 200, the response object is returned
#'   directly.
#' @examples
#'
#' \dontrun{
#'
#' ## get my direct messages
#' dms <- direct_messages_received()
#'
#' ## inspect data structure
#' str(dms)
#'
#' ## get direct messages I've sent
#' sdms <- direct_messages_sent()
#'
#' ## inspect data structure
#' str(dms)
#'
#' }
#'
#' @details Includes detailed information about the sender and
#'   recipient user. You can request up to 200 direct messages per
#'   call, and only the most recent 200 direct messages will be available using
#'   this endpoint.
#' @export
#' @keywords internal
direct_messages_received <- function(since_id = NULL,
                                     max_id = NULL,
                                     n = 200,
                                     parse = TRUE,
                                     token = NULL) {
  stop("The endpoint for `direct_messages_received()` no longer exists. ",
    "Please use `direct_messages()` instead.")
}

#' @export
#' @rdname direct_messages_received
direct_messages_sent <- function(since_id = NULL,
                                 max_id = NULL,
                                 n = 200,
                                 parse = TRUE,
                                 token = NULL) {
  stop("The endpoint for `direct_messages_received()` no longer exists. ",
    "Please use `direct_messages()` instead.")
}