Skip to content

Commit

Permalink
Merge pull request #41 from OxfordIHTM/dev
Browse files Browse the repository at this point in the history
allow option to keep search output as JSON; fix #40
  • Loading branch information
ernestguevarra authored Feb 15, 2024
2 parents 2eec806 + 9f79dfe commit 7f1405d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
19 changes: 16 additions & 3 deletions R/icd_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#' the translations of ICD-11 completes. The values are language codes such as
#' en, es, zh, etc. Depending on the `release_id` specified, the available
#' languages will vary. Default is English ("en").
#' @param parse Logical. Should JSON response body be parsed? Default is
#' TRUE. If FALSE, response body is kept as raw JSON.
#'
#' @return An `httr2_response` object
#'
Expand All @@ -68,7 +70,8 @@ icd_search_foundation <- function(base_url = "https://id.who.int",
release = NULL,
highlight = FALSE,
api_version = c("v2", "v1"),
language = "en") {
language = "en",
parse = TRUE) {
## Get API version to use ----
api_version <- match.arg(api_version)

Expand Down Expand Up @@ -135,8 +138,18 @@ icd_search_foundation <- function(base_url = "https://id.who.int",
## Perform request ----
httr2::req_perform()

## Structure JSON response ----
httr2::resp_body_json(req)
## Determine what output to return ----
if (parse) {
## Structure JSON response ----
resp <- httr2::resp_body_json(req)
} else {
### Keep as JSON ----
resp <- req |>
httr2::resp_body_raw()
}

## Return response body ----
resp
}


2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pandoc: 3.1.1
pkgdown: 2.0.7
pkgdown_sha: ~
articles: {}
last_built: 2024-02-15T07:39Z
last_built: 2024-02-15T09:04Z
urls:
reference: https://oxford-ihtm.io/codigo/reference
article: https://oxford-ihtm.io/codigo/articles
Expand Down
10 changes: 8 additions & 2 deletions docs/reference/icd_search.html

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

2 changes: 1 addition & 1 deletion docs/search.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion man/icd_search.Rd

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

0 comments on commit 7f1405d

Please sign in to comment.