Skip to content

Commit

Permalink
add tests/NEWs
Browse files Browse the repository at this point in the history
  • Loading branch information
LewisAJones committed Jan 16, 2024
1 parent 0ee2ec5 commit 6fb8202
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ importFrom(grid,rasterGrob)
importFrom(grid,unit)
importFrom(httr,GET)
importFrom(httr,POST)
importFrom(httr,add_headers)
importFrom(httr,content)
importFrom(jsonlite,fromJSON)
importFrom(jsonlite,toJSON)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# rphylopic (development version)

* Added add_phylopic_legend (#83)
* Added permalink generation option to get_attribution (#81)

# rphylopic 1.3.0

Expand Down
8 changes: 7 additions & 1 deletion R/get_attribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#' including: contributor name, contributor uuid, contributor contact,
#' image uuid, license, and license abbreviation. If `text` is set to
#' `TRUE`, a text paragraph with the contributor name, year of contribution,
#' and license type is returned.
#' and license type is returned. If `permalink` is set to `TRUE`, a
#' permanent link (hosted by [PhyloPic](https://www.phylopic.org)) will be
#' generated. This link can be used to view and share details about the
#' image silhouettes, including contributors and licenses.
#' @importFrom knitr combine_words
#' @importFrom utils packageVersion
#' @importFrom httr GET
Expand All @@ -35,6 +38,8 @@
#' uuids <- get_uuid(name = "Scleractinia", n = 5)
#' # Get attribution data for uuids
#' get_attribution(uuid = uuids, text = TRUE)
#' # Get attribution data for uuids and create permalink
#' get_attribution(uuid = uuids, text = TRUE, permalink = TRUE)
#' }
get_attribution <- function(uuid = NULL, img = NULL, text = FALSE,
permalink = FALSE) {
Expand Down Expand Up @@ -123,6 +128,7 @@ get_attribution <- function(uuid = NULL, img = NULL, text = FALSE,
if (permalink) {
att <- paste0(att, " Permalink: ", perm, ".")

Check warning on line 129 in R/get_attribution.R

View check run for this annotation

Codecov / codecov/patch

R/get_attribution.R#L129

Added line #L129 was not covered by tests
}
return(message(att))
}
} else if (length(uuid) > 1 && text) {
att <- lapply(att, function(x) {
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.r
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ phy_GET <- function(path, query = list(), ...) {
jsn
}

#' @importFrom httr POST
#' @importFrom httr POST add_headers
#' @importFrom jsonlite toJSON
#' @importFrom curl nslookup
phy_POST <- function(path, body = list(), ...) {
Expand Down
7 changes: 6 additions & 1 deletion man/get_attribution.Rd

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

4 changes: 4 additions & 0 deletions tests/testthat/test-get_attribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ test_that("get_attribution works", {
# Check img arg
img <- get_phylopic(uuid = uuid[1])
expect_true(is.list(get_attribution(img = img)))
# Check permalink generation
perm <- get_attribution(uuid = uuid, permalink = TRUE)
expect_true("permalink" %in% names(perm))
expect_message(get_attribution(uuid = uuid, text = TRUE, permalink = TRUE))

# Expect error
expect_error(get_attribution(uuid = NULL))
Expand Down

0 comments on commit 6fb8202

Please sign in to comment.