Skip to content

Commit 228a251

Browse files
committed
fix #68 replace httr with crul - except for gist_auth that uses oauth
1 parent 806dcef commit 228a251

32 files changed

+117
-126
lines changed

DESCRIPTION

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
Package: gistr
22
Title: Work with 'GitHub' 'Gists'
33
Description: Work with 'GitHub' 'gists' from 'R' (e.g.,
4-
<http://en.wikipedia.org/wiki/GitHub#Gist>,
5-
<https://help.github.com/articles/about-gists/>). A 'gist'
4+
<https://en.wikipedia.org/wiki/GitHub#Gist>,
5+
<https://docs.github.com/en/github/writing-on-github/creating-gists/>). A 'gist'
66
is simply one or more files with code/text/images/etc. This package allows
77
the user to create new 'gists', update 'gists' with new files, rename files,
88
delete files, get and delete 'gists', star and 'un-star' 'gists', fork 'gists',
99
open a 'gist' in your default browser, get embed code for a 'gist', list
1010
'gist' 'commits', and get rate limit information when 'authenticated'. Some
1111
requests require authentication and some do not. 'Gists' website:
1212
<https://gist.github.com/>.
13-
Version: 0.5.0.92
13+
Version: 0.5.1.91
1414
Authors@R: c(
1515
person("Scott", "Chamberlain", role = c("aut", "cre"),
1616
email = "[email protected]",
@@ -27,8 +27,9 @@ VignetteBuilder: knitr
2727
Encoding: UTF-8
2828
Language: en-US
2929
Imports:
30-
jsonlite (>= 1.4),
31-
httr (>= 1.2.0),
30+
jsonlite,
31+
crul,
32+
httr,
3233
magrittr,
3334
assertthat,
3435
knitr,
@@ -37,7 +38,7 @@ Imports:
3738
Suggests:
3839
git2r,
3940
testthat
40-
RoxygenNote: 7.0.2
41+
RoxygenNote: 7.1.1
4142
X-schema.org-applicationCategory: Web
4243
X-schema.org-keywords: http, https, API, web-services, GitHub, GitHub API, gist, gists, code, script, snippet
4344
X-schema.org-isPartOf: https://ropensci.org

NAMESPACE

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,16 @@ export(update)
4848
export(update_files)
4949
importFrom(assertthat,assert_that)
5050
importFrom(assertthat,has_extension)
51+
importFrom(crul,HttpClient)
5152
importFrom(dplyr,as_data_frame)
5253
importFrom(dplyr,bind_rows)
53-
importFrom(httr,DELETE)
54-
importFrom(httr,GET)
55-
importFrom(httr,PATCH)
56-
importFrom(httr,POST)
57-
importFrom(httr,PUT)
5854
importFrom(httr,add_headers)
59-
importFrom(httr,content)
60-
importFrom(httr,stop_for_status)
61-
importFrom(httr,warn_for_status)
55+
importFrom(httr,config)
56+
importFrom(httr,oauth2.0_token)
57+
importFrom(httr,oauth_app)
58+
importFrom(httr,oauth_endpoints)
6259
importFrom(jsonlite,flatten)
60+
importFrom(jsonlite,fromJSON)
6361
importFrom(knitr,knit)
6462
importFrom(magrittr,"%>%")
6563
importFrom(rmarkdown,render)

R/commits.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' @param page (integer) Page number to return.
66
#' @param per_page (integer) Number of items to return per page.
77
#' Default 30. Max 100.
8-
#' @param ... Further named args to [httr::GET()]
8+
#' @param ... Further named args to [crul::verb-GET]
99
#' @examples \dontrun{
1010
#' gists()[[1]] %>% commits()
1111
#' gist(id = '1f399774e9ecc9153a6f') %>% commits(per_page = 5)

R/delete.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ delete <- function(gist, ...) {
1111
gist <- as.gist(gist)
1212
res <- gist_DELETE(paste0(ghbase(), '/gists/', gist$id),
1313
auth = gist_auth(), headers = ghead(), ...)
14-
stop_for_status(res)
14+
res$raise_for_status()
1515
message('Your gist has been deleted')
1616
}
17-
18-
# res <- gist_DELETE(paste0(ghbase(), '/gists/', gist$id, "/2233500e6aac91a32cb84878edfb7a619fd8c56a"),
19-
# auth = gist_auth(), headers = ghead(), httr::verbose())

R/forks.R

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' @param page (integer) Page number to return.
66
#' @param per_page (integer) Number of items to return per page. Default 30.
77
#' Max 100.
8-
#' @param ... Further named args to [httr::GET()]
8+
#' @param ... Further named args to [crul::verb-GET]
99
#' @return A list of gist class objects
1010
#' @examples \dontrun{
1111
#' gist(id='1642874') %>% forks(per_page=2)
@@ -28,19 +28,14 @@ forks <- function(gist, page=NULL, per_page=30, ...) {
2828
#'
2929
#' @export
3030
#' @param gist A gist object or something coerceable to a gist
31-
#' @param ... Further named args to \code{\link[httr]{GET}}
31+
#' @param ... Further named args to [crul::verb-GET]
3232
#' @return A gist class object
3333
#' @examples \dontrun{
3434
#' # fork a gist
35-
#' gists()[[1]] %>% fork()
35+
#' w <- gists()[[1]] %>% fork()
3636
#'
3737
#' # browse to newly forked gist
38-
#' gist(id='0831f3fbd83ac4d46451') %>% fork() %>% browse()
39-
#'
40-
#' # extract the last one
41-
#' gist(id='1642874') %>%
42-
#' forks() %>%
43-
#' .[length(.)]
38+
#' browse(w)
4439
#' }
4540

4641
fork <- function(gist, ...) {

R/gist.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#' (bigfile <- gist(id = "b74b878fd7d9176a4c52"))
4848
#' ## then get the raw_url, and retrieve the file
4949
#' url <- bigfile$files$`plossmall.json`$raw_url
50-
#' # httr::GET(url)
5150
#' }
5251

5352
gist <- function(id, revision = NULL, ...){

R/gist_auth.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
gist_auth <- function(app = gistr_app, reauth = FALSE) {
2727

2828
if (exists("auth_config", envir = cache) && !reauth) {
29-
return(cache$auth_config)
29+
return(undo(cache$auth_config$headers))
3030
}
3131
pat <- Sys.getenv("GITHUB_PAT", "")
3232
if (!identical(pat, "")) {
@@ -41,9 +41,11 @@ gist_auth <- function(app = gistr_app, reauth = FALSE) {
4141
auth_config <- httr::config(token = token)
4242
}
4343
cache$auth_config <- auth_config
44-
auth_config
44+
undo(auth_config$headers)
4545
}
4646

47+
undo <- function(x) unclass(as.list(unclass(x)))
48+
4749
cache <- new.env(parent = emptyenv())
4850

4951
gistr_app <- httr::oauth_app(

R/gist_create.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@
4343
#' ```
4444
#' '}, knit=TRUE)
4545
#'
46-
#' library('httr')
47-
#' url <- "https://github.com/ropensci/geojsonio/blob/master/inst/examples/zillow_or.geojson"
48-
#' res <- httr::GET(url)
49-
#' json <- httr::content(res, as = "text")
46+
#' url <- "https://raw.githubusercontent.com/ropensci/geojsonio/master/inst/examples/zillow_or.geojson"
47+
#' json <- crul::HttpClient$new(url)$get()$parse("UTF-8")
5048
#' gist_create(code = json, filename = "zillow_or.geojson")
5149
#'
5250
#' # Knit and include source file, so both files are in the gist

R/gist_create_git.R

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,21 @@ unpack <- function(z) {
248248
}
249249

250250
cgist <- function(description, public) {
251-
res <- httr::POST(paste0(ghbase(), '/gists'),
252-
gist_auth(),
253-
encode = "json",
254-
body = jsonlite::toJSON(list(
255-
description = description,
256-
public = public,
257-
files = list(
258-
".gistr" = list(
259-
content = "gistr"
260-
)
261-
)
262-
), auto_unbox = TRUE)
251+
gist_POST(
252+
paste0(ghbase(), '/gists'),
253+
gist_auth(),
254+
ghead(),
255+
body = jsonlite::toJSON(list(
256+
description = description,
257+
public = public,
258+
files = list(
259+
".gistr" = list(
260+
content = "gistr"
261+
)
262+
)
263+
), auto_unbox = TRUE),
264+
encode = "json"
263265
)
264-
stopstatus(res)
265-
jsonlite::fromJSON(httr::content(res, "text", encoding = "UTF-8"), FALSE)
266266
}
267267

268268
all_artifacts <- function(x) {

R/gist_create_obj.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#' @param pretty (logical) For data.frame and matrix objects, create
1111
#' a markdown table. If FALSE, pushes up json. (default: `TRUE`)
1212
#' @param filename Name of the file to create. Default: `file.txt`
13-
#' @param ... Further args passed on to [httr::POST()]
13+
#' @param ... Further args passed on to [crul::verb-POST]
1414
#' @details This function is specifically for going from R objects to a gist,
1515
#' whereas [gist_create()] is for going from files or executing code
1616
#' @seealso [gist_create()], [gist_create_git()]

0 commit comments

Comments
 (0)