Module: Checkerberry

Extended by:
Configuration
Defined in:
lib/checkerberry.rb,
lib/checkerberry/error.rb,
lib/checkerberry/utils.rb,
lib/checkerberry/request.rb,
lib/checkerberry/version.rb

Defined Under Namespace

Modules: Utils Classes: BadGateway, Error, InternalServerError, NotFound, Request, RequestError, ServiceUnavailable, Unauthorized

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Methods included from Configuration

configuration, define_setting

Class Method Details

.data_source(source_id, verbose: false) ⇒ Hash

Get a single data source by ID

Parameters:

  • source_id (Integer)

    The data source ID

  • verbose (Boolean) (defaults to: false)

    Print headers to STDOUT

Returns:

  • (Hash)

    A hash with data source information



105
106
107
108
# File 'lib/checkerberry.rb', line 105

def self.data_source(source_id, verbose: false)
  endpoint = "data_sources/#{source_id}"
  Request.new(endpoint: endpoint, verbose: verbose).perform
end

.data_sources(verbose: false) ⇒ Array

Get list of data sources

Parameters:

  • verbose (Boolean) (defaults to: false)

    Print headers to STDOUT

Returns:

  • (Array)

    An array of data source information



94
95
96
97
# File 'lib/checkerberry.rb', line 94

def self.data_sources(verbose: false)
  endpoint = "data_sources"
  Request.new(endpoint: endpoint, verbose: verbose).perform
end

.ping(verbose: false) ⇒ Object

Ping the API (check if the service is alive)

Parameters:

  • verbose (Boolean) (defaults to: false)

    Print headers to STDOUT



113
114
115
116
# File 'lib/checkerberry.rb', line 113

def self.ping(verbose: false)
  endpoint = "ping"
  Request.new(endpoint: endpoint, verbose: verbose).perform
end

.search(query: nil, data_sources: nil, parent_taxon: nil, name_string: nil, genus: nil, species: nil, species_any: nil, infraspecies: nil, author: nil, year: nil, year_start: nil, year_end: nil, with_all_results: nil, verbose: false) ⇒ Object

Search for scientific names

Parameters:

  • query (String) (defaults to: nil)

    The search query

  • data_sources (Array, Integer) (defaults to: nil)

    The data source IDs to use for verification

  • parent_taxon (String) (defaults to: nil)

    The parent taxon name

  • name_string (String) (defaults to: nil)

    The exact name string to search for

  • genus (String) (defaults to: nil)

    The genus name

  • species (String) (defaults to: nil)

    The species name

  • species_any (String) (defaults to: nil)

    Any part of the species name

  • infraspecies (String) (defaults to: nil)

    The infraspecies name

  • author (String) (defaults to: nil)

    The author name

  • year (Integer) (defaults to: nil)

    The year of publication

  • year_start (Integer) (defaults to: nil)

    The start year for a range search

  • year_end (Integer) (defaults to: nil)

    The end year for a range search

  • with_all_results (Boolean) (defaults to: nil)

    Show all matches for each name



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/checkerberry.rb', line 59

def self.search(query: nil, data_sources: nil, parent_taxon: nil,
                name_string: nil, genus: nil, species: nil,
                species_any: nil, infraspecies: nil, author: nil,
                year: nil, year_start: nil, year_end: nil,
                with_all_results: nil, verbose: false)
  endpoint = "search"

  # require year_start and year_end together
  if year_start && !year_end
    raise ArgumentError, "year_end is required when year_start is provided"
  end
  if year_end && !year_start
    raise ArgumentError, "year_start is required when year_end is provided"
  end

  # require no year if year_start and year_end are provided
  if (year_start || year_end) && year
    raise ArgumentError, "year cannot be provided when year_start and year_end are provided"
  end

  data_sources_array = data_sources.is_a?(Array) ? data_sources : (data_sources.nil? ? nil : [data_sources])
  Request.new(endpoint: endpoint, method: :post,
              query: query, data_sources: data_sources_array, parent_taxon: parent_taxon,
              name_string: name_string, genus: genus, species: species,
              species_any: species_any, infraspecies: infraspecies,
              author: author, year: year, year_start: year_start,
              year_end: year_end, with_all_results: with_all_results,
              verbose: verbose).perform
end

.verify(names, data_sources: nil, vernacular_languages: nil, with_all_matches: nil, with_capitalization: nil, with_species_group: nil, with_uninomial_fuzzy_match: nil, with_stats: nil, min_taxon_threshold: nil, verbose: false) ⇒ Hash

Verify scientific names

Parameters:

  • names (String, Array)

    A single name or array of names to verify

  • data_sources (Array, Integer) (defaults to: nil)

    The data source IDs to use for verification

  • vernacular_languages (String, Array) (defaults to: nil)

    A single language ISO 639-3 or an array of ISO 639-3 languages for vernacular names

  • with_all_matches (Boolean) (defaults to: nil)

    Show all matches for each name

  • with_capitalization (Boolean) (defaults to: nil)

    Capitalize the first character

  • with_species_group (Boolean) (defaults to: nil)

    Match to species group

  • with_uninomial_fuzzy_match (Boolean) (defaults to: nil)

    Enable uninomial fuzzy matching

  • with_stats (Boolean) (defaults to: nil)

    Include statistics in response

  • min_taxon_threshold (Float) (defaults to: nil)

    The minimum taxon threshold for main taxon assignment

  • verbose (Boolean) (defaults to: false)

    Print headers to STDOUT

Returns:

  • (Hash)

    A hash with verification results



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/checkerberry.rb', line 29

def self.verify(names, data_sources: nil, vernacular_languages: nil,
                with_all_matches: nil, with_capitalization: nil,
                with_species_group: nil, with_uninomial_fuzzy_match: nil,
                with_stats: nil, min_taxon_threshold: nil, verbose: false)
  endpoint = "verifications"
  names_array = names.is_a?(Array) ? names : [names]
  data_sources_array = data_sources.is_a?(Array) ? data_sources : (data_sources.nil? ? nil : [data_sources])
  Request.new(endpoint: endpoint, method: :post, names: names_array,
              data_sources: data_sources_array, vernacular_languages: vernacular_languages,
              with_all_matches: with_all_matches, with_capitalization: with_capitalization,
              with_species_group: with_species_group, with_uninomial_fuzzy_match: with_uninomial_fuzzy_match,
              with_stats: with_stats, min_taxon_threshold: min_taxon_threshold,
              verbose: verbose).perform
end

.version(verbose: false) ⇒ Hash

Get version information

Parameters:

  • verbose (Boolean) (defaults to: false)

    Print headers to STDOUT

Returns:

  • (Hash)

    A hash with version information



123
124
125
126
# File 'lib/checkerberry.rb', line 123

def self.version(verbose: false)
  endpoint = "version"
  Request.new(endpoint: endpoint, verbose: verbose).perform
end