Module: Bananomia

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

Defined Under Namespace

Classes: BadGateway, BadRequest, Error, GatewayTimeout, InternalServerError, NotFound, Request, ServiceUnavailable

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Methods included from Configuration

configuration, define_setting

Class Method Details

.occurrence(id, verbose: false) ⇒ Hash, Boolean

Get and occurrence record

Parameters:

  • id (String)

    An occurence ID from Global Biodiversity Information Facility

  • verbose (Boolean) (defaults to: false)

    Print headers to STDOUT

Returns:

  • (Hash, Boolean)

    A JSON-LD hash



61
62
63
64
# File 'lib/bananomia.rb', line 61

def self.occurrence(id, verbose: false)
  endpoint = "occurrence/#{id}.jsonld"
  Request.new(endpoint: endpoint, verbose: verbose).perform
end

.parse(names, verbose: false) ⇒ Array, Boolean

Parse human names

Parameters:

  • names (String)

    Human name(s) separated by rn

  • verbose (Boolean) (defaults to: false)

    Print headers to STDOUT

Returns:

  • (Array, Boolean)

    An array of hashes



22
23
24
25
26
27
28
29
# File 'lib/bananomia.rb', line 22

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

.person(id, csv: nil, specimens: nil, page: nil, verbose: false) ⇒ Hash, ...

Get a person’s profile by ID or specimens

Parameters:

  • id (String)

    An ORCID or WikiData identifier

  • specimens (Boolean, nil) (defaults to: nil)

    Get the person’s specimens

  • csv (Boolean, nil) (defaults to: nil)

    For specimens, whether to return a csv

  • page (Integer, nil) (defaults to: nil)

    Pagination for the results list

  • verbose (Boolean) (defaults to: false)

    Print headers to STDOUT

Returns:

  • (Hash, String, Boolean)

    A JSON-LD hash or CSV



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bananomia.rb', line 40

def self.person(id, csv: nil, specimens: nil, page: nil, verbose: false)
  if csv and specimens
    extension = '.csv'
  else
    extension = '.jsonld'
  end

  if specimens
    endpoint = "#{id}/specimens#{extension}"
  else
    endpoint = "#{id}#{extension}"
  end
  Request.new(endpoint: endpoint, page: page, verbose: verbose).perform
end

.search_occurrences(dataset_id, occurrence_id, callback: nil, verbose: false) ⇒ Array, Boolean

Search occurrences

Parameters:

  • dataset_id (String)

    a registered dataset UUID provided by the Global Biodiversity Information Facility

  • occurrence_id (String)

    identifier from the data provider

  • callback (String, nil) (defaults to: nil)

    A string to produce a JSONP response instead of a JSON-LD response

  • page (Integer, nil)

    Pagination for the results list

  • verbose (Boolean) (defaults to: false)

    Print headers to STDOUT

Returns:

  • (Array, Boolean)

    An array of hashes



106
107
108
109
110
111
112
113
114
115
# File 'lib/bananomia.rb', line 106

def self.search_occurrences(dataset_id, occurrence_id, callback: nil, verbose: false)
  endpoint = 'occurrences/search'
  Request.new(
    endpoint: endpoint,
    dataset_id: dataset_id,
    occurrence_id: occurrence_id,
    callback: callback,
    verbose: verbose
  ).perform
end

.search_people(q, families_collected: nil, families_identified: nil, date: nil, page: nil, strict: nil, callback: nil, verbose: false) ⇒ Array, Boolean

Search human names

Parameters:

  • q (String)

    A single human name

  • families_collected (Boolean, nil) (defaults to: nil)

    Comma-separated list of taxonomic families collected

  • families_identified (Boolean, nil) (defaults to: nil)

    Comma-separated list of taxonomic families identified

  • date (String, nil) (defaults to: nil)

    Filters to alive during date (format: YYYY-MM-DD, YYYY-MM, or YYYY) e.g., Captain John Smith was alive from 1580-01-01 through 1631-06-21, so setting date to any value between

    their birth/death date will include Captain John in the search results
    

    Warning: Setting exactly equal to a person’s birthdate, excludes them from search!

  • strict (Boolean, nil) (defaults to: nil)

    Must include vs should include on families_identified, families_collected, date

  • callback (String, nil) (defaults to: nil)

    A string to produce a JSONP response instead of a JSON-LD response

  • page (Integer, nil) (defaults to: nil)

    Pagination for the results list

  • verbose (Boolean) (defaults to: false)

    Print headers to STDOUT

Returns:

  • (Array, Boolean)

    An array of hashes



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/bananomia.rb', line 81

def self.search_people(q, families_collected: nil, families_identified: nil, date: nil, page: nil,
                strict: nil, callback: nil, verbose: false)
  endpoint = 'users/search'
  Request.new(
    endpoint: endpoint,
    q: q,
    families_collected: families_collected,
    families_identified: families_identified,
    date: date,
    page: page,
    strict: strict,
    callback: callback,
    verbose: verbose
  ).perform
end

.suggest(q, is_public: nil, has_occurrences: nil, limit: nil, verbose: false) ⇒ Array, Boolean

Suggest human names (autocomplete widget)

Parameters:

  • q (String)

    Part of a human name

  • is_public (Boolean, nil) (defaults to: nil)

    Filters results to public profiles

  • has_occurrences (Boolean, nil) (defaults to: nil)

    Filters results to profiles with occurrences

  • limit (Integer, nil) (defaults to: nil)

    The number of results to return

  • verbose (Boolean) (defaults to: false)

    Print headers to STDOUT

Returns:

  • (Array, Boolean)

    An array of hashes



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/bananomia.rb', line 126

def self.suggest(q, is_public: nil, has_occurrences: nil, limit: nil, verbose: false)
  endpoint = 'user.json'
  Request.new(
    endpoint: endpoint,
    q: q,
    is_public: is_public,
    has_occurrences: has_occurrences,
    limit: limit,
    verbose: verbose
  ).perform
end