-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.R
37 lines (27 loc) · 844 Bytes
/
api.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#* @apiTitle Worldbank Download service
#* @apiVersion 0.0.1
#* @apiContact [email protected]
#* @apiDescription A minimal example to show how to bring a data pipeline to a service
#* @get /version
function() {
ejemplo <- fromJSON(
'{"version" : "0.0.1"}'
)
}
#* @param codigo World bank indicator code
#* @get /indicator
function(indicator_code = "FP.CPI.TOTL.ZG") {
url <- paste0("https://api.worldbank.org/v2/es/indicator/",
indicator_code, "?downloadformat=csv")
download(url, "file.zip", mode = "wb")
unzip("file.zip")
selected_file <- list.files(pattern = "^API")
gcs_upload(
file = selected_file,
bucket = "serviciobm",
name = paste0(indicator_code, ".csv"),
predefinedAcl = "bucketLevel"
)
file.remove( list.files(pattern = "*.csv"))
return(indicator_code)
}