Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key setup #31

Merged
merged 3 commits into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ Title: 'IUCN' Red List Client
Description: 'IUCN' Red List (<http://apiv3.iucnredlist.org/api/v3/docs>) client.
The 'IUCN' Red List is a global list of threatened and endangered species.
Functions cover all of the Red List 'API' routes. An 'API' key is required.
Version: 0.4.1.9420
Authors@R: c(person("Scott", "Chamberlain", role = c("aut", "cre"),
email = "myrmecocystus@gmail.com"))
Version: 0.4.1.9500
Authors@R:
c(person(given = "Scott",
family = "Chamberlain",
role = c("aut", "cre"),
email = "myrmecocystus@gmail.com"),
person(given = "rOpenSci",
role = "fnd",
comment = "https://ropensci.org/"),
person(given = "Maëlle",
family = "Salmon",
role = "ctb",
email = "maelle.salmon@yahoo.se"))
License: MIT + file LICENSE
URL: https://github.com/ropensci/rredlist
BugReports: https://github.com/ropensci/rredlist/issues
Expand All @@ -17,4 +27,5 @@ Imports:
Suggests:
roxygen2 (>= 6.0.1),
testthat
RoxygenNote: 6.0.1
RoxygenNote: 6.0.1.9000
Encoding: UTF-8
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ export(rl_synonyms)
export(rl_synonyms_)
export(rl_threats)
export(rl_threats_)
export(rl_use_iucn)
export(rl_version)
importFrom(jsonlite,fromJSON)
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
rredlist 0.4.1.9500
===================

* Gain new function `rl_use_iucn` to help with API key setup (PR #31 by @maelle).

rredlist 0.4.0
==============

Expand Down
21 changes: 21 additions & 0 deletions R/rl_key.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' Helper to get and save IUCN API key
#'
#' @description Browse IUCN Red List API key request URL and
#' provides instruction on how to store the key.
#'
#' @details Note that after filling the online form, you should
#' receive an API key shortly but not immediately.
#'
#' @aliases rl_use_iucn
#'
#' @export
#'
rl_use_iucn <- function(){
if(interactive()){
utils::browseURL("http://apiv3.iucnredlist.org/api/v3/token")
}

message("After getting your key set it as IUCN_REDLIST_KEY in .Renviron.\n IUCN_REDLIST_KEY='youractualkeynotthisstring'\n For that, use usethis::edit_r_environ()")

invisible("http://apiv3.iucnredlist.org/api/v3/token")
}
5 changes: 3 additions & 2 deletions R/rredlist-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#'
#' @section Authentication:
#' IUCN requires you to get your own API key, an alphanumeric string that you
#' need to send in every request. Get it at
#' need to send in every request. See key A IUCN API token. See \code{\link{rl_use_iucn}}
#' for help getting and storing it. Get it at
#' <http://apiv3.iucnredlist.org/api/v3/token>
#' Keep this key private. You can pass the key in to each function via the
#' `key` parameter, but it's better to store the key either as a
#' environment variable (`IUCN_REDLIST_KEY`) or an R option
#' (`iucn_redlist_key`) - we suggest using the former option.
#' (`iucn_redlist_key`) - we recommend using the former option.
#'
#' @section High vs. Low level package APIs:
#' **High level API**
Expand Down
13 changes: 7 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ See <http://apiv3.iucnredlist.org/about>

## Authentication

IUCN requires you to get your own API key, an alphanumeric string that you
need to send in every request. Get it at <http://apiv3.iucnredlist.org/api/v3/token>.
Keep this key private. You can pass the key in to each function via the
`key` parameter, but it's better to store the key either as a environment
variable (`IUCN_REDLIST_KEY`) or an R option (`iucn_redlist_key`) - we
suggest using the former option.
IUCN requires you to get your own API key, an alphanumeric string that you need to send in every request. There's an helper function in the package helping you getting it at <http://apiv3.iucnredlist.org/api/v3/token> and storing it.

```{r}
rredlist::rl_use_iucn()
```

Keep this key private. You can pass the key in to each function via the `key` parameter, but it's better to store the key either as a environment variable (`IUCN_REDLIST_KEY`) or an R option (`iucn_redlist_key`) - we recommend using the former option.

## High vs. Low level package APIs

Expand Down
3 changes: 1 addition & 2 deletions man-roxygen/all.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#' @param key A IUCN API token. See
#' \url{http://apiv3.iucnredlist.org/api/v3/token} to get a token
#' @param key A IUCN API token. See \code{\link{rl_use_iucn}}.
#' @param ... Curl options passed to \code{\link[crul]{HttpClient}}
#' @param parse (logical) Whether to parse to list (\code{FALSE}) or
#' data.frame (\code{TRUE}). Default: \code{TRUE}
3 changes: 1 addition & 2 deletions man/rl_common_names.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_comp_groups.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_countries.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_growth_forms.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_habitats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_history.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_measures.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_narrative.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_occ_country.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_regions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_search.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_sp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_sp_category.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_sp_citation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_sp_count.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_sp_country.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_synonyms.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/rl_threats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions man/rl_use_iucn.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/rredlist-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/testthat/test-rl_key.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
context("test-rl_key")

test_that("rl_key produces expected URL and message", {
expect_equal(rl_use_iucn(), "http://apiv3.iucnredlist.org/api/v3/token")
expect_message(rl_use_iucn(), "After getting your key set")
})