Skip to content

Commit

Permalink
Fix bugs with sending messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jimhester committed Oct 8, 2015
1 parent 473b4e6 commit 4c07595
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Imports:
base64enc,
magrittr,
jsonlite,
mime
mime,
argufy
Suggests:
testthat,
knitr,
argufy
knitr
Remotes:
gaborcsardi/argufy
License: MIT + file LICENSE
Expand Down
5 changes: 4 additions & 1 deletion R/gmailr.R
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,16 @@ print.gmail_thread <- print.gmail_message
#' @export
print.gmail_threads <- print.gmail_message

.last_response <- list()

gmailr_query <- function(fun, location, user_id, class = NULL, ...) {
req <- fun(gmail_path(user_id, location),
config(token = get_token()),
...)
.last_response <<- content(req, "parsed")
stop_for_status(req)
res <- .last_response

res <- content(req, "parsed")
if (!is.null(class)) {
class(res) <- class
}
Expand Down
6 changes: 3 additions & 3 deletions R/message.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ send_message <- function(

gmailr_POST(c("messages", "send"), user_id, class = "gmail_message",
query = list(uploadType = type),
body = jsonlite::toJSON(auto_unbox=TRUE,
c(threadId = thread_id,
raw = base64url_encode(mail))),
body = jsonlite::toJSON(auto_unbox=TRUE, null = "null",
c(threadId = thread_id,
list(raw = base64url_encode(mail)))),
add_headers("Content-Type" = "application/json"))
}
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ rename <- function(...) {
}
not_null <- function(x){ Filter(Negate(is.null), x) }

gmail_path <- function(user, ...) { paste("https://www.googleapis.com/gmail/v1/users", user, ..., sep="/") }
gmail_upload_path <- function(user, ...) { paste("https://www.googleapis.com/upload/gmail/v1/users", user, ..., sep="/") }
gmail_path <- function(user, ...) { paste("https://www.googleapis.com/gmail/v1/users", user, paste0(..., collapse = "/"), sep = "/") }
gmail_upload_path <- function(user, ...) { paste("https://www.googleapis.com/upload/gmail/v1/users", user, paste0(..., collapse = "/"), sep = "/") }
base64url_decode_to_char <- function(x) { rawToChar(base64decode(gsub("_", "/", gsub("-", "+", x)))) }
base64url_decode <- function(x) { base64decode(gsub("_", "/", gsub("-", "+", x))) }
base64url_encode <- function(x) { gsub("/", "_", gsub("\\+", "-", base64encode(charToRaw(as.character(x))))) }
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ valid_path <- function(path) {
is_string(path) && dir.exists(path)
}

if (requireNamespace("argufy", quietly = TRUE)) argufy::argufy_package() else `?` <- function(e1, e2) e1
argufy::argufy_package()

0 comments on commit 4c07595

Please sign in to comment.