Newer
Older
#' Api class to make appropriate request based on parameters
#'
#' @field api_type character. The name of the api to call (see url_mapping)
#' @field export_format character (default = "JSON"). The export's format
#' Available are CSV, XLSX, SDMX-ML and JSON
#' @field root_url character (default = "BASE_URL"). Root url to call (for i14y or dcat)
#' @field parameters character. Additional request parameters
#' @field id character. The identifier or id of the request's object
#' @field language character (default = "en"). The language of the response data.
#' Available are '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')
#' @field path character. The path leading to the nodes
#' (for 'nomenclature_search')
#' @field api_url character. The url to make the request to.
#'
#' @examples
#' api <- api_class(api_type = "codelist", id = "CL_NOGA_SECTION")
#' api <- api_class(api_type = "content_configuration")
api_type = "character",
export_format = "character",
root_url = "character",
parameters = "character",
id = "character",
language = "character",
path = "character",
api_url = "character"
),
methods = list(
initialize = function(...,
export_format = "JSON",
root_url = BASE_URL,
parameters = "",
id = "",
language = "en",
version_format = 2.1,
path = ".") {
...,
export_format = export_format,
root_url = root_url,
parameters = parameters,
id = id,
language = language,
version_format = version_format,
request_function <- REQUEST_FUNCTION_MAPPING[[export_format]]
if (parameters == "") {
url <- glue::glue("{root_url}/api/{api_url}")
url <- glue::glue("{root_url}/api/{api_url}?{parameters}")
get_url = function() {
"codelist" =
glue::glue("CodeLists/{id}/exports/{export_format}/{version_format}"),
"content_configuration" =
glue::glue("ContentConfigurations"),
"content_configuration_identifier" =
glue::glue("ContentConfigurations/{id}"),
"dcat_data_structure" =
glue::glue("DataStructures/{id}/{language}"),
"dcat_dataset_description" =
glue::glue("Datasets/{id}/{language}/description"),
"dcat_dataset_information" =
glue::glue("Datasets/{id}/{language}/distributions"),
"nomenclature_path_nodes" =
glue::glue("Nomenclatures/Childnodes/{id}/{language}/{path}"),
"nomenclature_one_level" =
glue::glue("Nomenclatures/{id}/levelexport/CSV"),
"nomenclature_multiple_levels" =
glue::glue("Nomenclatures/{id}/multiplelevels/CSV"),
"nomenclature_search" =
glue::glue("Nomenclatures/{id}/search"),
"agents_list" =
glue::glue("Agent"),
"agent_id" =
glue::glue("Agent/{id}"),
"dataset_list" =
glue::glue("Dataset"),
"dataset_id_distributions" =
glue::glue("Dataset/{id}/distributions"),
"dataset_id" =
glue::glue("Dataset/{id}"),
"dataset_identifier" =
glue::glue("Datataset/identifier/{id}"),
"dataset_identifier_distributions" =
glue::glue("Datataset/identifier/{id}/distributions"),
"distributions_list" =
glue::glue("Distribution"),
"distribution_id" =
glue::glue("Distribution/{id}")
)
api_url <<- url_mapping[[api_type]]
}
)
)