Module: Colrapi
- Extended by:
- Configuration
- Defined in:
- lib/colrapi.rb,
lib/colrapi/error.rb,
lib/colrapi/request.rb,
lib/colrapi/version.rb
Defined Under Namespace
Classes: BadGateway, BadRequest, Error, GatewayTimeout, InternalServerError, NotFound, Request, ServiceUnavailable
Constant Summary collapse
- VERSION =
"0.1.2"
Class Method Summary collapse
-
.archive(dataset_id, attempt: nil, verbose: false) ⇒ Binary
Get a dataset’s original archive.
-
.assembly(dataset_id, verbose: false) ⇒ Hash
Get assembly status.
-
.dataset(dataset_id: nil, attempt: nil, q: nil, short_title: nil, code: nil, private: nil, released_from: nil, contributes_to: nil, has_source_dataset: nil, has_gbif_id: nil, gbif_id: nil, gbif_publisher_id: nil, editor: nil, reviewer: nil, modified_by: nil, origin: nil, type: nil, license: nil, row_type: nil, created_after: nil, created_before: nil, issued_after: nil, issued_before: nil, modified_after: nil, modified_before: nil, min_size: nil, sort_by: nil, reverse: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get dataset metadata.
-
.decision(dataset_id, decision_id: nil, name: nil, rank: nil, modified_by: nil, broken: nil, subject_dataset_id: nil, mode: nil, subject: nil, offset: nil, limit: nil, verbose: false) ⇒ Hash, Boolean
Get project decisions.
-
.diff(dataset_id, dataset2_id, root_id: nil, root2_id: nil, min_rank: nil, authorship: nil, include_synonyms: nil, include_parent: nil, parent_rank: nil, offset: nil, limit: nil, token: nil, verbose: false) ⇒ String, Boolean
Get names diff between 2 datasets.
-
.duplicate(dataset_id, offset: nil, limit: nil, verbose: false) ⇒ Object
Get duplicate names.
-
.editor(dataset_id, token, verbose: false) ⇒ Object
Get editor info.
-
.estimate(dataset_id, estimate_id: nil, name: nil, rank: nil, modified_by: nil, broken: nil, min: nil, max: nil, offset: nil, limit: nil, verbose: false) ⇒ Hash, Boolean
Get estimates.
-
.export(dataset_id, show_id: nil, verbose: false) ⇒ Hash, Boolean
TODO: /dataset/key/export is covered, but /export and /export/id are not Get a dataset export.
-
.importer(dataset_id: nil, dataset_id_filter: nil, state: nil, running: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get importer status.
-
.issues(dataset_id, issue: nil, mode: 'verbatim', offset: nil, limit: nil, verbose: false) ⇒ Array, ...
Get data quality issues.
-
.logo(dataset_id, size: nil, verbose: false) ⇒ Binary
Get a dataset’s logo.
-
.matching(dataset_id, name: nil, authorship: nil, code: nil, rank: nil, within_superkingdom: nil, within_kingdom: nil, within_subkingdom: nil, within_superphylum: nil, within_phylum: nil, within_subphylum: nil, within_superclass: nil, within_class: nil, within_subclass: nil, within_superorder: nil, within_order: nil, within_suborder: nil, within_superfamily: nil, within_family: nil, within_subfamily: nil, within_tribe: nil, within_subtribe: nil, within_genus: nil, within_subgenus: nil, within_section: nil, within_species: nil, verbose: false) ⇒ Array, Boolean
Get names or a name from a dataset.
-
.metrics(dataset_id, import_attempt: nil, verbose: false) ⇒ Array, ...
Get metrics for the *last successful* import of a dataset or a specific import_attempt.
-
.name(dataset_id, name_id: nil, subresource: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get names or a name from a dataset.
-
.name_list(dataset_id, import_attempt: nil, verbose: nil) ⇒ Object
Get a text list of names for a dataset.
-
.name_tree(dataset_id, import_attempt: nil, verbose: nil) ⇒ Object
Get a text tree of names for a dataset.
-
.nameusage(dataset_id, nameusage_id: nil, q: nil, rank: nil, nidx_id: nil, subresource: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get name usages or a nameusage from a dataset Note: Queries the PSQL database, whereas nameusage_search uses Elastic Search.
-
.nameusage_pattern(dataset_id, regexp, status: nil, rank: nil, project_id: nil, decision_mode: nil, offset: nil, limit: nil, verbose: false) ⇒ Object
Search for a name usage with a regex pattern.
-
.nameusage_search(q: nil, dataset_id: nil, endpoint: 'nameusage/search', content: nil, issue: nil, type: nil, rank: nil, min_rank: nil, max_rank: nil, facet: nil, sort_by: nil, reverse: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Search the nameusage route, which uses Elastic Search.
-
.nameusage_suggest(dataset_id, q, fuzzy: nil, min_rank: nil, max_rank: nil, sort_by: nil, reverse: nil, accepted: nil, limit: nil, verbose: false) ⇒ Hash, Boolean
Get a name usage suggestion.
-
.nidx(nidx_id, subresource: nil, verbose: false) ⇒ Object
Get names index info.
-
.nidx_match(q, authorship: nil, rank: nil, code: nil, verbose: false) ⇒ Hash, Boolean
Get names index matches.
-
.parser(subresource: nil, q: nil, verbose: false) ⇒ Array, ...
Parse a subresource.
-
.parser_idconverter(mode, id, format, verbose: false) ⇒ String, ...
Encode or decode identifiers to different formats (e.g., proquints are used as stable identifiers in ChecklistBank).
-
.parser_metadata(url, format: nil, verbose: false) ⇒ String, ...
Parse metadata.
-
.parser_name(name, authorship: nil, rank: nil, code: nil, verbose: false) ⇒ Hash, Boolean
Parse a scientific name.
-
.patch(dataset_id, patch_id: nil, token: nil, verbose: false) ⇒ Object
Get metadata patch.
-
.preview(project_id, verbose: false) ⇒ Array, Boolean
Get the latest preview release metadata (or points to the project draft dataset after the preview is released?) (Note: you can also use 3LRC where 3 is the project_id as an ID on any endpoint with dataset_id or project_id to get data from the latest release candidate, or 3LR gets the latest release).
-
.reference(dataset_id, reference_id: nil, subresource: nil, issue: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get a reference with @reference_id from dataset @dataset_id via the reference route.
-
.reviewer(dataset_id, token, verbose: false) ⇒ Object
Get reviewer info.
-
.sector(dataset_id, sector_id: nil, name: nil, rank: nil, modified_by: nil, broken: nil, subject_dataset_id: nil, last_synced_before: nil, mode: nil, subject: nil, min_size: nil, without_data: nil, offset: nil, limit: nil, verbose: false) ⇒ Hash, Boolean
Get sector metadata, which allows importing datasets into project subtrees.
-
.sector_sync(dataset_id, sector_id: nil, attempt: nil, subresource: nil, state: nil, running: nil, offset: nil, limit: nil, verbose: false) ⇒ Hash, Boolean
Get sector sync info.
-
.settings(dataset_id) ⇒ Hash, Boolean
Get the dataset settings.
-
.source(dataset_id, source_id: nil, not_current_only: nil, original: nil, verbose: false) ⇒ Array, ...
Get source metadata for datasets assembled into a project dataset.
-
.synonym(dataset_id, synonym_id: nil, subresource: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get a synonym with @synonym_id from dataset @dataset_id via the synonym route.
-
.taxon(dataset_id, taxon_id: nil, subresource: nil, format: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get a taxon with @id from dataset @dataset_id via the taxon route.
-
.taxon_ids(dataset_id, verbose: false) ⇒ Array, Boolean
Get the full list of taxon IDs for a dataset (returns 1 ID string per line, not JSON).
-
.tree(dataset_id, taxon_id: nil, children: false, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get the root taxa.
-
.user(user_id: nil, q: nil, role: nil, offset: nil, limit: nil, token: nil, verbose: false) ⇒ Array, Boolean
Get user data.
-
.user_dataset(token, dataset_id: nil, origin: nil, verbose: false) ⇒ Array, Boolean
Get datasets user can access.
-
.user_login(user, password, verbose: false) ⇒ Object
Authenticate user and get authentication token.
-
.user_me(token, verbose: false) ⇒ Array, Boolean
Get the authenticated user.
-
.verbatim(dataset_id, verbatim_id: nil, q: nil, issue: nil, type: nil, term: nil, term_operator: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get verbatim data.
-
.vernacular(dataset_id: nil, q: nil, language: nil, offset: nil, limit: nil, verbose: false) ⇒ Hash
Get vernacular names.
-
.version(verbose: false) ⇒ String
Get backend version.
-
.vocab(term: nil, subresource: nil, children: false, verbose: false) ⇒ Array
Get vocab.
Methods included from Configuration
Class Method Details
.archive(dataset_id, attempt: nil, verbose: false) ⇒ Binary
Get a dataset’s original archive
31 32 33 34 |
# File 'lib/colrapi.rb', line 31 def self.archive(dataset_id, attempt: nil, verbose: false) endpoint = "dataset/#{dataset_id}/archive" Request.new(endpoint: endpoint, attempt: attempt, verbose: verbose).perform end |
.assembly(dataset_id, verbose: false) ⇒ Hash
Get assembly status
20 21 22 23 |
# File 'lib/colrapi.rb', line 20 def self.assembly(dataset_id, verbose: false) endpoint = "dataset/#{dataset_id}/assembly" Request.new(endpoint: endpoint, verbose: verbose).perform end |
.dataset(dataset_id: nil, attempt: nil, q: nil, short_title: nil, code: nil, private: nil, released_from: nil, contributes_to: nil, has_source_dataset: nil, has_gbif_id: nil, gbif_id: nil, gbif_publisher_id: nil, editor: nil, reviewer: nil, modified_by: nil, origin: nil, type: nil, license: nil, row_type: nil, created_after: nil, created_before: nil, issued_after: nil, issued_before: nil, modified_after: nil, modified_before: nil, min_size: nil, sort_by: nil, reverse: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get dataset metadata
For a specific dataset:
@param dataset_id [String] The dataset id
@param attempt [Integer] Returns archived metadata for a past import attempt number
Search datasets:
@param q [String] A search query for datasets
@param short_title [String] A dataset alias
@param code [String] The nomenclatural code (bacterial, botanical, cultivars, phytosociological, virus, zoological)
@param private [Boolean] Whether the dataset is private or not
@param released_from [Integer] Filter by a project id that a dataset was released from
@param contributes_to [Integer] Filter by a project id that a dataset contributes to
@param has_source_dataset [Boolean] Filter by if source datasets contribute to the project dataset
@param has_gbif_id [Boolean] Whether the dataset has a GBIF registry id
@param gbif_id [String] The GBIF registry id
@param gbif_publisher_id [String] Filter by a GBIF publisher's id
@param editor [Integer] Filter by an editor's user id
@param reviewer [Integer] Filter by a reviewer's user id
@param modified_by [Integer] Filter by a user id on last modified by
@param origin [Array, String] Filter by the origin of a dataset (external, project, release, xrelease)
@param type [Array, String] Filter by the dataset type (nomenclatural, taxonomic, phylogenetic, article, legal, thematic, other)
@param license [Array, String] Filter by the license type (cc0, cc_by, cc_by_sa, cc_by_nc, cc_by_nd, cc_by_nc_sa, cc_by_nc_nd, unspecified, other)
@param row_type [Array, String] Filter by datasets that include a row type (e.g., acef:AcceptedSpecies, col:Taxon, dwc:Taxon)
@param created_after [Date] Filter by created after date
@param created_before [Date] Filter by created before date
@param issued_after [Date] Filter by issued after date
@param issued_before [Date] Filter by issued before date
@param modified_after [Date] Filter by modified after date
@param modified_before [Date] Filter by modified before date
@param min_size [Integer] Filter by minimum record size
@param sort_by [String] Sort by (key, alias, title, creator, relevance, created, modified, imported, size)
@param reverse [Boolean] Sort in reverse
@param offset [Integer] Offset for pagination
@param limit [Integer] Limit for pagination
@param verbose [Boolean] Print headers to STDOUT
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/colrapi.rb', line 75 def self.dataset(dataset_id: nil, attempt: nil, q: nil, short_title: nil, code: nil, private: nil, released_from: nil, contributes_to: nil, has_source_dataset: nil, has_gbif_id: nil, gbif_id: nil, gbif_publisher_id: nil, editor: nil, reviewer: nil, modified_by: nil, origin: nil, type: nil, license: nil, row_type: nil, created_after: nil, created_before: nil, issued_after: nil, issued_before: nil, modified_after: nil, modified_before: nil, min_size: nil, sort_by: nil, reverse: nil, offset: nil, limit: nil, verbose: false) endpoint = "dataset" unless dataset_id.nil? endpoint = "#{endpoint}/#{dataset_id}" unless attempt.nil? endpoint = "#{endpoint}/#{attempt}" end endpoint = "#{endpoint}.json" Request.new(endpoint: endpoint, verbose: verbose).perform else Request.new(endpoint: endpoint, q: q, short_title: short_title, code: code, private: private, released_from: released_from, contributes_to: contributes_to, has_source_dataset: has_source_dataset, has_gbif_id: has_gbif_id, gbif_id: gbif_id, gbif_publisher_id: gbif_publisher_id, editor: editor, reviewer: reviewer, modified_by: modified_by, origin: origin, type: type, license: license, row_type: row_type, created_after: created_after, created_before: created_before, issued_after: issued_after, issued_before: issued_before, modified_after: modified_after, modified_before: modified_before, min_size: min_size, sort_by: sort_by, reverse: reverse, offset: offset, limit: limit, verbose: verbose).perform end end |
.decision(dataset_id, decision_id: nil, name: nil, rank: nil, modified_by: nil, broken: nil, subject_dataset_id: nil, mode: nil, subject: nil, offset: nil, limit: nil, verbose: false) ⇒ Hash, Boolean
Get project decisions
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/colrapi.rb', line 118 def self.decision(dataset_id, decision_id: nil, name: nil, rank: nil, modified_by: nil, broken: nil, subject_dataset_id: nil, mode: nil, subject: nil, offset: nil, limit: nil, verbose: false) if decision_id.nil? endpoint = "dataset/#{dataset_id}/decision" Request.new(endpoint: endpoint, name: name, rank: rank, modified_by: modified_by, broken: broken, subject_dataset_id: subject_dataset_id, mode: mode, subject: subject, offset: offset, limit: limit, verbose: verbose).perform else endpoint = "dataset/#{dataset_id}/decision/#{decision_id}" Request.new(endpoint: endpoint, verbose: verbose).perform end end |
.diff(dataset_id, dataset2_id, root_id: nil, root2_id: nil, min_rank: nil, authorship: nil, include_synonyms: nil, include_parent: nil, parent_rank: nil, offset: nil, limit: nil, token: nil, verbose: false) ⇒ String, Boolean
Get names diff between 2 datasets
161 162 163 164 165 166 167 168 169 |
# File 'lib/colrapi.rb', line 161 def self.diff(dataset_id, dataset2_id, root_id: nil, root2_id: nil, min_rank: nil, authorship: nil, include_synonyms: nil, include_parent: nil, parent_rank: nil, offset: nil, limit: nil, token: nil, verbose: false) endpoint = "dataset/#{dataset_id}/diff/#{dataset2_id}" Request.new(endpoint: endpoint, root_id: root_id, root2_id: root2_id, min_rank: min_rank, authorship: , include_synonyms: include_synonyms, include_parent: include_parent, parent_rank: parent_rank, offset: offset, limit: limit, token: token, verbose: verbose).perform end |
.duplicate(dataset_id, offset: nil, limit: nil, verbose: false) ⇒ Object
Get duplicate names
138 139 140 141 |
# File 'lib/colrapi.rb', line 138 def self.duplicate(dataset_id, offset: nil, limit: nil, verbose: false) endpoint = "dataset/#{dataset_id}/duplicate" Request.new(endpoint: endpoint, offset: offset, limit: limit, verbose: verbose).perform end |
.editor(dataset_id, token, verbose: false) ⇒ Object
Get editor info
# @return [Array, Hash, Boolean] An array of hashes
177 178 179 180 |
# File 'lib/colrapi.rb', line 177 def self.editor(dataset_id, token, verbose: false) endpoint = "dataset/#{dataset_id}/editor" Request.new(endpoint: endpoint, token: token, verbose: verbose).perform end |
.estimate(dataset_id, estimate_id: nil, name: nil, rank: nil, modified_by: nil, broken: nil, min: nil, max: nil, offset: nil, limit: nil, verbose: false) ⇒ Hash, Boolean
Get estimates
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/colrapi.rb', line 197 def self.estimate(dataset_id, estimate_id: nil, name: nil, rank: nil, modified_by: nil, broken: nil, min: nil, max: nil, offset: nil, limit: nil, verbose: false) endpoint = "dataset/#{dataset_id}/estimate" if estimate_id.nil? Request.new(endpoint: endpoint, name: name, rank: rank, modified_by: modified_by, broken: broken, min: min, max: max, offset: offset, limit: limit, verbose: verbose).perform else endpoint = "dataset/#{dataset_id}/estimate/#{estimate_id}" Request.new(endpoint: endpoint, verbose: verbose).perform end end |
.export(dataset_id, show_id: nil, verbose: false) ⇒ Hash, Boolean
TODO: /dataset/key/export is covered, but /export and /export/id are not Get a dataset export
217 218 219 220 |
# File 'lib/colrapi.rb', line 217 def self.export(dataset_id, show_id: nil, verbose: false) endpoint = "dataset/#{dataset_id}/export" Request.new(endpoint: endpoint, verbose: verbose).perform end |
.importer(dataset_id: nil, dataset_id_filter: nil, state: nil, running: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get importer status
273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/colrapi.rb', line 273 def self.importer(dataset_id: nil, dataset_id_filter: nil, state: nil, running: nil, offset: nil, limit: nil, verbose: false) endpoint = "importer" if dataset_id.nil? Request.new(endpoint: endpoint, dataset_id_filter: dataset_id_filter, state: state, running: running, offset: offset, limit: limit, verbose: verbose).perform else endpoint = "#{endpoint}/#{dataset_id}" Request.new(endpoint: endpoint, verbose: verbose).perform end end |
.issues(dataset_id, issue: nil, mode: 'verbatim', offset: nil, limit: nil, verbose: false) ⇒ Array, ...
Get data quality issues
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/colrapi.rb', line 233 def self.issues(dataset_id, issue: nil, mode: 'verbatim', offset: nil, limit: nil, verbose: false) if issue.nil? metrics = Request.new(endpoint: "/dataset/#{dataset_id}/import?state=finished").perform return {"issuesCount" => metrics[0]['issuesCount']} else if mode == 'interpreted' issues = self.vocab(term: 'issue') record_type = 'any' issues.each do |i| if i['name'] == issue.downcase record_type = i['group'] end end # TODO: so far issues are only filterable on nameusage/search and /reference # for other record_types, may need to add other endpoints in the future if record_type == 'reference' self.reference(dataset_id, issue: issue, offset: offset, limit: limit, verbose: verbose) else self.nameusage_search(dataset_id: dataset_id, issue: issue, facet: 'issue', offset: offset, limit: limit, verbose: verbose) end else self.verbatim(dataset_id, issue: issue, offset: offset, limit: limit, verbose: verbose) end end end |
.logo(dataset_id, size: nil, verbose: false) ⇒ Binary
Get a dataset’s logo
291 292 293 294 |
# File 'lib/colrapi.rb', line 291 def self.logo(dataset_id, size: nil, verbose: false) endpoint = "dataset/#{dataset_id}/logo" Request.new(endpoint: endpoint, size: size, verbose: verbose).perform end |
.matching(dataset_id, name: nil, authorship: nil, code: nil, rank: nil, within_superkingdom: nil, within_kingdom: nil, within_subkingdom: nil, within_superphylum: nil, within_phylum: nil, within_subphylum: nil, within_superclass: nil, within_class: nil, within_subclass: nil, within_superorder: nil, within_order: nil, within_suborder: nil, within_superfamily: nil, within_family: nil, within_subfamily: nil, within_tribe: nil, within_subtribe: nil, within_genus: nil, within_subgenus: nil, within_section: nil, within_species: nil, verbose: false) ⇒ Array, Boolean
Get names or a name from a dataset
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
# File 'lib/colrapi.rb', line 504 def self.matching(dataset_id, name: nil, authorship: nil, code: nil, rank: nil, within_superkingdom: nil, within_kingdom: nil, within_subkingdom: nil, within_superphylum: nil, within_phylum: nil, within_subphylum: nil, within_superclass: nil, within_class: nil, within_subclass: nil, within_superorder: nil, within_order: nil, within_suborder: nil, within_superfamily: nil, within_family: nil, within_subfamily: nil, within_tribe: nil, within_subtribe: nil, within_genus: nil, within_subgenus: nil, within_section: nil, within_species: nil, verbose: false) endpoint = "dataset/#{dataset_id}/nameusage/match" Request.new(endpoint: endpoint, name: name, authorship: , code: code, rank: rank, within_superkingdom: within_superkingdom, within_kingdom: within_kingdom, within_subkingdom: within_subkingdom, within_superphylum: within_superphylum, within_phylum: within_phylum, within_subphylum: within_subphylum, within_superclass: within_superclass, within_class: within_class, within_subclass: within_subclass, within_superorder: within_superorder, within_order: within_order, within_suborder: within_suborder, within_superfamily: within_superfamily, within_family: within_family, within_subfamily: within_subfamily, within_tribe: within_tribe, within_subtribe: within_subtribe, within_genus: within_genus, within_subgenus: within_subgenus, within_section: within_section, within_species: within_species, verbose: verbose).perform end |
.metrics(dataset_id, import_attempt: nil, verbose: false) ⇒ Array, ...
Get metrics for the *last successful* import of a dataset or a specific import_attempt
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/colrapi.rb', line 353 def self.metrics(dataset_id, import_attempt: nil, verbose: false) import = self.importer(dataset_id: dataset_id) unless %w[unchanged finished].include? import['state'] return {"code" => 400, 'message' => 'Dataset has not finished importing or failed to import'} end # it's necessary to get the last finished import attempt because status=unchanged import results don't have metrics # project release datasets do not seem to have import_attempts or should be taken from the project dataset, e.g.: # https://api.checklistbank.org/dataset/3/import/107 == https://api.checklistbank.org/dataset/9837/import if import_attempt.nil? import = self.importer(dataset_id_filter: dataset_id, state: 'finished') if import['total'] > 0 import_attempt = import['result'][0]['attempt'] end end endpoint = "dataset/#{dataset_id}/import" if !import_attempt.nil? endpoint = "#{endpoint}/#{import_attempt}" Request.new(endpoint: endpoint, verbose: verbose).perform else # /dataset/{id}/import returns an array of 1 item while /dataset/{id}/import/{attempt} doesn't res = Request.new(endpoint: endpoint, verbose: verbose).perform res[0] end end |
.name(dataset_id, name_id: nil, subresource: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get names or a name from a dataset
392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/colrapi.rb', line 392 def self.name(dataset_id, name_id: nil, subresource: nil, offset: nil, limit: nil, verbose: false) endpoint = "dataset/#{dataset_id}/name" unless name_id.nil? endpoint = "#{endpoint}/#{name_id}" offset = nil limit = nil end if !subresource.nil? and %w[relations synonyms types orphans].include? subresource endpoint = "#{endpoint}/#{subresource}" end Request.new(endpoint: endpoint, offset: offset, limit: limit, verbose: verbose).perform end |
.name_list(dataset_id, import_attempt: nil, verbose: nil) ⇒ Object
Get a text list of names for a dataset
410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/colrapi.rb', line 410 def self.name_list(dataset_id, import_attempt: nil, verbose: nil) # get last import attempt number if none given if import_attempt.nil? import = self.importer(dataset_id: dataset_id) import_attempt = import['attempt'] end endpoint = "dataset/#{dataset_id}/import/#{import_attempt}/names" Request.new(endpoint: endpoint, verbose: verbose).perform end |
.name_tree(dataset_id, import_attempt: nil, verbose: nil) ⇒ Object
Get a text tree of names for a dataset
427 428 429 430 431 432 433 434 435 436 437 |
# File 'lib/colrapi.rb', line 427 def self.name_tree(dataset_id, import_attempt: nil, verbose: nil) # get last import attempt number if none given if import_attempt.nil? import = self.importer(dataset_id: dataset_id) import_attempt = import['attempt'] end endpoint = "dataset/#{dataset_id}/import/#{import_attempt}/tree" Request.new(endpoint: endpoint, verbose: verbose).perform end |
.nameusage(dataset_id, nameusage_id: nil, q: nil, rank: nil, nidx_id: nil, subresource: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get name usages or a nameusage from a dataset
Note: Queries the PSQL database, whereas nameusage_search uses Elastic Search
454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
# File 'lib/colrapi.rb', line 454 def self.nameusage(dataset_id, nameusage_id: nil, q: nil, rank: nil, nidx_id: nil, subresource: nil, offset: nil, limit: nil, verbose: false) endpoint = "dataset/#{dataset_id}/nameusage" unless nameusage_id.nil? endpoint = "#{endpoint}/#{nameusage_id}" offset = nil limit = nil end unless subresource.nil? endpoint = "#{endpoint}/#{subresource}" end Request.new(endpoint: endpoint, q: q, rank: rank, nidx_id: nidx_id, offset: offset, limit: limit, verbose: verbose).perform end |
.nameusage_pattern(dataset_id, regexp, status: nil, rank: nil, project_id: nil, decision_mode: nil, offset: nil, limit: nil, verbose: false) ⇒ Object
Search for a name usage with a regex pattern
535 536 537 538 539 540 |
# File 'lib/colrapi.rb', line 535 def self.nameusage_pattern(dataset_id, regexp, status: nil, rank: nil, project_id: nil, decision_mode: nil, offset: nil, limit: nil, verbose: false) endpoint = "dataset/#{dataset_id}/nameusage/pattern" Request.new(endpoint: endpoint, regexp: regexp, project_id: project_id, status: status, rank: rank, decision_mode: decision_mode, offset: offset, limit: limit, verbose: verbose).perform end |
.nameusage_search(q: nil, dataset_id: nil, endpoint: 'nameusage/search', content: nil, issue: nil, type: nil, rank: nil, min_rank: nil, max_rank: nil, facet: nil, sort_by: nil, reverse: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Search the nameusage route, which uses Elastic Search
562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
# File 'lib/colrapi.rb', line 562 def self.nameusage_search(q: nil, dataset_id: nil, endpoint: 'nameusage/search', content: nil, issue: nil, type: nil, rank: nil, min_rank: nil, max_rank: nil, facet: nil, sort_by: nil, reverse: nil, offset: nil, limit: nil, verbose: false) # a nil dataset_id will search name usages from all datasets in ChecklistBank unless dataset_id.nil? endpoint = "dataset/#{dataset_id}/nameusage/search" end Request.new(endpoint: endpoint, q: q, content: content, issue: issue, type: type, rank: rank, min_rank: min_rank, max_rank: max_rank, facet: facet, sort_by: sort_by, reverse: reverse, offset: offset, limit: limit, verbose: verbose).perform end |
.nameusage_suggest(dataset_id, q, fuzzy: nil, min_rank: nil, max_rank: nil, sort_by: nil, reverse: nil, accepted: nil, limit: nil, verbose: false) ⇒ Hash, Boolean
Get a name usage suggestion
592 593 594 595 596 597 |
# File 'lib/colrapi.rb', line 592 def self.nameusage_suggest(dataset_id, q, fuzzy: nil, min_rank: nil, max_rank: nil, sort_by: nil, reverse: nil, accepted: nil, limit: nil, verbose: false) endpoint = "dataset/#{dataset_id}/nameusage/suggest" Request.new(endpoint: endpoint, q: q, fuzzy: fuzzy, min_rank: min_rank, max_rank: max_rank, sort_by: sort_by, reverse: reverse, accepted: accepted, limit: limit, verbose: verbose).perform end |
.nidx(nidx_id, subresource: nil, verbose: false) ⇒ Object
Get names index info
603 604 605 606 607 |
# File 'lib/colrapi.rb', line 603 def self.nidx(nidx_id, subresource: nil, verbose: false) endpoint = "nidx/#{nidx_id}" endpoint = "nidx/#{nidx_id}/#{subresource}" unless subresource.nil? Request.new(endpoint: endpoint, verbose: verbose).perform end |
.nidx_match(q, authorship: nil, rank: nil, code: nil, verbose: false) ⇒ Hash, Boolean
Get names index matches
618 619 620 621 |
# File 'lib/colrapi.rb', line 618 def self.nidx_match(q, authorship: nil, rank: nil, code: nil, verbose: false) endpoint = "nidx/match" Request.new(endpoint: endpoint, q: q, authorship: , rank: rank, code: code, verbose: verbose).perform end |
.parser(subresource: nil, q: nil, verbose: false) ⇒ Array, ...
Parse a subresource
This is the generic parser wrapper. For specialized parsers, like the names, homoglyphs, idconverter, metadata,
use the specialized parsers below like Colrapi.parser_name(). Returns a list of parsers if no subresource given.
632 633 634 635 636 |
# File 'lib/colrapi.rb', line 632 def self.parser(subresource: nil, q: nil, verbose: false) endpoint = "parser" endpoint = "#{endpoint}/#{subresource}" unless subresource.nil? Request.new(endpoint: endpoint, q: q, verbose: verbose).perform end |
.parser_idconverter(mode, id, format, verbose: false) ⇒ String, ...
Encode or decode identifiers to different formats (e.g., proquints are used as stable identifiers in ChecklistBank)
646 647 648 649 |
# File 'lib/colrapi.rb', line 646 def self.parser_idconverter(mode, id, format, verbose: false) endpoint = "parser/idconverter/#{mode}" Request.new(endpoint: endpoint, id: id, format: format, verbose: verbose).perform end |
.parser_metadata(url, format: nil, verbose: false) ⇒ String, ...
Parse metadata
658 659 660 661 |
# File 'lib/colrapi.rb', line 658 def self.(url, format: nil, verbose: false) endpoint = 'parser/metadata' Request.new(endpoint: endpoint, url: url, format: format, verbose: verbose).perform end |
.parser_name(name, authorship: nil, rank: nil, code: nil, verbose: false) ⇒ Hash, Boolean
Parse a scientific name
671 672 673 674 675 |
# File 'lib/colrapi.rb', line 671 def self.parser_name(name, authorship: nil, rank: nil, code: nil, verbose: false) endpoint = 'parser/name' Request.new(endpoint: endpoint, name: name, authorship: , rank: rank, code: code, verbose: verbose).perform end |
.patch(dataset_id, patch_id: nil, token: nil, verbose: false) ⇒ Object
Get metadata patch
681 682 683 684 685 686 687 |
# File 'lib/colrapi.rb', line 681 def self.patch(dataset_id, patch_id: nil, token: nil, verbose: false) endpoint = "dataset/#{dataset_id}/patch" unless patch_id.nil? endpoint = "#{endpoint}/#{patch_id}" end Request.new(endpoint: endpoint, token: token, verbose: verbose).perform end |
.preview(project_id, verbose: false) ⇒ Array, Boolean
Get the latest preview release metadata (or points to the project draft dataset after the preview is released?)
(Note: you can also use 3LRC where 3 is the project_id as an ID on any endpoint with dataset_id or project_id
to get data from the latest release candidate, or 3LR gets the latest release)
696 697 698 |
# File 'lib/colrapi.rb', line 696 def self.preview(project_id, verbose: false) Request.new(endpoint: "dataset/#{project_id}/preview", verbose: verbose).perform end |
.reference(dataset_id, reference_id: nil, subresource: nil, issue: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get a reference with @reference_id from dataset @dataset_id via the reference route
712 713 714 715 716 717 718 719 720 721 722 723 |
# File 'lib/colrapi.rb', line 712 def self.reference(dataset_id, reference_id: nil, subresource: nil, issue: nil, offset: nil, limit: nil, verbose: false) endpoint = "dataset/#{dataset_id}/reference" if subresource == 'orphans' reference_id = nil endpoint = "#{endpoint}/orphans" end unless reference_id.nil? endpoint = "#{endpoint}/#{reference_id}" end Request.new(endpoint: endpoint, issue: issue, offset: offset, limit: limit, verbose: verbose).perform end |
.reviewer(dataset_id, token, verbose: false) ⇒ Object
Get reviewer info
# @return [Array, Hash, Boolean] An array of hashes
731 732 733 734 |
# File 'lib/colrapi.rb', line 731 def self.reviewer(dataset_id, token, verbose: false) endpoint = "dataset/#{dataset_id}/reviewer" Request.new(endpoint: endpoint, token: token, verbose: verbose).perform end |
.sector(dataset_id, sector_id: nil, name: nil, rank: nil, modified_by: nil, broken: nil, subject_dataset_id: nil, last_synced_before: nil, mode: nil, subject: nil, min_size: nil, without_data: nil, offset: nil, limit: nil, verbose: false) ⇒ Hash, Boolean
Get sector metadata, which allows importing datasets into project subtrees
756 757 758 759 760 761 762 763 764 765 766 767 768 769 |
# File 'lib/colrapi.rb', line 756 def self.sector(dataset_id, sector_id: nil, name: nil, rank: nil, modified_by: nil, broken: nil, subject_dataset_id: nil, last_synced_before: nil, mode: nil, subject: nil, min_size: nil, without_data: nil, offset: nil, limit: nil, verbose: false) endpoint = "dataset/#{dataset_id}/sector" if sector_id.nil? Request.new(endpoint: endpoint, name: name, rank: rank, modified_by: modified_by, broken: broken, subject_dataset_id: subject_dataset_id, last_synced_before: last_synced_before, mode: mode, subject: subject, min_size: min_size, without_data: without_data, offset: offset, limit: limit, verbose: verbose).perform else endpoint = "#{endpoint}/#{sector_id}" Request.new(endpoint: endpoint, verbose: verbose).perform end end |
.sector_sync(dataset_id, sector_id: nil, attempt: nil, subresource: nil, state: nil, running: nil, offset: nil, limit: nil, verbose: false) ⇒ Hash, Boolean
Get sector sync info
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 |
# File 'lib/colrapi.rb', line 785 def self.sector_sync(dataset_id, sector_id: nil, attempt: nil, subresource: nil, state: nil, running: nil, offset: nil, limit: nil, verbose: false) endpoint = "dataset/#{dataset_id}/sector/sync" if sector_id.nil? Request.new(endpoint: endpoint, state: state, running: running, offset: offset, limit: limit, verbose:verbose).perform else if attempt.nil? endpoint = "dataset/#{dataset_id}/sector/#{sector_id}/sync" else endpoint = "dataset/#{dataset_id}/sector/#{sector_id}/sync/#{attempt}" endpoint = "#{endpoint}/#{subresource}" unless subresource.nil? end Request.new(endpoint: endpoint, verbose:verbose).perform end end |
.settings(dataset_id) ⇒ Hash, Boolean
Get the dataset settings
824 825 826 |
# File 'lib/colrapi.rb', line 824 def self.settings(dataset_id) Request.new(endpoint: "dataset/#{dataset_id}/settings").perform end |
.source(dataset_id, source_id: nil, not_current_only: nil, original: nil, verbose: false) ⇒ Array, ...
Get source metadata for datasets assembled into a project dataset
809 810 811 812 813 814 815 816 817 |
# File 'lib/colrapi.rb', line 809 def self.source(dataset_id, source_id: nil, not_current_only: nil, original: nil, verbose: false) endpoint = "dataset/#{dataset_id}/source" if source_id.nil? Request.new(endpoint: endpoint, not_current_only: not_current_only, verbose: verbose).perform else endpoint = "dataset/#{dataset_id}/source/#{source_id}" Request.new(endpoint: endpoint, original: original, verbose: verbose).perform end end |
.synonym(dataset_id, synonym_id: nil, subresource: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get a synonym with @synonym_id from dataset @dataset_id via the synonym route
839 840 841 842 843 844 845 846 847 848 |
# File 'lib/colrapi.rb', line 839 def self.synonym(dataset_id, synonym_id: nil, subresource: nil, offset: nil, limit: nil, verbose: false) endpoint = "dataset/#{dataset_id}/synonym" unless synonym_id.nil? endpoint = "#{endpoint}/#{synonym_id}" end if subresource == 'source' endpoint = "#{endpoint}/source" end Request.new(endpoint: endpoint, offset: offset, limit: limit, verbose: verbose).perform end |
.taxon(dataset_id, taxon_id: nil, subresource: nil, format: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get a taxon with @id from dataset @dataset_id via the taxon route
872 873 874 875 876 877 878 879 880 881 882 |
# File 'lib/colrapi.rb', line 872 def self.taxon(dataset_id, taxon_id: nil, subresource: nil, format: nil, offset: nil, limit: nil, verbose: false) endpoint = "dataset/#{dataset_id}/taxon" unless taxon_id.nil? endpoint = "#{endpoint}/#{taxon_id}" end if !subresource.nil? endpoint = "#{endpoint}/#{subresource}" end Request.new(endpoint: endpoint, offset: offset, format: format, limit: limit, verbose: verbose).perform end |
.taxon_ids(dataset_id, verbose: false) ⇒ Array, Boolean
Get the full list of taxon IDs for a dataset (returns 1 ID string per line, not JSON)
855 856 857 |
# File 'lib/colrapi.rb', line 855 def self.taxon_ids(dataset_id, verbose: false) Request.new(endpoint: "dataset/#{dataset_id}/taxon/ids", verbose: verbose).perform end |
.tree(dataset_id, taxon_id: nil, children: false, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get the root taxa
895 896 897 898 899 900 |
# File 'lib/colrapi.rb', line 895 def self.tree(dataset_id, taxon_id: nil, children: false, offset: nil, limit: nil, verbose: false) endpoint = "dataset/#{dataset_id}/tree" endpoint = "#{endpoint}/#{taxon_id}" unless taxon_id.nil? endpoint = "#{endpoint}/children" unless taxon_id.nil? or !children Request.new(endpoint: endpoint, offset: offset, limit: limit, verbose: verbose).perform end |
.user(user_id: nil, q: nil, role: nil, offset: nil, limit: nil, token: nil, verbose: false) ⇒ Array, Boolean
Get user data
914 915 916 917 918 919 920 921 922 923 |
# File 'lib/colrapi.rb', line 914 def self.user(user_id: nil, q: nil, role: nil, offset: nil, limit: nil, token: nil, verbose: false) if user_id.nil? endpoint = "user" Request.new(endpoint: endpoint, q: q, role: role, offset: offset, limit: limit, token: token, verbose: verbose).perform else endpoint = "user/#{user_id}" Request.new(endpoint: endpoint, token: token, verbose: verbose).perform end end |
.user_dataset(token, dataset_id: nil, origin: nil, verbose: false) ⇒ Array, Boolean
Get datasets user can access
931 932 933 934 935 936 937 938 939 |
# File 'lib/colrapi.rb', line 931 def self.user_dataset(token, dataset_id: nil, origin: nil, verbose: false) endpoint = "user/dataset" if dataset_id.nil? Request.new(endpoint: endpoint, token: token, origin: origin, verbose: verbose).perform else endpoint = "user/dataset/#{dataset_id}" Request.new(endpoint: endpoint, token: token, verbose: verbose).perform end end |
.user_login(user, password, verbose: false) ⇒ Object
Authenticate user and get authentication token
942 943 944 |
# File 'lib/colrapi.rb', line 942 def self.user_login(user, password, verbose: false) Request.new(endpoint: "user/login", user: user, password: password, verbose: verbose).perform end |
.user_me(token, verbose: false) ⇒ Array, Boolean
Get the authenticated user
952 953 954 |
# File 'lib/colrapi.rb', line 952 def self.user_me(token, verbose: false) Request.new(endpoint: "user/me", token: token, verbose: verbose).perform end |
.verbatim(dataset_id, verbatim_id: nil, q: nil, issue: nil, type: nil, term: nil, term_operator: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Get verbatim data
TODO: May not work yet: github.com/CatalogueOfLife/backend/issues/1201
@param term [Array, String] Filter by term (http://api.checklistbank.org/vocab/term)
@param term_operator [String] The operator to use with term ('and' or 'or')
973 974 975 976 977 978 979 980 981 982 983 |
# File 'lib/colrapi.rb', line 973 def self.verbatim(dataset_id, verbatim_id: nil, q: nil, issue: nil, type: nil, term: nil, term_operator: nil, offset: nil, limit: nil, verbose: false) endpoint = "dataset/#{dataset_id}/verbatim" if verbatim_id.nil? Request.new(endpoint: endpoint, q: q, issue: issue, type: type, term: term, term_operator: term_operator, offset: offset, limit: limit, verbose: verbose).perform else endpoint = "#{endpoint}/#{verbatim_id}" Request.new(endpoint: endpoint, verbose: verbose).perform end end |
.vernacular(dataset_id: nil, q: nil, language: nil, offset: nil, limit: nil, verbose: false) ⇒ Hash
Get vernacular names
996 997 998 999 1000 1001 1002 1003 1004 |
# File 'lib/colrapi.rb', line 996 def self.vernacular(dataset_id: nil, q: nil, language: nil, offset: nil, limit: nil, verbose: false) if dataset_id.nil? endpoint = 'vernacular' Request.new(endpoint: endpoint, q: q, language: language, offset: offset, limit: limit, verbose: verbose).perform else endpoint = "dataset/#{dataset_id}/vernacular" Request.new(endpoint: endpoint, q: q, language: language, offset: offset, limit: limit, verbose: verbose).perform end end |
.version(verbose: false) ⇒ String
Get backend version
1009 1010 1011 |
# File 'lib/colrapi.rb', line 1009 def self.version(verbose: false) Request.new(endpoint: 'version', verbose: verbose).perform end |
.vocab(term: nil, subresource: nil, children: false, verbose: false) ⇒ Array
Get vocab
1021 1022 1023 1024 1025 1026 1027 |
# File 'lib/colrapi.rb', line 1021 def self.vocab(term: nil, subresource: nil, children: false, verbose: false) endpoint = "vocab" endpoint = "#{endpoint}/#{term}" unless term.nil? endpoint = "#{endpoint}/#{subresource}" unless term.nil? or subresource.nil? endpoint = "#{endpoint}/children" if children and term == "geotime" Request.new(endpoint: endpoint, verbose: verbose).perform end |