Skip to content

Commit

Permalink
Merge pull request #150 from mrkaye97/slackr-230
Browse files Browse the repository at this point in the history
slackr 2.3.0
  • Loading branch information
mrkaye97 authored Apr 17, 2021
2 parents aa569be + 1be95dc commit 03cdad6
Show file tree
Hide file tree
Showing 60 changed files with 1,056 additions and 509 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master

name: R-CMD-check
Expand All @@ -34,7 +32,6 @@ jobs:
- {os: ubuntu-16.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.4', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.3', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
Expand Down
2 changes: 0 additions & 2 deletions CRAN-RELEASE

This file was deleted.

2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: slackr
Type: Package
Title: Send Messages, Images, R Objects and Files to 'Slack' Channels/Users
Version: 2.2.0
Version: 2.3.0
Date: 2021-03-03
Author: Bob Rudis [aut, cre], Jay Jacobs [ctb], David Severski [ctb],
Quinn Weber [ctb], Konrad Karczewski [ctb], Shinya Uryu [ctb],
Expand Down
7 changes: 6 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export(auth_test)
export(call_slack_api)
export(convert_response_to_tibble)
export(create_config_file)
export(dev.slackr)
export(dev_slackr)
export(ggslackr)
Expand All @@ -22,15 +23,18 @@ export(slackrUsers)
export(slackr_bot)
export(slackr_channels)
export(slackr_chtrans)
export(slackr_csv)
export(slackr_delete)
export(slackr_dev)
export(slackr_history)
export(slackr_ims)
export(slackr_msg)
export(slackr_save)
export(slackr_setup)
export(slackr_teardown)
export(slackr_tex)
export(slackr_upload)
export(slackr_users)
export(tex_slackr)
export(textSlackr)
export(text_slackr)
export(with_pagination)
Expand Down Expand Up @@ -66,3 +70,4 @@ importFrom(memoise,memoise)
importFrom(tibble,as_tibble)
importFrom(tibble,tibble)
importFrom(utils,URLencode)
importFrom(utils,write.csv)
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# slackr 2.3.0

* Adds `slackr_csv()`, which simplifies the process of writing data frames to Slack as csv files
* Adds `slackr_teardown()`, which reverts the changes made by `slackr_setup()` by unsetting the environment variables
* Adds `create_config_file()` to simplify the process of setting up a config file
* `save_slackr()` is now deprecated in favor of `slackr_save()` and `tex_slackr()` has been deprecated in favor of `slackr_tex()`

# slackr 2.2.0

* Gets rid of the usage of `slackr_chtrans()` in the vast majority of functions, significantly speeding up `slackr_***()` by limiting API requests
Expand Down
33 changes: 16 additions & 17 deletions R/call_slack_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ stop_for_status <- function(r) {
# note that httr::stop_for_status should be called explicitly

httr::stop_for_status(r)
cr <- content(r)
cr <- content(r, encoding = "UTF-8")

# A response code of 200 doesn't mean everything is ok, so check if the
# response is not ok
Expand All @@ -26,7 +26,7 @@ stop_for_status <- function(r) {
cr$ok <- NULL
cr$error <- NULL
additional_msg <- paste(
sapply(seq_along(cr), function(i)paste(names(cr)[i], ":=", unname(cr)[i])),
sapply(seq_along(cr), function(i) paste(names(cr)[i], ":=", unname(cr)[i])),
collapse = "\n"
)
warning(
Expand Down Expand Up @@ -80,33 +80,32 @@ with_retry <- function(fun) {
#' @export
#'
call_slack_api <- function(
path, ..., body = NULL, .method = c("GET", "POST"),
bot_user_oauth_token,
.verbose = Sys.getenv("SLACKR_VERBOSE", "FALSE"),
.next_cursor = ""

) {
path, ..., body = NULL, .method = c("GET", "POST"),
bot_user_oauth_token,
.verbose = Sys.getenv("SLACKR_VERBOSE", "FALSE"),
.next_cursor = "") {
if (missing(bot_user_oauth_token) || is.null(bot_user_oauth_token)) {
bot_user_oauth_token <- Sys.getenv("SLACK_BOT_USER_OAUTH_TOKEN", "")
}
if (is.null(bot_user_oauth_token) || bot_user_oauth_token == "") {
warning("Provide a value for bot_user_oauth_token",
immediate. = TRUE,
call. = FALSE)
immediate. = TRUE,
call. = FALSE
)
}
url <- "https://slack.com"
.method <- match.arg(.method)

# Set locale to C (POSIX)
loc <- Sys.getlocale('LC_CTYPE')
Sys.setlocale('LC_CTYPE','C')
loc <- Sys.getlocale("LC_CTYPE")
Sys.setlocale("LC_CTYPE", "C")
on.exit(Sys.setlocale("LC_CTYPE", loc))

# Make verbose call if env var is set
if (.verbose == "TRUE") {
old_config <- set_config(verbose())
on.exit(set_config(old_config), add = TRUE)
} #else {
} # else {
# set_config(httr::verbose(data_out = FALSE, data_in = FALSE, info = FALSE, ssl = FALSE))
# }

Expand Down Expand Up @@ -140,7 +139,7 @@ call_slack_api <- function(
}


add_cursor_get = function(..., .next_cursor = "") {
add_cursor_get <- function(..., .next_cursor = "") {
z <- list(...)
if (!is.null(.next_cursor) && .next_cursor != "") {
# message("Appending cursor to query")
Expand All @@ -149,7 +148,7 @@ add_cursor_get = function(..., .next_cursor = "") {
z
}

add_cursor_post = function(..., .next_cursor = "") {
add_cursor_post <- function(..., .next_cursor = "") {
z <- list(...)[[1]]
if (!is.null(.next_cursor) && .next_cursor != "") {
message("Appending cursor to query")
Expand Down Expand Up @@ -191,7 +190,7 @@ with_pagination <- function(fun, extract) {
done <- FALSE
old_cursor <- ""
next_cursor <- ""
result = NA
result <- NA
had_to_cursor <- FALSE
while (!done) {
# make the api call
Expand Down Expand Up @@ -219,7 +218,7 @@ with_pagination <- function(fun, extract) {
)
}
}
if(had_to_cursor) message("")
if (had_to_cursor) message("")
result
}

Expand Down
49 changes: 23 additions & 26 deletions R/call_slack_internals.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,26 @@ list_users <- function(bot_user_oauth_token = Sys.getenv("SLACK_BOT_USER_OAUTH_T
#'
#' @references https://api.slack.com/methods/chat.postMessage
post_message <- function(
txt,
channel,
emoji = "",
username = Sys.getenv("SLACK_USERNAME"),
bot_user_oauth_token = Sys.getenv("SLACK_BOT_USER_OAUTH_TOKEN"),
...)
{
txt,
channel,
emoji = "",
username = Sys.getenv("SLACK_USERNAME"),
bot_user_oauth_token = Sys.getenv("SLACK_BOT_USER_OAUTH_TOKEN"),
...) {
z <-
call_slack_api(
"/api/chat.postMessage",
.method = POST,
bot_user_oauth_token = bot_user_oauth_token,
body = list(
text = txt,
channel = channel,
username = username,
link_names = 1,
icon_emoji = emoji,
...
"/api/chat.postMessage",
.method = POST,
bot_user_oauth_token = bot_user_oauth_token,
body = list(
text = txt,
channel = channel,
username = username,
link_names = 1,
icon_emoji = emoji,
...
)
)
)

invisible(content(z))
}
Expand All @@ -107,13 +106,12 @@ post_message <- function(
#'
#' @references https://api.slack.com/methods/files.upload
files_upload <- function(
file,
channel,
txt = "",
username = Sys.getenv("SLACK_USERNAME"),
bot_user_oauth_token = Sys.getenv("SLACK_BOT_USER_OAUTH_TOKEN"),
...)
{
file,
channel,
txt = "",
username = Sys.getenv("SLACK_USERNAME"),
bot_user_oauth_token = Sys.getenv("SLACK_BOT_USER_OAUTH_TOKEN"),
...) {
z <- call_slack_api(
"/api/files.upload",
.method = POST,
Expand All @@ -138,4 +136,3 @@ list_scopes <- function(bot_user_oauth_token = Sys.getenv("SLACK_BOT_USER_OAUTH_
)
invisible(content(z))
}

51 changes: 38 additions & 13 deletions R/deprecated.r
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @seealso \code{\link[slackr]{slackr_dev}}
#' @family Deprecated functions
dev.slackr <- function(...) {
.Deprecated(new = 'slackr_dev')
.Deprecated(new = "slackr_dev")
slackr_dev(...)
}

Expand All @@ -22,7 +22,7 @@ dev.slackr <- function(...) {
#' @seealso \code{\link[slackr]{slackr_dev}}
#' @family Deprecated functions
dev_slackr <- function(...) {
.Deprecated(new = 'slackr_dev')
.Deprecated(new = "slackr_dev")
slackr_dev(...)
}

Expand All @@ -35,10 +35,23 @@ dev_slackr <- function(...) {
#' @family Deprecated functions
#' @seealso \code{\link[slackr]{save_slackr}}
save.slackr <- function(...) {
.Deprecated(new = 'save_slackr')
.Deprecated(new = "save_slackr")
save_slackr(...)
}

#' Superseded by slackr_save
#'
#' deprecated
#'
#' @param ... arguments to pass to slackr_save
#' @export
#' @seealso \code{\link[slackr]{slackr_save}}
#' @family Deprecated functions
save_slackr <- function(...) {
.Deprecated(new = "slackr_save")
slackr_save(...)
}

#' Superseded by slackr_bot
#'
#' deprecated
Expand All @@ -48,7 +61,7 @@ save.slackr <- function(...) {
#' @family Deprecated functions
#' @seealso \code{\link[slackr]{slackr_bot}}
slackrBot <- function(...) {
.Deprecated(new = 'slackr_bot')
.Deprecated(new = "slackr_bot")
slackr_bot(...)
}

Expand All @@ -61,7 +74,7 @@ slackrBot <- function(...) {
#' @seealso \code{\link[slackr]{slackr_chtrans}}
#' @family Deprecated functions
slackrChtrans <- function(...) {
.Deprecated(new = 'slackr_chtrans')
.Deprecated(new = "slackr_chtrans")
slackr_chtrans(...)
}

Expand All @@ -74,7 +87,7 @@ slackrChtrans <- function(...) {
#' @seealso \code{\link[slackr]{slackr_chtrans}}
#' @family Deprecated functions
slackrChTrans <- function(...) {
.Deprecated(new = 'slackr_chtrans')
.Deprecated(new = "slackr_chtrans")
slackr_chtrans(...)
}

Expand All @@ -87,7 +100,7 @@ slackrChTrans <- function(...) {
#' @family Deprecated functions
#' @seealso \code{\link[slackr]{slackr_channels}}
slackrChannels <- function(...) {
.Deprecated(new = 'slackr_channels')
.Deprecated(new = "slackr_channels")
slackr_channels(...)
}

Expand All @@ -100,7 +113,7 @@ slackrChannels <- function(...) {
#' @family Deprecated functions
#' @seealso \code{\link[slackr]{slackr_ims}}
slackrIms <- function(...) {
.Deprecated(new = 'slackr_ims')
.Deprecated(new = "slackr_ims")
slackr_ims(...)
}

Expand All @@ -113,7 +126,7 @@ slackrIms <- function(...) {
#' @seealso \code{\link[slackr]{slackr_msg}}
#' @family Deprecated functions
slackrMsg <- function(...) {
.Deprecated(new = 'slackr_msg')
.Deprecated(new = "slackr_msg")
slackr_msg(...)
}

Expand All @@ -126,7 +139,7 @@ slackrMsg <- function(...) {
#' @family Deprecated functions
#' @seealso \code{\link[slackr]{slackr_setup}}
slackrSetup <- function(...) {
.Deprecated(new = 'slackr_setup')
.Deprecated(new = "slackr_setup")
slackr_setup(...)
}

Expand All @@ -139,7 +152,7 @@ slackrSetup <- function(...) {
#' @seealso \code{\link[slackr]{slackr_upload}}
#' @family Deprecated functions
slackrUpload <- function(...) {
.Deprecated(new = 'slackr_upload')
.Deprecated(new = "slackr_upload")
slackr_upload(...)
}

Expand All @@ -152,7 +165,7 @@ slackrUpload <- function(...) {
#' @seealso \code{\link[slackr]{slackr_users}}
#' @family Deprecated functions
slackrUsers <- function(...) {
.Deprecated(new = 'slackr_users')
.Deprecated(new = "slackr_users")
slackr_users(...)
}

Expand All @@ -165,6 +178,18 @@ slackrUsers <- function(...) {
#' @seealso \code{\link[slackr]{slackr_msg}}
#' @family Deprecated functions
textSlackr <- function(...) {
.Deprecated(new = 'slackr_msg')
.Deprecated(new = "slackr_msg")
text_slackr(...)
}

#' Superseded by slackr_tex
#'
#' deprecated
#'
#' @param ... arguments to pass to slackr_tex
#' @seealso \code{\link[slackr]{slackr_tex}}
#' @family Deprecated functions
tex_slackr <- function(...) {
.Deprecated(new = 'slackr_tex')
slackr_tex(...)
}
Loading

0 comments on commit 03cdad6

Please sign in to comment.