Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit38a6f3e

Browse files
authored
Usegargle::response_process() (#210)
* Switch to gargle::response_process()* Add NEWS bullets* Touch up other mentions/uses of gm_last_response()* Mark as internal to suppress from index
1 parent10ee8fc commit38a6f3e

File tree

8 files changed

+91
-46
lines changed

8 files changed

+91
-46
lines changed

‎CLAUDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Follow tidyverse style guide conventions. Use `cli::cli_abort()` for error messa
2727
OAuth authentication is managed through the gargle package. Users must provide their own OAuth client via`gm_auth_configure()`. Authentication state is maintained across sessions. See`R/gm_auth.R` for implementation details.
2828

2929
**HTTP Requests**
30-
All Gmail API calls go through httr. Request and response handling follows gargle conventions. The most recent API response is available via`gm_last_response()` for debugging.
30+
All Gmail API calls go through httr. Request and response handling follows gargle conventions. The most recent API response is available via`gargle::gargle_last_response()` for debugging.
3131

3232
**MIME Message Construction**
3333
Email messages are built using MIME (Multipurpose Internet Mail Extensions) format. The`gm_mime()` function creates a base MIME object, which is then populated using builder functions like`gm_to()`,`gm_subject()`, and`gm_text_body()`. See`R/gm_mime.R` for the implementation.

‎DESCRIPTION‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Imports:
1818
base64enc,
1919
cli,
2020
crayon,
21-
gargle (>= 1.5.1),
21+
gargle (>= 1.6.0.9000),
2222
glue,
2323
httr,
2424
jsonlite,
@@ -42,3 +42,5 @@ Config/usethis/last-upkeep: 2025-11-03
4242
Encoding: UTF-8
4343
Roxygen: list(markdown = TRUE)
4444
RoxygenNote: 7.3.3
45+
Remotes:
46+
r-lib/gargle

‎NEWS.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
#gmailr (development version)
22

3+
* All HTTP responses are passed through`gargle::response_process()`, which updates gmailr's error handling to be consistent with other packages that use gargle for HTTP requests. Users might notice that errors are more verbose (and hopefully more informative). Also the class vector has changed:
4+
5+
- Previously:`c("condition", "error", "gmail_error")`
6+
- Now:`c("gmailr_error", "gargle_error_request_failed", "http_error_{XXX}", "gargle_error", "rlang_error", "error", "condition")`
7+
38
##Deprecations
49

510
* Functions that lack the`gm_` prefix have been removed, concluding a deprecation process that kicked off with gmailr 1.0.0 (released 2019-08-23). These functions were hard deprecated in gmailr 2.0.0 (released 2023-06-30). This eliminates many name conflicts with other packages (including the base package).
611

712
* Legacy auth functions`clear_token()`,`gmail_auth()`, and`use_secret_file()` have been removed, following the same deprecation timeline as described above.
813

14+
*`gm_last_response()` is deprecated, in favor of`gargle::gargle_last_response()`, since gmailr no longer caches the last response itself.
15+
916
##Bug fixes
1017

11-
* Fixed MIME structure for emails with text+HTML bodies and attachments. These messages now correctly use nested`multipart/mixed` (outer) containing`multipart/alternative` (text/HTML), preventing the loss of some of the message parts (#202).
18+
* Fixed MIME structure for emails with text+HTML bodies and attachments. These messages now correctly use nested`multipart/mixed` (outer) containing`multipart/alternative` (innertext/HTML), preventing the loss of some of the message parts (#202).
1219

1320
#gmailr 2.0.0
1421

‎R/aaa.R‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
the<- new.env(parent= emptyenv())
2-
31
.onLoad<-function(libname,pkgname) {
42
.auth<<-gargle::init_AuthState(
53
package="gmailr",

‎R/gmailr.R‎

Lines changed: 64 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -310,39 +310,24 @@ print.gmail_drafts <- function(x, ...) {
310310
)
311311
}
312312

313-
the$last_response<-list()
314-
315313
gmailr_query<-function(
316314
fun,
317315
location,
318316
user_id,
319317
class=NULL,
320318
...,
321-
upload=FALSE
319+
upload=FALSE,
320+
call= caller_env()
322321
) {
323322
path_fun<-if (upload)gmail_upload_pathelsegmail_path
324323
response<- fun(path_fun(user_id,location), gm_token(),...)
325-
result<- content(response,"parsed")
326-
327-
the$last_response<-response
328-
if (status_code(response)>=300) {
329-
cond<- structure(
330-
list(
331-
call= sys.call(-1),
332-
content=result,
333-
response=response,
334-
message= paste0(
335-
"Gmail API error:",
336-
status_code(response),
337-
"\n",
338-
result$error$message,
339-
"\n"
340-
)
341-
),
342-
class= c("condition","error","gmailr_error")
343-
)
344-
stop(cond)
345-
}
324+
325+
result<-gargle::response_process(
326+
response,
327+
remember=TRUE,
328+
call=call,
329+
error_class="gmailr_error"
330+
)
346331

347332
if (!is.null(class)&&!is.null(result)) {
348333
class(result)<-class
@@ -352,27 +337,71 @@ gmailr_query <- function(
352337

353338
#' Response from the last query
354339
#'
340+
#' `r lifecycle::badge("deprecated")`
341+
#'
342+
#' @description
343+
#' gmailr now uses [gargle::response_process()] to process responses, so
344+
#' [gargle::gargle_last_response()] can and should be used for *post mortem*
345+
#' analysis, instead of `gm_last_response()`. One benefit of this switch is that
346+
#' auth tokens are redacted in the stored response.
347+
#'
348+
#' @keywords internal
355349
#' @export
356350
gm_last_response<-function() {
357-
the$last_response
351+
lifecycle::deprecate_warn(
352+
"3.0.0",
353+
"gm_last_response()",
354+
"gargle::gargle_last_response()"
355+
)
356+
gargle::gargle_last_response()
358357
}
359358

360-
gmailr_GET<-function(location,user_id,class=NULL,...) {
361-
gmailr_query(GET,location,user_id,class,...)
359+
gmailr_GET<-function(
360+
location,
361+
user_id,
362+
class=NULL,
363+
...,
364+
call= caller_env()
365+
) {
366+
gmailr_query(GET,location,user_id,class,...,call=call)
362367
}
363368

364-
gmailr_DELETE<-function(location,user_id,class=NULL,...) {
365-
gmailr_query(DELETE,location,user_id,class,...)
369+
gmailr_DELETE<-function(
370+
location,
371+
user_id,
372+
class=NULL,
373+
...,
374+
call= caller_env()
375+
) {
376+
gmailr_query(DELETE,location,user_id,class,...,call=call)
366377
}
367378

368-
gmailr_PATCH<-function(location,user_id,class=NULL,...) {
369-
gmailr_query(PATCH,location,user_id,class,...)
379+
gmailr_PATCH<-function(
380+
location,
381+
user_id,
382+
class=NULL,
383+
...,
384+
call= caller_env()
385+
) {
386+
gmailr_query(PATCH,location,user_id,class,...,call=call)
370387
}
371388

372-
gmailr_POST<-function(location,user_id,class=NULL,...) {
373-
gmailr_query(POST,location,user_id,class,...)
389+
gmailr_POST<-function(
390+
location,
391+
user_id,
392+
class=NULL,
393+
...,
394+
call= caller_env()
395+
) {
396+
gmailr_query(POST,location,user_id,class,...,call=call)
374397
}
375398

376-
gmailr_PUT<-function(location,user_id,class=NULL,...) {
377-
gmailr_query(PUT,location,user_id,class,...)
399+
gmailr_PUT<-function(
400+
location,
401+
user_id,
402+
class=NULL,
403+
...,
404+
call= caller_env()
405+
) {
406+
gmailr_query(PUT,location,user_id,class,...,call=call)
378407
}

‎_pkgdown.yml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,4 @@ reference:
8484
These functions don't fit neatly into the above categories and are generally used internally or for debugging.
8585
contents:
8686
-gm_history
87-
-gm_last_response
8887
-quoted_printable_encode
89-
-gm_last_response

‎man/gm_last_response.Rd‎

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎tests/testthat/_snaps/gm_label.md‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
Code
44
gm_label(new_label3$id)
55
Condition
6-
Error in `gmailr_GET()`:
7-
! Gmail API error: 404
8-
Requested entity was not found.
6+
Error in `gm_label()`:
7+
! Client error: (404) Not Found
8+
Requested entity was not found.
9+
NOT_FOUND
10+
* message: Requested entity was not found.
11+
* domain: global
12+
* reason: notFound
913

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp