-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John Waller
committed
Sep 25, 2024
1 parent
78d00a8
commit 2767e6b
Showing
8 changed files
with
200 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,23 @@ | |
#' @param pwd your GBIF password | ||
#' @param email your email address | ||
#' @param curlopts list of curl options | ||
#' | ||
#' | ||
#' @details | ||
#' This is an experimental feature, and the implementation may change throughout | ||
#' 2024. The feature is currently only available for preview by invited users. | ||
#' Contact [email protected] to request access. | ||
#' | ||
#' @return an object of class 'occ_download_sql' | ||
#' | ||
#' @references | ||
#' https://techdocs.gbif.org/en/data-use/api-sql-downloads | ||
#' | ||
#' @name occ_download_sql | ||
#' @export | ||
#' | ||
#' @examples /dontrun{ | ||
#' | ||
#' occ_download_sql("SELECT gbifid,countryCode FROM occurrence | ||
#' WHERE genusKey = 2435098") | ||
#' } | ||
#' | ||
occ_download_sql <- function(q = NULL, | ||
|
@@ -47,6 +57,7 @@ occ_download_sql <- function(q = NULL, | |
|
||
} | ||
|
||
#' @name occ_download_sql | ||
#' @export | ||
occ_download_sql_validate <- function(req = NULL, user = NULL, pwd = NULL) { | ||
stopifnot(is.list(req)) | ||
|
@@ -57,6 +68,7 @@ occ_download_sql_validate <- function(req = NULL, user = NULL, pwd = NULL) { | |
out | ||
} | ||
|
||
#' @name occ_download_sql | ||
#' @export | ||
occ_download_sql_prep <- function(q=NULL, | ||
format = "SQL_TSV_ZIP", | ||
|
@@ -97,6 +109,7 @@ occ_download_sql_prep <- function(q=NULL, | |
|
||
} | ||
|
||
#' @name occ_download_sql | ||
#' @export | ||
print.occ_download_sql <- function(x) { | ||
stopifnot(inherits(x, 'occ_download_sql')) | ||
|
@@ -123,6 +136,7 @@ print.occ_download_sql <- function(x) { | |
cat_n(" ", attr(x,"citation")) | ||
} | ||
|
||
#' @name occ_download_sql | ||
#' @export | ||
print.occ_download_sql_prep <- function(x) { | ||
stopifnot(inherits(x, 'occ_download_sql_prep')) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
http_interactions: | ||
- request: | ||
method: post | ||
uri: https://api.gbif.org/v1/occurrence/download/request/validate | ||
body: | ||
encoding: '' | ||
string: '{"sendNotification":[true],"notificationAddresses":["<gbif_user>@gbif.org"],"format":"SQL_TSV_ZIP","sql":"SELECT | ||
gbifid,countryCode FROM occurrence WHERE genusKey = 2435098"}' | ||
headers: | ||
Accept-Encoding: gzip, deflate | ||
Content-Type: application/json | ||
Accept: application/json | ||
response: | ||
status: | ||
status_code: '201' | ||
message: Created | ||
explanation: Document created, URL follows | ||
headers: | ||
status: HTTP/1.1 201 Created | ||
content-type: application/json | ||
body: | ||
encoding: '' | ||
file: no | ||
string: '{"sql":"SELECT gbifid, countrycode\nFROM occurrence\nWHERE occurrence.genuskey | ||
= 2435098","notificationAddresses":["<gbif_user>@gbif.org"],"sendNotification":false,"type":"OCCURRENCE","format":"SQL_TSV_ZIP"}' | ||
recorded_at: 2024-09-24 14:05:47 GMT | ||
recorded_with: vcr/1.2.0, webmockr/0.9.0 | ||
- request: | ||
method: post | ||
uri: https://api.gbif.org/v1/occurrence/download/request | ||
body: | ||
encoding: '' | ||
string: '{"sendNotification":[true],"notificationAddresses":["<gbif_user>@gbif.org"],"format":"SQL_TSV_ZIP","sql":"SELECT | ||
gbifid,countryCode FROM occurrence WHERE genusKey = 2435098"}' | ||
headers: | ||
Accept-Encoding: gzip, deflate | ||
Content-Type: application/json | ||
Accept: application/json | ||
response: | ||
status: | ||
status_code: '201' | ||
message: Created | ||
explanation: Document created, URL follows | ||
headers: | ||
status: HTTP/1.1 201 Created | ||
content-type: application/json | ||
body: | ||
encoding: '' | ||
file: no | ||
string: 0028400-240906103802322 | ||
recorded_at: 2024-09-24 14:05:47 GMT | ||
recorded_with: vcr/1.2.0, webmockr/0.9.0 | ||
- request: | ||
method: get | ||
uri: https://api.gbif.org/v1/occurrence/download/0028400-240906103802322 | ||
body: | ||
encoding: '' | ||
string: '' | ||
headers: | ||
Accept-Encoding: gzip, deflate | ||
Accept: application/json, text/xml, application/xml, */* | ||
response: | ||
status: | ||
status_code: '200' | ||
message: OK | ||
explanation: Request fulfilled, document follows | ||
headers: | ||
status: HTTP/1.1 200 OK | ||
content-type: application/json | ||
body: | ||
encoding: '' | ||
file: no | ||
string: '{"key":"0028400-240906103802322","doi":"10.15468/dl.fnrv3s","license":"unspecified","request":{"sql":"SELECT | ||
gbifid,countryCode FROM occurrence WHERE genusKey = 2435098","creator":"<gbif_user>","notificationAddresses":["<gbif_user>@gbif.org"],"sendNotification":false,"type":"OCCURRENCE","format":"SQL_TSV_ZIP"},"created":"2024-09-24T14:05:47.599+00:00","modified":"2024-09-24T14:05:47.599+00:00","eraseAfter":"2025-03-24T14:05:47.552+00:00","status":"PREPARING","downloadLink":"https://api.gbif.org/v1/occurrence/download/request/0028400-240906103802322.zip","size":0,"totalRecords":0,"numberDatasets":0,"source":"rgbif"}' | ||
recorded_at: 2024-09-24 14:05:47 GMT | ||
recorded_with: vcr/1.2.0, webmockr/0.9.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
test_that("occ_download_sql : real requests work", { | ||
skip_on_cran() | ||
skip_on_ci() | ||
|
||
vcr::use_cassette("occ_download_sql_1", { | ||
qqq <- occ_download_sql("SELECT gbifid,countryCode FROM occurrence WHERE genusKey = 2435098") | ||
}, match_requests_on = c("method", "uri", "body")) | ||
expect_is(qqq, "occ_download_sql") | ||
expect_equal(attr(qqq, "status"), "PREPARING") | ||
expect_equal(attr(qqq, "format"), "SQL_TSV_ZIP") | ||
print(qqq) | ||
|
||
}) | ||
|
||
test_that("occ_download_sql : fails well", { | ||
skip_on_cran() | ||
skip_on_ci() | ||
|
||
expect_error(occ_download_sql("dog")) | ||
expect_error(occ_download_sql("SELECT * FROM occurrence")) | ||
expect_error(occ_download_sql("SELECT dog FROM occurrence")) | ||
}) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.