api_call.R 4.78 KB
Newer Older
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
1
library(hash)
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
2

Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
3
4
5
6
7
8
9
10
11
###############################################################
########################## i14y APIs ##########################
###############################################################

get_codelist <- function(
  identifier, 
  export_format="SDMX-ML", 
  version_format=2.1, 
  annotations=FALSE
12
){
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  api <- api_class(
    api_type = "codelist",
    export_format = export_format,
    parameters = glue("annotations={tolower(annotations)}"),
    id = identifier
  )
  api$get_response()
}


get_content_configuration <- function(){
  api <- api_class(api_type = "content_configuration")
  api$get_response()
}
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
27
28


Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
29
30

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

Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
38
39


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

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



Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
52
53
54
55
56
get_dataset_information <- function(identifier, language='en'){
  api <- api_class(
    api_type = "dcat_dataset_information",
    id = identifier, 
    language = language
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
57
  )
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
58
  api$get_response()
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
59
}
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73



get_data_structure <- function(identifier, language='en'){
  api <- api_class(
    api_type = "dcat_data_structure",
    id = identifier, 
    language = language
  )
  api$get_response()
}



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


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


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
get_nomenclature_multiple_levels <- function(
  identifier, 
  filters, 
  level_from=1, 
  level_to=2,
  language='en', 
  annotations=FALSE
){
  parameters = glue("language={language}&levelFrom={level_from}&levelTo={level_to}&annotations={tolower(annotations)}&{stringify(filters)}")
  api <- api_class(
    api_type = "nomenclature_multiple_levels",
    id = identifier, 
    parameters = parameters,
    export_format= "CSV"
  )
  api$get_response()
  ###############################################################
  # TODO: post processing in R
  ###############################################################
}


query_nomenclature <- function(
  identifier, 
  query,
  page_number,
  page_size,
  filters,
  language='en'
){
  parameters = glue("query={URLencode(query)}&page={page_number}&pageSize={page_size}&language={language}&{stringify(filters)}")
  api <- api_class(
    api_type = "nomenclature_search",
    id = identifier, 
    parameters = parameters
  )
  api$get_response()
}



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

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

Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
dcat_list_all_agents <- function(){
  api <- api_class(
    api_type = "agents_list",
    root_url = DCAT_URL
  )
  api$get_response()
}


dcat_get_agent_from_id <- function(agent_id){
  api <- api_class(
    api_type = "agent_id",
    root_url = DCAT_URL,
    id = agent_id
  )
  api$get_response()
}


dcat_list_all_datasets <- function(){
  api <- api_class(
    api_type = "dataset_list",
    root_url = DCAT_URL
  )
  api$get_response()
}


dcat_get_distributions_from_dataset_id <- function(dataset_id){
  api <- api_class(
    api_type = "dataset_id_distributions",
    root_url = DCAT_URL,
    id = dataset_id
  )
  api$get_response()
}


dcat_get_dataset_from_id <- function(dataset_id){
  api <- api_class(
    api_type = "dataset_id",
    root_url = DCAT_URL,
    id = dataset_id
  )
  api$get_response()
}


dcat_get_dataset_from_identifier <- function(identifier){
  api <- api_class(
    api_type = "dataset_identifier",
    root_url = DCAT_URL,
    id = identifier
  )
  api$get_response()
}


dcat_get_distributions_from_dataset_identifier <- function(identifier){
  api <- api_class(
    api_type = "dataset_identifier_distributions",
    root_url = DCAT_URL,
    id = identifier
  )
  api$get_response()
}


dcat_list_all_distributions <- function(){
  api <- api_class(
    api_type = "distributions_list",
    root_url = DCAT_URL
  )
  api$get_response()
}


dcat_get_distribution_from_id <- function(distribution_id){
  api <- api_class(
    api_type = "distribution_id",
    root_url = DCAT_URL,
    id = distribution_id
  )
  api$get_response()
}