Skip to content

Commit

Permalink
Add argument encoding in api_get() (#246)
Browse files Browse the repository at this point in the history
* Add encoding argument to api_get()
  • Loading branch information
KKamel67 authored Apr 30, 2024
1 parent d796d68 commit cb61dbd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: antaresRead
Type: Package
Title: Import, Manipulate and Explore the Results of an 'Antares' Simulation
Version: 2.6.1
Version: 2.6.2
Authors@R: c(
person("Tatiana", "Vargas", email = "[email protected]", role = c("aut", "cre")),
person("Jalal-Edine", "ZAWAM", role = "aut"),
Expand Down
16 changes: 15 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
> Copyright © 2016 RTE Réseau de transport d’électricité
# antaresRead 2.6.1
# antaresRead 2.6.2 (development)

NEW FEATURES :
* `api_get()` add encoding argument to pass to `httr::content()`

BUGFIXES :

BREAKING CHANGES :

DATA :

PERFORMANCE :


# antaresRead 2.6.1

BUGFIXES :

Expand Down
11 changes: 7 additions & 4 deletions R/API-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#' @param ... Additional arguments passed to API method.
#' @param default_endpoint Default endpoint to use.
#' @param parse_result `character` options for parameter `as` of function [httr::content()]
#' @param encoding argument to pass as argument to the function [httr::content()]
#' @param opts Antares simulation options or a `list` with an `host = ` slot.
#'
#' @return Response from the API.
Expand All @@ -24,16 +25,18 @@
#' endpoint = NULL,
#' parse_result = NULL)
#'
#' # you can force parse options as text
#' # you can force parse options as text and encoding to UTF-8
#' api_get(opts = list(host = "http://0.0.0.0:8080"),
#' endpoint = NULL,
#' parse_result = "text")
#' parse_result = "text",
#' encoding = "UTF-8")
#'
#' }
api_get <- function(opts,
endpoint, ...,
default_endpoint = "v1/studies",
parse_result = NULL) {
parse_result = NULL,
encoding = NULL) {
if (inherits(endpoint, "AsIs")) {
opts$host <- endpoint
endpoint <- NULL
Expand Down Expand Up @@ -74,7 +77,7 @@ api_get <- function(opts,
stop_for_status(result, task = mess_error)
}else
warn_for_status(result)
content(result, as = parse_result)
content(result, as = parse_result, encoding = encoding)
}

#' @export
Expand Down
10 changes: 7 additions & 3 deletions man/API-methods.Rd

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

0 comments on commit cb61dbd

Please sign in to comment.