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.6"
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, token: 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 PostgreSQL database, whereas nameusage_search uses Elasticsearch.
-
.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, authorship: nil, authorship_year: nil, dataset_id: nil, endpoint: 'nameusage/search', extinct: nil, field: nil, content: nil, issue: nil, type: nil, rank: nil, min_rank: nil, max_rank: nil, environment: nil, facet: nil, nomenclatural_code: nil, highest_taxon_id: nil, usage_id: nil, nomenclatural_status: nil, name_type: nil, origin: nil, secondary_source: nil, sector_mode: nil, sector_dataset_id: nil, status: nil, taxonomic_group: 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, token, 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, token: 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 title [String] A dataset title
@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 token [String, nil] An authentication token from Colrapi.user_login()
@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
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/colrapi.rb', line 77 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, token: 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, token: token, 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
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/colrapi.rb', line 120 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
163 164 165 166 167 168 169 170 171 |
# File 'lib/colrapi.rb', line 163 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
140 141 142 143 |
# File 'lib/colrapi.rb', line 140 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
179 180 181 182 |
# File 'lib/colrapi.rb', line 179 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
199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/colrapi.rb', line 199 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
219 220 221 222 |
# File 'lib/colrapi.rb', line 219 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
275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/colrapi.rb', line 275 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
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 260 261 |
# File 'lib/colrapi.rb', line 235 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
293 294 295 296 |
# File 'lib/colrapi.rb', line 293 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
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
# File 'lib/colrapi.rb', line 506 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
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 380 381 |
# File 'lib/colrapi.rb', line 355 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
394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/colrapi.rb', line 394 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
412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/colrapi.rb', line 412 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
429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/colrapi.rb', line 429 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 PostgreSQL database, whereas nameusage_search uses Elasticsearch
456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/colrapi.rb', line 456 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
537 538 539 540 541 542 |
# File 'lib/colrapi.rb', line 537 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, authorship: nil, authorship_year: nil, dataset_id: nil, endpoint: 'nameusage/search', extinct: nil, field: nil, content: nil, issue: nil, type: nil, rank: nil, min_rank: nil, max_rank: nil, environment: nil, facet: nil, nomenclatural_code: nil, highest_taxon_id: nil, usage_id: nil, nomenclatural_status: nil, name_type: nil, origin: nil, secondary_source: nil, sector_mode: nil, sector_dataset_id: nil, status: nil, taxonomic_group: nil, sort_by: nil, reverse: nil, offset: nil, limit: nil, verbose: false) ⇒ Array, Boolean
Search the nameusage route, which uses Elastic Search
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
# File 'lib/colrapi.rb', line 580 def self.nameusage_search(q: nil, authorship: nil, authorship_year: nil, dataset_id: nil, endpoint: 'nameusage/search', extinct: nil, field: nil, content: nil, issue: nil, type: nil, rank: nil, min_rank: nil, max_rank: nil, environment: nil, facet: nil, nomenclatural_code: nil, highest_taxon_id: nil, usage_id: nil, nomenclatural_status: nil, name_type: nil, origin: nil, secondary_source: nil, sector_mode: nil, sector_dataset_id: nil, status: nil, taxonomic_group: 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, authorship: , authorship_year: , extinct: extinct, field: field, content: content, issue: issue, type: type, rank: rank, min_rank: min_rank, max_rank: max_rank, facet: facet, nomenclatural_code: nomenclatural_code,environment: environment, highest_taxon_id: highest_taxon_id, usage_id: usage_id, name_type: name_type, nomenclatural_status: nomenclatural_status, origin: origin, secondary_source: secondary_source, sector_mode: sector_mode, sector_dataset_id: sector_dataset_id, status: status, taxonomic_group: taxonomic_group, 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
620 621 622 623 624 625 |
# File 'lib/colrapi.rb', line 620 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
631 632 633 634 635 |
# File 'lib/colrapi.rb', line 631 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
646 647 648 649 |
# File 'lib/colrapi.rb', line 646 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.
660 661 662 663 664 |
# File 'lib/colrapi.rb', line 660 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)
674 675 676 677 |
# File 'lib/colrapi.rb', line 674 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
686 687 688 689 |
# File 'lib/colrapi.rb', line 686 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
699 700 701 702 703 |
# File 'lib/colrapi.rb', line 699 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
709 710 711 712 713 714 715 |
# File 'lib/colrapi.rb', line 709 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, token, 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)
725 726 727 |
# File 'lib/colrapi.rb', line 725 def self.preview(project_id, token, verbose: false) Request.new(endpoint: "dataset/#{project_id}LRC.json", token: token, 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
741 742 743 744 745 746 747 748 749 750 751 752 |
# File 'lib/colrapi.rb', line 741 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
760 761 762 763 |
# File 'lib/colrapi.rb', line 760 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
785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
# File 'lib/colrapi.rb', line 785 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
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 |
# File 'lib/colrapi.rb', line 814 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
853 854 855 |
# File 'lib/colrapi.rb', line 853 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
838 839 840 841 842 843 844 845 846 |
# File 'lib/colrapi.rb', line 838 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
868 869 870 871 872 873 874 875 876 877 |
# File 'lib/colrapi.rb', line 868 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
901 902 903 904 905 906 907 908 909 910 911 |
# File 'lib/colrapi.rb', line 901 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)
884 885 886 |
# File 'lib/colrapi.rb', line 884 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
924 925 926 927 928 929 |
# File 'lib/colrapi.rb', line 924 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
943 944 945 946 947 948 949 950 951 952 |
# File 'lib/colrapi.rb', line 943 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
960 961 962 963 964 965 966 967 968 |
# File 'lib/colrapi.rb', line 960 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
971 972 973 |
# File 'lib/colrapi.rb', line 971 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
981 982 983 |
# File 'lib/colrapi.rb', line 981 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')
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 |
# File 'lib/colrapi.rb', line 1002 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
1025 1026 1027 1028 1029 1030 1031 1032 1033 |
# File 'lib/colrapi.rb', line 1025 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
1038 1039 1040 |
# File 'lib/colrapi.rb', line 1038 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
1050 1051 1052 1053 1054 1055 1056 |
# File 'lib/colrapi.rb', line 1050 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 |