Skip to content

Commit

Permalink
Merge pull request #90 from CenterForOpenScience/dev
Browse files Browse the repository at this point in the history
v0.2.3
  • Loading branch information
aaronwolen authored Jan 29, 2019
2 parents fb59b7d + c600208 commit 6a2e58d
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 26 deletions.
1 change: 0 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
^CODE_OF_CONDUCT\.md$
^\.github$
^Meta$
^doc$
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ This outlines how to propose a change to osfr.

### Development environment

To get started with osfr development you'll need to generate a personal access token (PAT) on OSF's testing server. The following steps will get you setup:
To get started with osfr development you'll need to generate a personal access token (PAT) on OSF's *testing* server. The following steps will get you setup:

1. Create an account on <https://test.osf.io/>.
2. Generate a PAT for the new account with all permission scopes enabled. This is necessary to run osfr's unit tests.
2. Generate a PAT for the new account with all permission scopes enabled (this is necessary to run osfr's unit tests).
3. Fork the osfr repository and clone a local copy.
4. Create a `.Renviron` file in the root of your project directory that defines the `OSF_PAT` and `OSF_SERVER` environment variables. It should look like this:
4. Create a `.Renviron` file in the root of your project directory that defines the `OSF_PAT` and `OSF_SERVER` environment variables. You can easily create or edit an existing `.Renviron` file by running `usethis::edit_r_environ(scope = "project")`. The end result should look like this:

```
OSF_PAT=<YOUR PAT GOES HERE>
OSF_SERVER=test
```

5. Load your local copy of osfr with `devtools::load_all()` and verify that `osf_open(osf_retrieve_user("me"))` opens your test server profile on the `test.osf.io` domain.
5. Load your local copy of osfr with `devtools::load_all()` and verify that `osf_open(osf_retrieve_user("me"))` opens your user profile on the `test.osf.io` domain.

Once this is setup correctly, you should be able to run osfr's tests without error (`devtools::test()`).

Expand Down
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ cache: packages

matrix:
include:

- r: oldrel
r_build_args: --no-build-vignettes
r_check_args: --ignore-vignettes
- r: devel
r_build_args: --no-build-vignettes
r_check_args: --ignore-vignettes

- r: release
r_build_args: --no-build-vignettes
r_check_args: --ignore-vignettes
r_packages:
- pkgdown
after_success:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: osfr
Title: R Interface to OSF
Version: 0.2.2
Version: 0.2.3
Authors@R: c(
person("Aaron", "Wolen",, "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2542-2202")),
Expand All @@ -11,7 +11,7 @@ Authors@R: c(
Description: Manage your projects and access open research materials and data on OSF.
Depends: R (>= 3.1.0)
Imports:
crul,
crul (>= 0.7.0),
jsonlite,
stringi,
purrr,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ importFrom(purrr,"%||%")
importFrom(purrr,imap_chr)
importFrom(purrr,map)
importFrom(purrr,map_chr)
importFrom(purrr,modify_at)
importFrom(purrr,pluck)
importFrom(purrr,set_names)
importFrom(purrr,transpose)
Expand Down
19 changes: 14 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
# osfr 0.2.2
# osfr 0.2.3

## New functions
## New features

* `osf_mv()` to move files and directories to a new project, component, or
subdirectory
* Failed OSF API requests are now re-attempted 3 times (requires crul v0.7.0)

## Minor fixes

* Fix incorrect column name in empty `osf_tbl`s (#88, @machow)
* No longer importing `modify_at()`
* Add rOpenSci badge (#89, @maelle)
* Don't build vignettes on travis

# osfr 0.2.2

## New features

* Added `osf_mv()` to move files and directories to a new project, component, or
subdirectory
* `osf_rm()` can now delete files and directories

## Minor improvements and fixes

* Restructured tests to better handle environments in which `OSF_PAT` and/or `OSF_SERVER` are not defined
* Fix incorrect column name in empty `osf_tbl`s (#88, @machow)

# osfr 0.2.1

Expand Down
13 changes: 11 additions & 2 deletions R/api-client-osf.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,17 @@ user_agent <- function(agent = "osfr") {

method <- match.arg(method, c("get", "put", "patch", "post", "delete"))
cli <- .osf_cli()
method <- cli[[method]]
method(path, query, body = body, ...)

cli$retry(
method,
path,
query,
body = body,
times = 3,
retry_only_on = "502",
onwait = retry_message,
...
)
}

# TODO: .osf_request and .osf_paginated_request returns should be consistent
Expand Down
3 changes: 1 addition & 2 deletions R/api-client-wb.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,5 @@

method <- match.arg(method, c("get", "put", "patch", "post", "delete"))
cli <- .wb_cli()
method <- cli[[method]]
method(path, query, body = body, ...)
cli$verb(method, path, query, body = body, ...)
}
2 changes: 0 additions & 2 deletions R/osf_mkdir.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ osf_mkdir <- function(x, path, verbose = FALSE) {
UseMethod("osf_mkdir")
}

# TODO: DRY out the osf_tbl_node and osf_tbl_file methods

#' @export
osf_mkdir.osf_tbl_node <- function(x, path, verbose = FALSE) {
x <- make_single(x)
Expand Down
10 changes: 6 additions & 4 deletions R/utils-api-responses.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,18 @@ raise_error <- function(x) {

# Convert datetime attributes to POSIXct objects
# param x an OSF response list that contains an attributes element
#' @importFrom purrr modify_at
parse_datetime_attrs <- function(x) {
stopifnot(is.list(x))
stopifnot("attributes" %in% names(x))

x$attributes <- purrr::modify_at(x$attributes,
.at = c("date_registered", "date_created", "date_modified", "modified_utc"),
.f = parse_datetime
dt_keys <- intersect(
c("date_registered", "date_created", "date_modified", "modified_utc"),
names(x$attributes)
)

dt_vals <- lapply(x$attributes[dt_keys], parse_datetime)

x$attributes <- modifyList(x$attributes, dt_vals)
return(x)
}

Expand Down
2 changes: 1 addition & 1 deletion R/utils-nodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ recurse_node <- function(id, maxdepth = 5) {
# containing the ID of the most deeply nested node.
recurse_tree <- function(id, maxdepth = 5) {
if (maxdepth == 1) return(id)
# TODO: use consistent argument names for number of items to return

children <- .osf_node_children(id, n_max = Inf)
child_ids <- purrr::map_chr(children, "id")

Expand Down
13 changes: 13 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ http_error <- function(code, ...) {
stop(args, msg, call. = FALSE)
}

#' Inform user the API request failed and will be retried
#' @param res response object from the failed request
#' @param time wait time in seconds
#' @noRd
retry_message <- function(res, time) {
message(
sprintf(
"Request failed (Status code: %s). Retrying in %ds...",
res$status_code, ceiling(time)
)
)
}

is_osf_url <- function(url) grepl("osf.io", tolower(url), fixed = TRUE)

is_osf_dir <- function(x) {
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Big thanks to Rusty Speidel for designing our logo and [Tim Errington][tim] for

## Contributing

Check out the [Contributing Guidelines](.github/CONTRIBUTING.md) to get started with osfr development and note that by contributing to this project, you agree to abide by the terms outlined in the [Contributor Code of Conduct](CODE_OF_CONDUCT.md).
Check out the [Contributing Guidelines](.github/CONTRIBUTING.md) to get started with osfr development and note that by contributing to this project, you agree to abide by the terms outlined in the [Contributor Code of Conduct](.github/CODE_OF_CONDUCT.md).

<!-- links -->
[osf]: https://osf.io "Open Science Framework"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,6 @@ development.
Check out the [Contributing Guidelines](.github/CONTRIBUTING.md) to get
started with osfr development and note that by contributing to this
project, you agree to abide by the terms outlined in the [Contributor
Code of Conduct](CODE_OF_CONDUCT.md).
Code of Conduct](.github/CODE_OF_CONDUCT.md).

<!-- links -->
3 changes: 3 additions & 0 deletions tests/testthat/test-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ test_that("a directory can be downloaded as a zip file", {
context("Moving/copying files")

test_that("moving to a destination with an existing file throws an error", {
skip_if_no_pat()
expect_error(osf_mv(f1, d1), "Cannot complete action: file or folder")
})

Expand Down Expand Up @@ -181,6 +182,8 @@ test_that("moving destination can be a different node", {
})

test_that("directories can be moved to a sibling directory", {
skip_if_no_pat()

d2 <- osf_mkdir(p1, "d2")
d1 <- osf_mv(d1, d2)
expect_s3_class(f1, "osf_tbl_file")
Expand Down

0 comments on commit 6a2e58d

Please sign in to comment.