Commit a6e519f9 authored by Pauline Maury Laribière's avatar Pauline Maury Laribière
Browse files

api_class, constatns, format_request done

parent 1c6c0a19
Pipeline #268952 passed with stage
in 2 minutes and 27 seconds
library(hash)
library(methods)
library(glue)
api <- setRefClass(
"Api",
fields = list(
api_type = "character",
export_format = "character",
root_url = "character",
parameters = "character",
id = "character",
language = "character",
version_format="numeric",
path = "character",
api_url = "character"
),
methods = list(
api_call = function(){
request_function <- REQUEST_FUNCTION_MAPPING[[export_format]]
request_function(f("{root_url}/api/{api_url}"))
},
get_url = function() {
url_mapping <- hash(
# i14y
'codelist'=
glue('CodeLists/{id}/exports/{export_format}/{version_format}'),
'content_configuration' =
glue('ContentConfigurations'),
'content_configuration_identifier' =
glue('ContentConfigurations/{id}'),
'dcat_dataset_description' =
glue('Datasets/{id}/{language}/description'),
'dcat_dataset_information' =
glue('Datasets/{id}/{language}/distributions'),
'data_structure' =
glue('DataStructures/{id}/{language}'),
'nomenclature_path_nodes' =
glue('Nomenclatures/Childnodes/{id}/{language}/{path}'),
'nomenclature_one_level' =
glue('Nomenclatures/{id}/levelexport/CSV'),
'nomenclature_multiple_levels' =
glue('Nomenclatures/{id}/multiplelevels/CSV'),
'nomenclature_search' =
glue('Nomenclatures/{id}/search'),
# dcat
'agents_list' =
glue('Agent'),
'agent_id' =
glue('Agent/{id}'),
'dataset_list' =
glue('Dataset'),
'dataset_id_distributions' =
glue('Dataset/{id}/distributions'),
'dataset_id' =
glue('Dataset/{id}'),
'dataset_identifier' =
glue('Datataset/identifier/{id}'),
'dataset_identifier_distributions' =
glue('Datataset/identifier/{id}/distributions'),
'distributions_list' =
glue('Distribution'),
'distribution_id' =
glue('Distribution/{id}')
)
api_url <<- url_mapping[[api_type]]
}
)
)
api_call <- api(
api_type = "nomenclature_one_level",
export_format = "CSV",
root_url = BASE_URL,
parameters = "CL_NOGA_SECTION",
id = "CL_NOGA_SECTION",
language = "fr",
version_format=2.1,
path = "."
)
api_call$get_url()
api_call$api_url
name <- "Fred"
age <- 50
anniversary <- as.Date("1991-10-12")
glue('My name is {name},',
'my age next year is {age + 1},',
'my anniversary is {format(anniversary, "%A, %B %d, %Y")}.')
url_mapping <- hash(
# blablah
'codelist'=
glue('CodeLists/{name}'),
'content_configuration' =
glue('ContentConfigurations')
)
url_mapping[['codelist']]
# Root URL constants
BASE_URL <- 'https://www.i14y.admin.ch'
DCAT_URL <- 'https://dcat.app.cfap02.atlantica.admin.ch'
\ No newline at end of file
......@@ -17,12 +17,14 @@ csv_request <- function(url) {
}
REQUEST_FUNCTION_MAPPING <- hash(
"sdmx" = sdmx_request,
"json" = json_request,
"csv" = csv_request
"SDMX" = sdmx_request,
"JSON" = json_request,
"CSV" = csv_request
)
json <- fromJSON(rawToChar(GET("https://www.i14y.admin.ch/api/ContentConfigurations")$content))
names(json)
......
install.packages(c("httr", "jsonlite"))
devtools::install_github("opensdmx/rsdmx")
\ No newline at end of file
install.packages(c("httr", "jsonlite", "glue", "hash"))
devtools::install_github("opensdmx/rsdmx")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment