Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
DSCC
FSO Metadata Auto R
Commits
cabda009
Commit
cabda009
authored
Mar 07, 2022
by
Pauline Maury Laribière
Browse files
adding possibility for multi languages
parent
02b8543d
Pipeline
#325547
passed with stage
in 14 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
R/api_call.R
View file @
cabda009
#' Get a codelist based on an identifier
#'
#' @param identifier the codelist's identifier
#' @param language string for language to return.
#' Available are 'fr', 'de', 'it', 'en'.
#' @param language string for language(s) to return.
#' Available are 'all', 'fr', 'de', 'it', 'en'.
#' If 'all' (default), all languages are returned.
#' @param export_format the export's format
#' Available are CSV, XLSX, SDMX-ML or JSON.
#' @param version_format the export format's version
...
...
@@ -12,19 +13,18 @@
#' @return response based on the export format
#' @export
get_codelist
<-
function
(
identifier
,
language
=
"
fr
"
,
language
=
"
all
"
,
export_format
=
"SDMX-ML"
,
version_format
=
2.1
,
annotations
=
FALSE
)
{
api
<-
api_class
(
api_type
=
"codelist"
,
id
=
identifier
,
language
=
language
,
export_format
=
export_format
,
parameters
=
glue
::
glue
(
"annotations={tolower(annotations)}"
),
id
=
identifier
)
dplyr
::
select
(
api
$
get_response
(),
dplyr
::
contains
(
language
)
|
dplyr
::
matches
(
"id"
)
parameters
=
glue
::
glue
(
"annotations={tolower(annotations)}"
)
)
api
$
get_response
()
}
...
...
@@ -43,18 +43,17 @@ get_codelist <- function(identifier,
get_nomenclature_one_level
<-
function
(
identifier
,
filters
=
list
(),
level_number
=
1
,
language
=
"
fr
"
,
language
=
"
all
"
,
annotations
=
FALSE
)
{
parameters
<-
glue
::
glue
(
"language={language}"
,
"&level={level_number}"
,
"level={level_number}"
,
"&annotations={tolower(annotations)}"
,
"&{list_to_string(filters)}"
)
print
(
parameters
)
api
<-
api_class
(
api_type
=
"nomenclature_one_level"
,
id
=
identifier
,
language
=
language
,
parameters
=
parameters
,
export_format
=
"CSV"
)
...
...
R/api_class.R
View file @
cabda009
...
...
@@ -6,8 +6,8 @@
#' Available are CSV, XLSX, SDMX-ML and JSON
#' @field parameters character. Additional request parameters
#' @field id character. The identifier or id of the request's object
#' @field language character (default = "
en
"). Language of the response data.
#' Available are 'fr', 'de', 'it', 'en'
#' @field language character (default = "
all
"). Language of the response data.
#' Available are
'all',
'fr', 'de', 'it', 'en'
#' @field version_format numeric (default = 2.1). The export format's version
#' (2.0 or 2.1 when format is SDMX-ML)
#' (for 'codelist')
...
...
@@ -30,7 +30,7 @@ api_class <- setRefClass(
export_format
=
"JSON"
,
parameters
=
""
,
id
=
""
,
language
=
"
en
"
,
language
=
"
all
"
,
version_format
=
2.1
)
{
callSuper
(
...
,
...
...
@@ -43,15 +43,27 @@ api_class <- setRefClass(
get_url
(
id
,
export_format
,
version_format
,
language
)
},
get_response
=
function
()
{
# Select type of call to API
request_function
<-
REQUEST_FUNCTION_MAPPING
[[
export_format
]]
if
(
parameters
==
""
)
{
url
<-
glue
::
glue
(
"{BASE_URL}/api/{api_url}"
)
}
else
{
url
<-
glue
::
glue
(
"{BASE_URL}/api/{api_url}?{parameters}"
)
}
request_function
(
url
)
# API call
res
<-
request_function
(
url
)
# If specified language, keep only language specific columns
if
(
language
!=
"all"
)
{
res
<-
dplyr
::
select
(
res
,
dplyr
::
contains
(
language
)
|
dplyr
::
matches
(
"id"
)
)
}
res
},
get_url
=
function
(
id
,
export_format
,
version_format
,
language
)
{
# Map function names to specific API URL
url_mapping
<-
list
(
"codelist"
=
glue
::
glue
(
"CodeLists/{id}/exports/{export_format}/{version_format}"
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment