Skip to content

Commit

Permalink
version 0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott authored and cran-robot committed Jun 28, 2018
1 parent 9f818b4 commit c1a786d
Show file tree
Hide file tree
Showing 24 changed files with 272 additions and 224 deletions.
18 changes: 12 additions & 6 deletions DESCRIPTION
Expand Up @@ -10,9 +10,11 @@ Description: Work with 'GitHub' 'gists' from 'R' (e.g.,
'gist' 'commits', and get rate limit information when 'authenticated'. Some
requests require authentication and some do not. 'Gists' website:
<https://gist.github.com/>.
Version: 0.4.0
Version: 0.4.2
Authors@R: c(
person("Scott", "Chamberlain", role = c("aut", "cre"), email = "myrmecocystus@gmail.com"),
person("Scott", "Chamberlain", role = c("aut", "cre"),
email = "myrmecocystus@gmail.com",
comment = c(ORCID="0000-0003-1444-9135")),
person("Ramnath", "Vaidyanathan", role = "aut"),
person("Karthik", "Ram", role = "aut")
)
Expand All @@ -22,13 +24,17 @@ BugReports: https://github.com/ropensci/gistr/issues
VignetteBuilder: knitr
Imports: jsonlite (>= 1.4), httr (>= 1.2.0), magrittr, assertthat,
knitr, rmarkdown, dplyr
Suggests: roxygen2 (>= 6.0.1), git2r, testthat
Suggests: git2r, testthat
RoxygenNote: 6.0.1
X-schema.org-applicationCategory: Web
X-schema.org-keywords: http, https, API, web-services, GitHub, GitHub
API, gist, gists, code, script, snippet
X-schema.org-isPartOf: https://ropensci.org
NeedsCompilation: no
Packaged: 2017-04-20 19:42:16 UTC; sacmac
Author: Scott Chamberlain [aut, cre],
Packaged: 2018-06-27 22:31:37 UTC; sckott
Author: Scott Chamberlain [aut, cre] (<https://orcid.org/0000-0003-1444-9135>),
Ramnath Vaidyanathan [aut],
Karthik Ram [aut]
Maintainer: Scott Chamberlain <myrmecocystus@gmail.com>
Repository: CRAN
Date/Publication: 2017-04-20 23:40:22 UTC
Date/Publication: 2018-06-28 05:05:47 UTC
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,2 +1,2 @@
YEAR: 2017
YEAR: 2018
COPYRIGHT HOLDER: Scott Chamberlain
46 changes: 23 additions & 23 deletions MD5
@@ -1,48 +1,48 @@
915b106244b328d9d2639145130ec232 *DESCRIPTION
c5af52351472a750055a760a8924ce71 *LICENSE
1d8f9856ab236c5a6a9ce0dbaa3ba017 *DESCRIPTION
1b96a74f7e95cf508e814ad0c04525e5 *LICENSE
62683e3e47c2eaa65c0d92c0a6e2ba82 *NAMESPACE
dae221ab66e5251c358491d3786247e8 *NEWS.md
dba6800f321d0fc55525fad9a1ce4d6e *NEWS.md
11863e3fcfb542966ab582466bff77fb *R/add_files.R
81456be9dbaa18152cafbe853fcf237b *R/browse.R
d2b6fe7d6fb3723566d34180122fb1b8 *R/commits.R
8a862eb23f131cd71bb60a41719abd2c *R/delete.R
280d94e029aa071ef37c81bc38129c28 *R/embed.R
a84337c9d8662c71d35575773e51c80a *R/forks.R
89fe3c7ac34537629bd34591c458e90b *R/gist.R
a71ce147d74e337f1539db022024bf39 *R/gist.R
06ec5cd863a5a047c3ca63d07ffcc51c *R/gist_auth.R
29ec6bfab5b17187e7c9099ef45223ce *R/gist_create.R
389d613f11e063d26ac349c9f89d34d7 *R/gist_create_git.R
0021ef24c5b58a89d297cab22165d3dd *R/gist_create.R
2833a19cc2f8593770c8d1668ef51720 *R/gist_create_git.R
72040aefdfd8039edb0782aac1c1ad43 *R/gist_create_obj.R
c5902d120109fd1b711fd54f75b80b34 *R/gist_map.R
042364dbd3ef9bccffdb50cda6f678fd *R/gist_save.R
e1ce7f1f12a7abc6606595536edf6793 *R/gistr-package.R
c311257d684006acf0aa927f77e1d4ba *R/gists.R
def9a4d55b4b215bbf7b34c1ef38c702 *R/rate_limit.R
81492fb728230f1e4828335363fa45bc *R/rate_limit.R
108f031bf8506ad53e286a6448b1029f *R/run.R
80e1b5f0b618d328524b20a254035bc1 *R/star.R
5f97b231e345d7b421950becf8d457f6 *R/tabl.R
e1de5b69d2a7b42dd2ccde63e4542e24 *R/update.R
e5cff78079aedea7d3838bcab8382337 *R/update.R
4434ef10e2531038b97136ea04cccd47 *R/utils.R
7fe74ea661003bac5dfd62b1b4cdb181 *R/zzz.R
d6af2015c8b41ef223e47510a755e35d *README.md
a06131bf3fc9fff19d631c8fc7546735 *build/vignette.rds
f853c4cd7764c781d0f55eff13c4060d *R/zzz.R
3a88d8f10cc658221c0279c2f2411178 *README.md
58222dd90840968ff8e7a097bc218418 *build/vignette.rds
7eb782a666409c351bf3bae44f6a42ad *inst/doc/gistr_vignette.Rmd
3823fd75b005e459f56418990c112794 *inst/doc/gistr_vignette.html
5e8d191653fabf940e83fc8b652ced6e *inst/examples/alm.md
1275996ea246b818a2996e969cb104bf *inst/examples/artifacts_eg1.Rmd
ed65765d86c6b2a337f236b324534c95 *inst/examples/ecoengine_eg.geojson
f02d614aea3004912babc111acbcfad0 *inst/examples/example1.R
830bc3ff47204f1824b9776d2406bacb *inst/examples/example1.md
168ac824dc327b0821966627be96ed51 *inst/examples/example1.md
b606b05b6ee00ccfdb98907626ce08a7 *inst/examples/example2.R
b05e21a6d88dd34fd62c65417b2afc28 *inst/examples/file.png
2045081f4b90408319fcd92bf1b419eb *inst/examples/ggplot_imgur.Rmd
0eae2be87879bd0e24633957407cbfb0 *inst/examples/plots.Rmd
94c12be780424d0785fc320638a4ae9a *inst/examples/plots.md
eb1c172ff3269322633791a75cb5cd1e *inst/examples/plots.md
6a15a53b5b9f71c9c3b34e837886d69a *inst/examples/plots_imgur.Rmd
25891c43fb4a5bcf48c6f8c912487b3f *inst/examples/plots_imgur.Rnw
8032e5305bc7a3efa765cdbe1a1c0b35 *inst/examples/plots_imgur.md
fe404fd5727070b02c85a21b9dae95f6 *inst/examples/plots_imgur.md
da0c1154920e767939470021f7394046 *inst/examples/rmarkdown_eg.Rmd
d0b6ea8182b2b6f2441cc3800aa20fff *inst/examples/rmarkdown_eg.md
367a1eb3459802e082066133a87e509e *inst/examples/rmarkdown_eg.md
c1f87da976ae368c2c7b17367858d399 *inst/examples/rnw_example.Rnw
1694aa81a6dbc620f9abacb7b4d098a6 *inst/examples/stuff.Rmd
bf2204b1c2956660e3c7ef2878b08211 *inst/examples/stuff.md
Expand All @@ -60,33 +60,33 @@ a6cce450a25490fdc61cf4ce35d7e927 *man/commits.Rd
ce61fd6157f6e95df24028fea3776b0b *man/files.Rd
1d0d824ef99c694d4d71c7a95821e02f *man/fork.Rd
f82c3383b62b33edc263637b6da68dac *man/forks.Rd
b19018147a40059e2e82dbea22ab8b0e *man/gist.Rd
f64147a4c629ba4d0f6fdfd96aa4f905 *man/gist.Rd
caa9ffacd475ebca29a07eee49d20e72 *man/gist_auth.Rd
9ab2d0bd9e479a6003e46658b2ddef04 *man/gist_create.Rd
4c4c7b234315934bda0b6e727becd76a *man/gist_create_git.Rd
008c2f5bfc7202681a812a530a043bcc *man/gist_create.Rd
a3b9394424fe918742b074b0e9b50aaa *man/gist_create_git.Rd
e52feb2d89ea3dfde2545ea8c04d3d56 *man/gist_create_obj.Rd
9d55f19f5460d0139dad0c2ecfc8cd3e *man/gist_map.Rd
2a7b7838e657a4b78e3bc03cccbf40c2 *man/gist_save.Rd
364f6d0ca33d487ec17b2d7759b9e50a *man/gistr-package.Rd
af7027406c41e4af06732f82c1f09f9a *man/gists.Rd
a64a7ea44fcaa33c2d3ad0f7909cbc3e *man/pipe.Rd
78e8aec5d028a25af7c6c496ad487e21 *man/rate_limit.Rd
cf3bb3c4271fe05ed2effea85d2853d2 *man/rate_limit.Rd
49b1a87c106d90fe609249e31bbc2c19 *man/run.Rd
da91e633ee0741c8f522bedde981f8dd *man/star.Rd
807b2dd18bf7c735ccae0885bd198493 *man/tabl.Rd
e29c586cfbd0e82c1514891fac007e1b *man/update.Rd
5d6e5b084fb60825d7fafeb3d8ca437d *man/update.Rd
a790703d07775f53a14de5c5223d370c *tests/localtests/test-gist_create.R
adeb6046d172a1bd6f794d1913fbfa8e *tests/test-all.R
a995038d6ebc73774540e16bcba59dd5 *tests/testthat/test-commits.R
8c6a98654159c7d750fdcd8e685cd8f6 *tests/testthat/test-delete.R
ddeb4c3f3a8b75d45d6edabf5e22281d *tests/testthat/test-embed.R
a14ad327ea4af256fde603704ba32bbd *tests/testthat/test-fork.R
248ea473e2b06d0a5edbc105452ec0ba *tests/testthat/test-gist.R
f69dc882d8fab835a4afbca6f5410b6d *tests/testthat/test-fork.R
fbb2a87fb0317357b72dd3f3b3685fed *tests/testthat/test-gist.R
60e582abf9182b752473a4982c3773bc *tests/testthat/test-gist_create_git.R
5d646573ab0d14bc7ed65930878a6ef2 *tests/testthat/test-gist_create_obj.R
bcc183ba5176daa8c9f3c8ba50275f86 *tests/testthat/test-gist_save.R
f2b1e5818fe1e588719a06dc47b72f38 *tests/testthat/test-gists.R
6922dcf7d8810995ff9cc3c205cf5b31 *tests/testthat/test-rate_limit.R
ab7dd28d03f365a7d18ec949a9cbd72f *tests/testthat/test-star.R
43870934f461a3b22194b8ef9ab1ad78 *tests/testthat/test-star.R
ade0ce498dfdac53076053a731271d79 *tests/testthat/test-update.R
7eb782a666409c351bf3bae44f6a42ad *vignettes/gistr_vignette.Rmd
13 changes: 13 additions & 0 deletions NEWS.md
@@ -1,3 +1,16 @@
gistr 0.4.2
===============

### NEW FEATURES

* `gist()` gains a parameter `revision` to request a specific revision of a gists. note that the returned brief print out of the gist in your console may not vary from revision to revision, but the underlying data has the correct data for the revision (#71)

### MINOR IMPROVEMENTS

* affecting all functions that create data `gist_create()`, `gist_create_git()`, `gist_create_obj()`, `update()`, `delete()`: GitHub for good reason gives a 404 when there are authentication issues. A common problem is that a user has incorrect or missing scopes. We now attempt to detect this scope problem specifically and throw a message when that happens (#70)
* toggle whether we index to a git path with `@` vs. `$` depending on `git2r` package version; for an upcoming version of `git2r` (#74)


gistr 0.4.0
===============

Expand Down
14 changes: 12 additions & 2 deletions R/gist.R
Expand Up @@ -2,6 +2,7 @@
#'
#' @export
#' @param id (character) A gist id, or a gist URL
#' @param revision (character) A sha. optional
#' @param x Object to coerce. Can be an integer (gist id), string
#' (gist id), a gist, or an list that can be coerced to a gist.
#' @template all
Expand All @@ -17,6 +18,13 @@
#' as.gist('f1403260eb92f5dfa7e1')
#' as.gist(10)
#' as.gist(gist('f1403260eb92f5dfa7e1'))
#'
#' # get a specific revision of a gist
#' id <- 'c1e2cb547d9f22bd314da50fe9c7b503'
#' gist(id, 'a5bc5c143beb697f23b2c320ff5a8dacf960b0f3')
#' gist(id, 'b70d94a8222a4326dff46fc85bc69d0179bd1da2')
#' gist(id, '648bb44ab9ae59d57b4ea5de7d85e24103717e8b')
#' gist(id, '0259b13c7653dc95e20193133bcf71811888cbe6')
#'
#' # from a url, or partial url
#' x <- "https://gist.github.com/expersso/4ac33b9c00751fddc7f8"
Expand All @@ -42,8 +50,10 @@
#' # httr::GET(url)
#' }

gist <- function(id, ...){
res <- gist_GET(switch_url('id', normalize_id(id)), gist_auth(), ghead(), ...)
gist <- function(id, revision = NULL, ...){
url <- switch_url('id', normalize_id(id))
if (!is.null(revision)) url <- file.path(url, revision)
res <- gist_GET(url, gist_auth(), ghead(), ...)
as.gist(res)
}

Expand Down
22 changes: 7 additions & 15 deletions R/gist_create.R
Expand Up @@ -24,15 +24,6 @@
#' numbers
#' '})
#'
#' # or include results if you want, and change the filename in this case
#' gist_create(code={'
#' x <- letters
#' numbers <- runif(8)
#' numbers
#'
#' [1] 0.3229318 0.5933054 0.7778408 0.3898947 0.1309717 0.7501378 0.3206379 0.3379005
#' '}, filename="my_cool_code.R")
#'
#' # Knit an .Rmd file before posting as a gist
#' file <- system.file("examples", "stuff.Rmd", package = "gistr")
#' gist_create(file, description='a new cool gist', knit=TRUE)
Expand All @@ -54,11 +45,10 @@
#' '}, knit=TRUE)
#'
#' library('httr')
#' base <- "http://pelias.mapzen.com/search"
#' res <- httr::GET(base, query = list(input = 'coffee shop', lat = 45.5,
#' lon = -122.6))
#' url <- "https://github.com/ropensci/geojsonio/blob/master/inst/examples/zillow_or.geojson"
#' res <- httr::GET(url)
#' json <- httr::content(res, as = "text")
#' gist_create(code = json, filename = "pelias_test.geojson")
#' gist_create(code = json, filename = "zillow_or.geojson")
#'
#' # Knit and include source file, so both files are in the gist
#' file <- system.file("examples", "stuff.Rmd", package = "gistr")
Expand All @@ -77,8 +67,7 @@
#' cat(readLines(file), sep = "\n") # peek at file
#' gist_create(file, knit=TRUE)
#' ## if not, GitHub doesn't allow upload of binary files via the HTTP API
#' ## (which gistr uses) but check back later as I'm working on an option to
#' ## get binary files uploaded, but will involve having to use git
#' ## (which gistr uses) - so see gist_create_git(), which uses git
#' file <- system.file("examples", "plots.Rmd", package = "gistr")
#' gist_create(file, knit=TRUE, imgur_inject = TRUE)
#' ## works with ggplot2 as well
Expand Down Expand Up @@ -113,6 +102,9 @@ gist_create <- function(files=NULL, description = "", public = TRUE,
renderopts=list(), include_source = FALSE, imgur_inject = FALSE,
rmarkdown = FALSE, ...) {

if (is.null(files) && is.null(code)) {
stop("must use one of 'files' or 'code'", call. = FALSE)
}
if (!is.null(code)) files <- code_handler(code, filename)
if (knit) {
allfiles <- list()
Expand Down
5 changes: 4 additions & 1 deletion R/gist_create_git.R
Expand Up @@ -168,7 +168,9 @@ gist_create_git <- function(files = NULL, description = "", public = TRUE,
}

# add files
ftoadd <- gsub(sprintf("%s/?|\\./", git@path), "", allfiles)
git2r_ver <- unclass(utils::packageVersion('git2r'))[[1]][2]
patttth <- if (git2r_ver >= 22) git$path else git@path
ftoadd <- gsub(sprintf("%s/?|\\./", patttth), "", allfiles)
git2r::add(git, ftoadd)
# commit files
cm <- tryCatch(git2r::commit(git, message = "added files from gistr"),
Expand Down Expand Up @@ -261,6 +263,7 @@ cgist <- function(description, public) {
)
), auto_unbox = TRUE)
)
stopstatus(res)
jsonlite::fromJSON(httr::content(res, "text", encoding = "UTF-8"), FALSE)
}

Expand Down
1 change: 0 additions & 1 deletion R/rate_limit.R
Expand Up @@ -4,7 +4,6 @@
#' @param ... Named args to \code{\link[httr]{GET}}
#' @examples \dontrun{
#' rate_limit()
#' rate_limit(config=verbose())
#' }

rate_limit <- function(...){
Expand Down
3 changes: 2 additions & 1 deletion R/update.R
Expand Up @@ -4,14 +4,15 @@
#' @param gist A gist object or something coerceable to a gist
#' @param description (character) Brief description of gist (optional)
#' @template all
#' @return
#' @examples \dontrun{
#' file1 <- system.file("examples", "alm.md", package = "gistr")
#' file2 <- system.file("examples", "zoo.json", package = "gistr")
#'
#' # add new files
#' gists(what = "minepublic")[[3]] %>%
#' add_files(file1, file2) %>%
#' update(config = verbose())
#' update()
#'
#' # update existing files
#' ### file name has to match to current name
Expand Down
15 changes: 11 additions & 4 deletions R/zzz.R
Expand Up @@ -90,7 +90,9 @@ gist_PUT <- function(url, auth, headers, ...){
}

gist_DELETE <- function(url, auth, headers, ...){
DELETE(url, auth, headers, ...)
res <- DELETE(url, auth, headers, ...)
stopstatus(res, 204)
res
}

process <- function(x){
Expand All @@ -100,13 +102,18 @@ process <- function(x){
jsonlite::fromJSON(temp, FALSE)
}

stopstatus <- function(x) {
if (x$status_code > 203) {
stopstatus <- function(x, status_stop = 203) {
if (x$status_code > status_stop) {
res <- jsonlite::fromJSON(httr::content(x, as = "text",
encoding = "UTF-8"), FALSE)
errs <- sapply(res$errors, function(z) paste(names(z), z, sep = ": ",
collapse = "\n"))
stop(res$message, "\n", errs, call. = FALSE)
# check for possible oauth scope problems
scopes_problem <- ""
if (is.null(x$`x-oauth-scopes`)) {
scopes_problem <- " GitHub response headers suggest no or insufficient scopes\n To create gists you need the `gist` OAuth scope on your token."
}
stop(res$message, "\n", errs, "\n", scopes_problem, call. = FALSE)
}
}

Expand Down

0 comments on commit c1a786d

Please sign in to comment.