Skip to content

Commit

Permalink
updating blog post and dev ver bump
Browse files Browse the repository at this point in the history
  • Loading branch information
John Waller committed Sep 25, 2024
1 parent 78d00a8 commit 2767e6b
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 33 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Description: A programmatic interface to the Web Service methods
retrieving information on data providers, getting species occurrence
records, getting counts of occurrence records, and using the GBIF
tile map service to make rasters summarizing huge amounts of data.
Version: 3.8.0.1
Version: 3.8.0.2
License: MIT + file LICENSE
Authors@R: c(
person("Scott", "Chamberlain", role = "aut", comment = c(ORCID="0000-0003-1444-9135")),
Expand Down
18 changes: 16 additions & 2 deletions R/occ_download_sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand All @@ -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",
Expand Down Expand Up @@ -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'))
Expand All @@ -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'))
Expand Down
31 changes: 30 additions & 1 deletion man/occ_download_sql.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/rgbif-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions tests/fixtures/occ_download_sql_1.yml
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
30 changes: 30 additions & 0 deletions tests/testthat/test-occ_download_sql.R
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"))
})







Loading

0 comments on commit 2767e6b

Please sign in to comment.