Skip to content

Commit

Permalink
add pagination support; add image fetch complement to Darwin Core API…
Browse files Browse the repository at this point in the history
… call
  • Loading branch information
wbbaker committed Sep 30, 2024
1 parent e1f2b21 commit c02c541
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/modules/otus/services/TaxonWorks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { makeAPIRequest } from '@/utils/request'

/**
* Generate query params for pagination.
* @param opt.per {number} - Number of items per page.
* @param opt.page {number} - Page number
* @returns {""|string}
*/
const perPage = (opt) => {
const { per, page } = opt ?? {}
const queryParams = [per && `per=${per}`, page && `page=${page}`].filter(Boolean).join("&")
return queryParams && `?${queryParams}` // prepend "?" if there are any query params
}

export default class TaxonWorks {
static getTaxonNameCitations(taxonId, opt) {
return makeAPIRequest.get(`/taxon_names/${taxonId}/inventory/catalog`, opt)
Expand Down Expand Up @@ -59,24 +71,13 @@ export default class TaxonWorks {
return makeAPIRequest.get(`/otus/${otuId}/inventory/content`, opt)
}

// Note that this could support multiple OTUs.
// The API takes a comma-separated list of OTU IDs.
static getCollectionObjects(otuId, opt) {
return makeAPIRequest.get(`/collection_objects?otu_id[]=${otuId}`, opt)
// See taxonworks/lib/collection_object/filter.rb Queries:CollectionObject:Filter for full list of options.
// However, none seems to change the result.
/*
@with_buffered_collecting_event = boolean_param(params, :with_buffered_collecting_event)
@with_buffered_determinations = boolean_param(params, :with_buffered_determinations)
@with_buffered_other_labels = boolean_param(params, :with_buffered_other_labels)
*/
// return makeAPIRequest.get(`/collection_objects?otu_id[]=${otuId}&with_buffered_determination=true`, opt)
// return makeAPIRequest.get(`/collection_objects?otu_id[]=${otuId}&descendants=true`, opt)
// return makeAPIRequest.get(`/collection_objects?otu_id[]=${otuId}/dwc.json`, opt)
}

static getOtuInventoryDarwinCore(otuId, opt) {
return makeAPIRequest.get(`/otus/${otuId}/inventory/dwc.json`, opt)
/** The descendant taxa of an OTU, in Darwin Core format. */
static getDescendantsDarwinCore(otuId, opt) {
return makeAPIRequest.get(`/otus/${otuId}/inventory/dwc.json${perPage(opt)}`, opt)
}

static getDescendantsImageGallery(otuId, opt) {
return makeAPIRequest.get(`/otus/${otuId}/inventory/dwc_gallery.json${perPage(opt)}`, opt)
}

/** Load image info (thumbnail, etc) from a URL such as one in a Darwin Core 'associatedMedia' field. */
Expand Down

0 comments on commit c02c541

Please sign in to comment.