Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the GBIF issue for single argument queries #166

Merged
merged 7 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GBIF/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GBIF"
uuid = "ee291a33-5a6c-5552-a3c8-0f29a1181037"
authors = ["Timothée Poisot <timothee.poisot@umontreal.ca>"]
version = "0.4.1"
version = "0.4.2"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
5 changes: 3 additions & 2 deletions GBIF/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# GBIF wrapper for Julia

This is project offers an interface to the [GBIF] search API from
This is project offers an interface to the GBIF search API from
Julia. Current efforts focus on querying and exporting occurrences through the
`occurrence/search` endpoint. There is partial support for the taxonomic API.

The recommended way to use this package is through the
`SpeciesDistributionToolkit` package.
`SpeciesDistributionToolkit` package, which will transparently export all of the
`GBIF` types and methods.
5 changes: 4 additions & 1 deletion GBIF/src/occurrence.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
format_querypair_stem(stem::Bool) = replace(string(stem), " " => "%20")
format_querypair_stem(stem::Any) = replace(string(stem), " " => "%20")

function format_querypair_stem(stem::Tuple{T, T}) where {T <: Number}
Expand Down Expand Up @@ -44,7 +45,9 @@ function occurrence(key::String)::GBIFRecord
return GBIFRecord(result)
catch err
if err isa HTTP.Exceptions.StatusError
throw("Occurrence $(key) (at $(occ_url)) cannot be accessed - error code: $(err.status)")
throw(
"Occurrence $(key) (at $(occ_url)) cannot be accessed - error code: $(err.status)",
)
else
throw("Occurrence $(key) cannot be accessed")
end
Expand Down
4 changes: 3 additions & 1 deletion GBIF/src/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ function validate_occurrence_query(query::Pair)

# ENUMs
if query.first ∈ keys(gbifenums)
@assert query.second ∈ gbifenums[query.first]
if !(query.second ∈ gbifenums[query.first])
@error "The value $(query.second) is not a valid value for $(query.first)"
end
end
end
13 changes: 13 additions & 0 deletions GBIF/test/edgecases.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module GBIFEdgeCasesTest
using Test
using GBIF

# When there is a single argument used for a query, sometimes the second position gets
# converted to not text
queryset = ["hasCoordinate" => true]
@test length(occurrences(queryset...)) > 0

queryset = ["hasCoordinate" => true]
@test length(occurrences(taxon("Alces alces"), queryset...)) > 0

end
5 changes: 3 additions & 2 deletions GBIF/test/occurrence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ o = occurrence(k)
@test o.key == k

# This occurrence has been deleted, so this needs some wrapping
k = 1258202889
@test_throws "cannot be accessed - error code" occurrence(k)
# It has been added back at some point
# k = 1258202889
# @test_throws "cannot be accessed - error code" occurrence(k)

# This occurrence is incorrectly formatted for some reason
k = 1039645472
Expand Down
1 change: 1 addition & 0 deletions GBIF/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ tests = [
"methods" => "methods.jl",
"query support" => "query.jl",
"tables interface" => "tables.jl",
"edge cases" => "edgecases.jl",
]

for test in tests
Expand Down