api_call.R 5.49 KB
Newer Older
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
1
2
3
4
###############################################################
########################## i14y APIs ##########################
###############################################################

Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
5
6
7
8
9
# @export
get_codelist <- function(identifier,
                         export_format = "SDMX-ML",
                         version_format = 2.1,
                         annotations = FALSE) {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
10
11
12
13
14
15
16
17
18
19
  api <- api_class(
    api_type = "codelist",
    export_format = export_format,
    parameters = glue("annotations={tolower(annotations)}"),
    id = identifier
  )
  api$get_response()
}


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
20
get_content_configuration <- function() {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
21
22
23
  api <- api_class(api_type = "content_configuration")
  api$get_response()
}
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
24
25


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
26

Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
27
get_identifier_content <- function(identifier) {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
28
  api <- api_class(
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
29
30
    api_type = "content_configuration_identifier",
    id = identifier
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
31
32
33
  )
  api$get_response()
}
34

Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
35
36


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
37

Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
38
get_dataset_description <- function(identifier, language = "fr") {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
39
40
  api <- api_class(
    api_type = "dcat_dataset_description",
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
41
    id = identifier,
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
42
43
44
45
    language = language
  )
  api$get_response()
}
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
46
47
48



Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
49
get_dataset_information <- function(identifier, language = "en") {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
50
51
  api <- api_class(
    api_type = "dcat_dataset_information",
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
52
    id = identifier,
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
53
    language = language
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
54
  )
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
55
  api$get_response()
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
56
}
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
57
58
59



Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
60
get_data_structure <- function(identifier, language = "en") {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
61
62
  api <- api_class(
    api_type = "dcat_data_structure",
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
63
    id = identifier,
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
64
65
66
67
68
69
70
    language = language
  )
  api$get_response()
}



Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
71
72
73
74
get_nomenclature_path_nodes <- function(identifier,
                                        path = ".",
                                        filters = "",
                                        language = "en") {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
75
76
  api <- api_class(
    api_type = "nomenclature_path_nodes",
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
77
    id = identifier,
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
78
79
80
81
82
83
84
85
    path = path,
    parameters = stringify(filters),
    language = language
  )
  api$get_response()
}


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
86
87
88
89
90
91
get_nomenclature_one_level <- function(identifier,
                                       filters,
                                       level_number = 1,
                                       language = "en",
                                       annotations = FALSE) {
  parameters <- glue::glue("language={language}&level={level_number}&annotations={tolower(annotations)}&{stringify(filters)}")
92
93
94
  print(parameters)
  api <- api_class(
    api_type = "nomenclature_one_level",
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
95
    id = identifier,
96
    parameters = parameters,
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
97
    export_format = "CSV"
98
99
100
  )
  api$get_response()
}
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
101
102


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
103
104
105
106
107
108
109
get_nomenclature_multiple_levels <- function(identifier,
                                             filters,
                                             level_from = 1,
                                             level_to = 2,
                                             language = "en",
                                             annotations = FALSE) {
  parameters <- glue::glue("language={language}&levelFrom={level_from}&levelTo={level_to}&annotations={tolower(annotations)}&{stringify(filters)}")
110
111
  api <- api_class(
    api_type = "nomenclature_multiple_levels",
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
112
    id = identifier,
113
    parameters = parameters,
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
114
    export_format = "CSV"
115
116
117
118
119
120
121
122
  )
  api$get_response()
  ###############################################################
  # TODO: post processing in R
  ###############################################################
}


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
123
124
125
126
127
128
129
query_nomenclature <- function(identifier,
                               query,
                               page_number,
                               page_size,
                               filters,
                               language = "en") {
  parameters <- glue::glue("query={URLencode(query)}&page={page_number}&pageSize={page_size}&language={language}&{stringify(filters)}")
130
131
  api <- api_class(
    api_type = "nomenclature_search",
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
132
    id = identifier,
133
134
135
136
137
138
139
140
141
142
    parameters = parameters
  )
  api$get_response()
}



###############################################################
########################## dcat APIs ##########################
###############################################################
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
143

Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
144

Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
145
dcat_list_all_agents <- function() {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
146
147
148
149
150
151
152
153
  api <- api_class(
    api_type = "agents_list",
    root_url = DCAT_URL
  )
  api$get_response()
}


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
154
dcat_get_agent_from_id <- function(agent_id) {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
155
156
157
158
159
160
161
162
163
  api <- api_class(
    api_type = "agent_id",
    root_url = DCAT_URL,
    id = agent_id
  )
  api$get_response()
}


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
164
dcat_list_all_datasets <- function() {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
165
166
167
168
169
170
171
172
  api <- api_class(
    api_type = "dataset_list",
    root_url = DCAT_URL
  )
  api$get_response()
}


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
173
dcat_get_distributions_from_dataset_id <- function(dataset_id) {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
174
175
176
177
178
179
180
181
182
  api <- api_class(
    api_type = "dataset_id_distributions",
    root_url = DCAT_URL,
    id = dataset_id
  )
  api$get_response()
}


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
183
dcat_get_dataset_from_id <- function(dataset_id) {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
184
185
186
187
188
189
190
191
192
  api <- api_class(
    api_type = "dataset_id",
    root_url = DCAT_URL,
    id = dataset_id
  )
  api$get_response()
}


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
193
dcat_get_dataset_from_identifier <- function(identifier) {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
194
195
196
197
198
199
200
201
202
  api <- api_class(
    api_type = "dataset_identifier",
    root_url = DCAT_URL,
    id = identifier
  )
  api$get_response()
}


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
203
dcat_get_distributions_from_dataset_identifier <- function(identifier) {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
204
205
206
207
208
209
210
211
212
  api <- api_class(
    api_type = "dataset_identifier_distributions",
    root_url = DCAT_URL,
    id = identifier
  )
  api$get_response()
}


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
213
dcat_list_all_distributions <- function() {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
214
215
216
217
218
219
220
221
  api <- api_class(
    api_type = "distributions_list",
    root_url = DCAT_URL
  )
  api$get_response()
}


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
222
dcat_get_distribution_from_id <- function(distribution_id) {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
223
224
225
226
227
228
229
  api <- api_class(
    api_type = "distribution_id",
    root_url = DCAT_URL,
    id = distribution_id
  )
  api$get_response()
}