ropensci-archive / nbaR

:warning: ARCHIVED :warning: R client library for the Netherlands Biodiversity Api (NBA)
Other
3 stars 2 forks source link

Named list #29

Closed hettling closed 5 years ago

hettling commented 5 years ago

Named lists in query conditions do not work?

library(nbaR)
sc <- SpecimenClient$new()
field <- 'identifications.defaultClassification.genus'
qc <- QueryCondition$new(field = field, operator = 'EQUALS', value = 'Solanum')
# success
qs <- QuerySpec$new(conditions = list(qc))
res <- sc$query(querySpec = qs)
res$content$totalSize
# fail
qc_list <- list('solanum' = qc)
qs <- QuerySpec$new(conditions = qc_list)
res <- sc$query(querySpec = qs)
res$content$totalSize
hettling commented 5 years ago

Problem is that named lists will create elements in the querySpec JSON:

> QuerySpec$new(conditions = list(qc))$toJSONString()
{
  "conditions": [
    {
      "field": "identifications.defaultClassification.genus",
      "operator": "EQUALS",
      "value": "Solanum"
    }
  ]
} 
> QuerySpec$new(conditions = list(solanum=qc))$toJSONString()
{
  "conditions": {
    "solanum": {
      "field": "identifications.defaultClassification.genus",
      "operator": "EQUALS",
      "value": "Solanum"
    }
  }
} 
hettling commented 5 years ago

This works now, unit test with above example added.