-
Notifications
You must be signed in to change notification settings - Fork 0
/
NEON-API-calls.R
124 lines (105 loc) · 4.56 KB
/
NEON-API-calls.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
## ---query the API------------------------------------------------------------------------------------
# Load the necessary libraries
library(httr)
library(jsonlite)
# Source configini file to get NEON token
source("/Users/kelsey/Github/neon-biorepo-tools/configini.R")
## ---Function to find sampleClasses for a given sampleID------------------------------------------------------------------------------------
find.sampleClass <- function(sampleID){
reqURL<-paste0("http://data.neonscience.org/api/v0/samples/classes?sampleTag=",sampleID,"&apiToken=",Neon_Token)
req<-GET(reqURL)
req.text <- content(req, as="text")
avail <- jsonlite::fromJSON(req.text,
simplifyDataFrame=T,
flatten=T)
avail.data<-avail$data$sampleClasses
return(avail.data)
}
## ---Sample Views Functions------------------------------------------------------------------------------------
# Functions to request data using the GET function & the API call & Make the data readable by jsonlite & flatten into list
view.sampID <- function(sampleID,sampleClass){
reqURL<-paste0("http://data.neonscience.org/api/v0/samples/view?sampleTag=",sampleID,
"&sampleClass=",sampleClass,"&apiToken=",Neon_Token)
req<-GET(reqURL)
req.text <- content(req, as="text")
avail <- jsonlite::fromJSON(req.text,
simplifyDataFrame=T,
flatten=T)
avail.data<-avail$data$sampleViews
return(avail.data)
}
view.uuid <- function(sampleUuid){
reqURL<-paste0("http://data.neonscience.org/api/v0/samples/view?sampleUuid=",sampleUuid,"&apiToken=",Neon_Token)
req<-GET(reqURL)
req.text <- content(req, as="text")
avail <- jsonlite::fromJSON(req.text,
simplifyDataFrame=T,
flatten=T)
avail.data<-avail$data$sampleViews
return(avail.data)
}
view.barcode <- function(sampleCode){
reqURL<-paste0("http://data.neonscience.org/api/v0/samples/view?barcode=",sampleCode,"&apiToken=",Neon_Token)
req<-GET(reqURL)
req.text <- content(req, as="text")
avail <- jsonlite::fromJSON(req.text,
simplifyDataFrame=T,
flatten=T)
avail.data<-avail$data$sampleViews
return(avail.data)
}
view.IGSN <- function(IGSN){
reqURL<-paste0("http://data.neonscience.org/api/v0/samples/view?archiveGuid=",IGSN,"&apiToken=",Neon_Token)
req<-GET(reqURL)
req.text <- content(req, as="text")
avail <- jsonlite::fromJSON(req.text,
simplifyDataFrame=T,
flatten=T)
avail.data<-avail$data$sampleViews
return(avail.data)
}
## ---Sample Downloads Functions------------------------------------------------------------------------------------
download.sampID <- function(sampleID,sampleClass,degree){
reqURL<-paste0("http://data.neonscience.org/api/v0/samples/download?sampleTag=",sampleID,
"&sampleClass=",sampleClass,"°ree=",degree,"&apiToken=",Neon_Token)
req<-GET(reqURL)
req.text <- content(req, as="text")
avail <- jsonlite::fromJSON(req.text,
simplifyDataFrame=T,
flatten=T)
avail.data<-avail$data$sampleViews
return(avail.data)
}
download.uuid <- function(sampleUuid,degree){
reqURL<-paste0("http://data.neonscience.org/api/v0/samples/download?sampleUuid=",sampleUuid,
"°ree=",degree,"&apiToken=",Neon_Token)
req<-GET(reqURL)
req.text <- content(req, as="text")
avail <- jsonlite::fromJSON(req.text,
simplifyDataFrame=T,
flatten=T)
avail.data<-avail$data$sampleViews
return(avail.data)
}
download.barcode <- function(sampleCode,degree){
reqURL<-paste0("http://data.neonscience.org/api/v0/samples/download?barcode=",sampleCode,
"°ree=",degree,"&apiToken=",Neon_Token)
req<-GET(reqURL)
req.text <- content(req, as="text")
avail <- jsonlite::fromJSON(req.text,
simplifyDataFrame=T,
flatten=T)
avail.data<-avail$data$sampleViews
return(avail.data)
}
download.IGSN <- function(IGSN,degree){
reqURL<-paste0("http://data.neonscience.org/api/v0/samples/download?archiveGuid=",IGSN,
"°ree=",degree,"&apiToken=",Neon_Token)
req<-GET(reqURL)
req.text <- content(req, as="text")
avail <- jsonlite::fromJSON(req.text,
simplifyDataFrame=T,
flatten=T)
avail.data<-avail$data$sampleViews
return(avail.data)
}