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

working codelist

parent a6e519f9
Pipeline #269005 passed with stage
in 21 seconds
get_codelist <- function() {
api <- api_class(
api_type = "codelist",
export_format = "SDMX-ML",
parameters = "level=1&annotations=true&additionalProp2=string&language=fr",
id = "CL_NOGA_SECTION"
)
api$get_response()
}
get_codelist()
get_one_level <- function() {
api_call <- api(
api_type = "nomenclature_one_level",
export_format = "CSV",
root_url = BASE_URL,
parameters = "level=1&annotations=true&additionalProp2=string&language=fr",
id = "HCL_CH_ISCO_19_PROF",
language = "fr",
)
api_call$get_url()
api_call$api_call()
}
get_one_level()
......@@ -2,7 +2,7 @@ library(hash)
library(methods)
library(glue)
api <- setRefClass(
api_class <- setRefClass(
"Api",
fields = list(
......@@ -18,10 +18,41 @@ api <- setRefClass(
),
methods = list(
api_call = function(){
initialize = function(
...,
export_format = "JSON",
root_url = BASE_URL,
parameters = "",
id = "",
language = "en",
version_format=2.1,
path = "."
){
callSuper(
...,
export_format = export_format,
root_url = root_url,
parameters = parameters,
id = id,
language = language,
version_format=version_format,
path = path
)
get_url()
},
get_response = function(){
request_function <- REQUEST_FUNCTION_MAPPING[[export_format]]
request_function(f("{root_url}/api/{api_url}"))
print(request_function)
if(parameters==""){
url = glue("{root_url}/api/{api_url}")
} else {
url = glue("{root_url}/api/{api_url}?{parameters}")
}
print(url)
request_function(url)
},
get_url = function() {
url_mapping <- hash(
# i14y
......@@ -72,33 +103,21 @@ api <- setRefClass(
)
api_call <- api(
api_call <- api_class(
api_type = "codelist",
export_format = "SDMX-ML",
parameters = "level=1&annotations=true&additionalProp2=string&language=fr",
id = "CL_NOGA_SECTION"
)
api_call$api_url
api_call$get_response()
api_call <- api_class(
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 = "."
parameters = "level=1&annotations=true&additionalProp2=string&language=fr",
id = "HCL_CH_ISCO_19_PROF"
)
api_call$get_url()
api_call$api_url
api_call$get_response()
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
DCAT_URL <- 'https://dcat.app.cfap02.atlantica.admin.ch'
# Request function
REQUEST_FUNCTION_MAPPING <- hash(
"SDMX-ML" = sdmx_request,
"JSON" = json_request,
"CSV" = csv_request
)
\ No newline at end of file
......@@ -5,7 +5,7 @@ library(hash)
sdmx_request <- function(url) {
as.data.frame(readSDMX(myUrl))
as.data.frame(readSDMX(url))
}
json_request <- function(url) {
......@@ -15,32 +15,3 @@ json_request <- function(url) {
csv_request <- function(url) {
read.csv(url)
}
REQUEST_FUNCTION_MAPPING <- hash(
"SDMX" = sdmx_request,
"JSON" = json_request,
"CSV" = csv_request
)
json <- fromJSON(rawToChar(GET("https://www.i14y.admin.ch/api/ContentConfigurations")$content))
names(json)
json$identifier
res <- GET("https://www.i14y.admin.ch/api/ContentConfigurations/HCL_CH_ISCO_19_PROF")
cc <- fromJSON(rawToChar(res$content))
res <- GET("https://www.i14y.admin.ch/api/Nomenclatures/Childnodes/HCL_CH_ISCO_19_PROF/fr/.?additionalProp1=string")
ncn <- fromJSON(rawToChar(res$content))
data1 <- read.csv("https://www.i14y.admin.ch/api/Nomenclatures/HCL_CH_ISCO_19_PROF/levelexport/CSV?level=1&annotations=true&additionalProp2=string&language=fr")
h[['csv']]("https://www.i14y.admin.ch/api/Nomenclatures/HCL_CH_ISCO_19_PROF/levelexport/CSV?level=1&annotations=true&additionalProp2=string&language=fr")
data2 <- read.csv("https://www.i14y.admin.ch/api/Nomenclatures/HCL_CH_ISCO_19_PROF/multiplelevels/CSV?language=fr&levelFrom=1&levelTo=4&annotations=true&additionalProp1=string")
myUrl <- "https://www.i14y.admin.ch/api/CodeLists/CL_NOGA_SECTION/exports/SDMX-ML/2.1?annotations=true"
dataset <- as.data.frame(readSDMX(myUrl))
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