Skip to content

Commit

Permalink
occurrence search is broken (#9)
Browse files Browse the repository at this point in the history
* pass keywords to http query

* fix ocurrence search tests
  • Loading branch information
tiemvanderdeure committed Jan 29, 2024
1 parent df850dc commit b313812
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/occurrence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,15 @@ $(_keydocs(OCCURRENCE_KEY_DESC, keys(OCCURRENCE_KEY_DESC)))
"""
function occurrence_search end
function occurrence_search(species::Species; kw...)
occurrence_search(; q=_bestquery(species)[1][2], kw...)
occurrence_search(; _bestquery(species)..., kw...)
end
occurrence_search(q; kw...) = occurrence_search(; q, kw...)
function occurrence_search(; returntype=nothing, limit=20, offset=0, kw...)
if !isnothing(returntype)
allowed_rt = keys(OCCURRENCE_SEARCH_RETURNTYPE)
returntype in allowed_rt || throw(ArgumentError("$returntype not in $allowed_rt"))
url = _joinurl(OCCURRENCE_SEARCH_URL, returntype)
query = _format_query((; limit, kw...), keys(OCCURRENCE_KEY_DESC))
query = _format_query((; limit, q = kw[1]), keys(OCCURRENCE_KEY_DESC))
request = HTTP.get(url; query)
return _handle_request(JSON3.read, request)
end
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ end
results = occurrence_search(sp)
oc1 = results[1]
@test oc1 isa GBIF2.Occurrence
@test oc1.genus == "Hippophae"
@test all(results.species .== "Coracina newtoni")
@testset "occurrence tables write to CSV" begin
CSV.write("occurence_test.csv", results)
df = CSV.read("occurence_test.csv", DataFrame)
Expand All @@ -110,7 +110,7 @@ end
end
end
@test_throws ArgumentError species_search("Lalage newtoni"; not_a_keyword=2)
results = occurrence_search(sp; returntype=:catalogNumber)
results = occurrence_search(returntype=:occurrenceId, q = "https://www.inaturalist.org/observations")
@test results isa AbstractVector{<:String} # TODO maybe it should be specialised to Int
results = occurrence_search("")
end
Expand Down

0 comments on commit b313812

Please sign in to comment.