Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
DSCC
FSO Metadata Auto R
Commits
a6e519f9
Commit
a6e519f9
authored
Oct 20, 2021
by
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
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
api_class.R
0 → 100644
View file @
a6e519f9
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'
]]
constants.R
0 → 100644
View file @
a6e519f9
# 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
format_request.R
View file @
a6e519f9
...
...
@@ -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.R
View file @
a6e519f9
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"
)
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