crawlyflower 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d09d7c7cbc67c9f0b951b65721429f50954afbda4498fb7164ef1e4baef662e8
4
+ data.tar.gz: e819ff083cc3ad3fc3cf9adf21e778d84de499617060178c9ede90e0e2618a2b
5
+ SHA512:
6
+ metadata.gz: 52b5955cb246e580e919bb2f083236de3b1e8d56ebbe110e8004d5b104f7f2ee0ce22078692f30f063b8d48d86aad49da78e7c2aa916425363d88cf8c05b6c2d
7
+ data.tar.gz: abb488db453c0a9eccfbb6fb16803b1873277720451a612c0cae1ac4b4eb351bd08d480ec57a1eeae5d461970517c1534cbc611c027026694ea05372224deb2f
@@ -0,0 +1,20 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.3.4
14
+ bundler-cache: true
15
+ - name: Run the default task
16
+ run: bundle exec rake
17
+ env:
18
+ USER: ${{ vars.USER }}
19
+ PASSWORD: ${{ secrets.PASSWORD }}
20
+
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .byebug_history
2
+ .vscode
3
+ .idea
4
+ /.bundle/
5
+ /.yardoc
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+ *.gem
13
+ Gemfile.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.0.1] - 2026-03-03
4
+
5
+ - Initial release
6
+
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at diapriid@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in crawlyflower.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2026 Species File Group
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # Crawlyflower
2
+
3
+ <img src="https://github.com/SpeciesFileGroup/crawlyflower/blob/main/crawlyflower.png" width="350" alt="Crawlyflower"/>
4
+
5
+ `crawlyflower` (a play on cauliflower) is a low-level wrapper around the [WoRMS (World Register of Marine Species) REST API](https://www.marinespecies.org/rest/). Code follows the spirit/approach of the Gem [serrano](https://github.com/sckott/serrano), and indeed much of the wrapping utility is copied 1:1 from that repo, thanks [@sckott](https://github.com/sckott).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'crawlyflower'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install crawlyflower
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'crawlyflower'
27
+ ```
28
+
29
+ Get a record by AphiaID:
30
+ ```ruby
31
+ Crawlyflower.record(127160)
32
+ ```
33
+
34
+ Get classification:
35
+ ```ruby
36
+ Crawlyflower.classification(127160)
37
+ ```
38
+
39
+ Search by name:
40
+ ```ruby
41
+ Crawlyflower.records_by_name("Solea solea")
42
+ ```
43
+
44
+ Get children of a taxon:
45
+ ```ruby
46
+ Crawlyflower.children(126132)
47
+ ```
48
+
49
+ Get synonyms:
50
+ ```ruby
51
+ Crawlyflower.synonyms(127160)
52
+ ```
53
+
54
+ Get vernacular names:
55
+ ```ruby
56
+ Crawlyflower.vernaculars(127160)
57
+ ```
58
+
59
+ Get distributions:
60
+ ```ruby
61
+ Crawlyflower.distributions(127160)
62
+ ```
63
+
64
+ Get sources:
65
+ ```ruby
66
+ Crawlyflower.sources(127160)
67
+ ```
68
+
69
+ Get external identifiers:
70
+ ```ruby
71
+ Crawlyflower.external_id(127160, type: "tsn")
72
+ ```
73
+
74
+ Get attributes:
75
+ ```ruby
76
+ Crawlyflower.attributes(127160)
77
+ ```
78
+
79
+ Suggest taxa by name prefix:
80
+ ```ruby
81
+ Crawlyflower.suggest("Solea")
82
+ ```
83
+
84
+ ## Development
85
+
86
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
87
+
88
+ To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, update the CHANGELOG.md, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
89
+
90
+ ## License
91
+
92
+ The gem is available as open source under the terms of the [MIT license](https://github.com/SpeciesFileGroup/crawlyflower/blob/main/LICENSE.txt). You can learn more about the MIT license on [Wikipedia](https://en.wikipedia.org/wiki/MIT_License) and compare it with other open source licenses at the [Open Source Initiative](https://opensource.org/license/mit/).
93
+
94
+ ## Code of Conduct
95
+
96
+ Everyone interacting in the Crawlyflower project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/SpeciesFileGroup/crawlyflower/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ t.verbose = true
11
+ end
12
+
13
+ desc "Run tests"
14
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "crawlyflower"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/crawlyflower/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "crawlyflower"
7
+ s.version = Crawlyflower::VERSION
8
+ s.authors = ["Geoff Ower"]
9
+ s.email = ["gdower@illinois.edu"]
10
+
11
+ s.summary = "WoRMS REST API Client"
12
+ s.description = "crawlyflower is a low-level wrapper around the WoRMS (World Register of Marine Species) REST API."
13
+ s.homepage = "https://github.com/SpeciesFileGroup/crawlyflower"
14
+ s.license = "MIT"
15
+ s.required_ruby_version = ">= 2.5.0"
16
+
17
+ s.metadata["homepage_uri"] = s.homepage
18
+ s.metadata["source_code_uri"] = "https://github.com/SpeciesFileGroup/crawlyflower"
19
+ s.metadata["changelog_uri"] = "https://github.com/SpeciesFileGroup/crawlyflower/releases/tag/v#{s.version}"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ s.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|s|features)/}) }
25
+ end
26
+ s.bindir = "exe"
27
+ s.executables = s.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ s.require_paths = ["lib"]
29
+
30
+ s.add_development_dependency "bundler", "~> 2.1", ">= 2.1.4"
31
+ s.add_development_dependency "rake", "~> 13.0", ">= 13.0.1"
32
+ s.add_development_dependency "test-unit", "~> 3.3", ">= 3.3.6"
33
+ s.add_development_dependency "vcr", "~> 6.0"
34
+ s.add_development_dependency "webmock", "~> 3.18"
35
+
36
+ s.add_runtime_dependency "faraday", "~> 2.2"
37
+ s.add_runtime_dependency "faraday-follow_redirects", ">= 0.1", "< 0.4"
38
+ s.add_runtime_dependency "multi_json", "~> 1.15"
39
+ end
data/crawlyflower.png ADDED
Binary file
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crawlyflower
4
+ # Custom error class for rescuing from all Crawlyflower errors
5
+ class Error < StandardError; end
6
+
7
+ # Raised when WoRMS returns the HTTP status code 400
8
+ class BadRequest < Error; end
9
+
10
+ # Raised when WoRMS returns the HTTP status code 404
11
+ class NotFound < Error; end
12
+
13
+ # Raised when WoRMS returns the HTTP status code 500
14
+ class InternalServerError < Error; end
15
+
16
+ # Raised when WoRMS returns the HTTP status code 502
17
+ class BadGateway < Error; end
18
+
19
+ # Raised when WoRMS returns the HTTP status code 503
20
+ class ServiceUnavailable < Error; end
21
+
22
+ # Raised when WoRMS returns the HTTP status code 504
23
+ class GatewayTimeout < Error; end
24
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "multi_json"
5
+
6
+ # @private
7
+ module Faraday
8
+ module CrawlyflowerErrors
9
+ # @private
10
+ class Middleware < Faraday::Middleware
11
+ def call(env)
12
+ @app.call(env).on_complete do |response|
13
+ case response[:status].to_i
14
+ when 400
15
+ raise Crawlyflower::BadRequest, error_message_400(response)
16
+ when 404
17
+ raise Crawlyflower::NotFound, error_message_400(response)
18
+ when 500
19
+ raise Crawlyflower::InternalServerError, error_message_500(response, "Something is technically wrong.")
20
+ when 502
21
+ raise Crawlyflower::BadGateway, error_message_500(response, "The server returned an invalid or incomplete response.")
22
+ when 503
23
+ raise Crawlyflower::ServiceUnavailable, error_message_500(response, "The service is unavailable.")
24
+ when 504
25
+ raise Crawlyflower::GatewayTimeout, error_message_500(response, "504 Gateway Time-out")
26
+ end
27
+ end
28
+ end
29
+
30
+ def initialize(app)
31
+ super app
32
+ @parser = nil
33
+ end
34
+
35
+ private
36
+
37
+ def error_message_400(response)
38
+ "\n #{response[:method].to_s.upcase} #{response[:url]}\n Status #{response[:status]}#{error_body(response[:body])}"
39
+ end
40
+
41
+ def error_body(body)
42
+ if !body.nil? && !body.empty? && body.is_a?(String)
43
+ if json?(body)
44
+ body = ::MultiJson.load(body)
45
+ if body["message"].nil?
46
+ body = nil
47
+ else
48
+ body = body["message"]
49
+ end
50
+ end
51
+ end
52
+
53
+ if body.nil?
54
+ nil
55
+ else
56
+ ": #{body}"
57
+ end
58
+ end
59
+
60
+ def error_message_500(response, body = nil)
61
+ "#{response[:method].to_s.upcase} #{response[:url]}: #{[response[:status].to_s + ":", body].compact.join(" ")}"
62
+ end
63
+
64
+ def json?(string)
65
+ MultiJson.load(string)
66
+ true
67
+ rescue MultiJson::ParseError
68
+ false
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,25 @@
1
+ # taken from https://raw.githubusercontent.com/sckott/serrano/main/lib/serrano/helpers/configuration.rb
2
+ # taken from: https://viget.com/extend/easy-gem-configuration-variables-with-defaults
3
+ module Configuration
4
+ def configuration
5
+ yield self
6
+ end
7
+
8
+ def define_setting(name, default = nil)
9
+ class_variable_set("@@#{name}", default)
10
+ define_class_method "#{name}=" do |value|
11
+ class_variable_set("@@#{name}", value)
12
+ end
13
+ define_class_method name do
14
+ class_variable_get("@@#{name}")
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def define_class_method(name, &block)
21
+ (class << self; self; end).instance_eval do
22
+ define_method name, &block
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,41 @@
1
+ require_relative "faraday"
2
+ require "faraday/follow_redirects"
3
+ require_relative "utils"
4
+ require "crawlyflower/error"
5
+
6
+ module Crawlyflower
7
+ class Request
8
+ attr_accessor :endpoint, :verbose, :options
9
+
10
+ def initialize(**args)
11
+ @endpoint = args[:endpoint]
12
+ @verbose = args[:verbose]
13
+ @options = args[:options] || {}
14
+ @accept = args[:accept] || 'application/json,*/*'
15
+ end
16
+
17
+ def perform
18
+ conn = Faraday.new(url: Crawlyflower.base_url, request: { params_encoder: Faraday::FlatParamsEncoder }) do |f|
19
+ f.response :logger if @verbose
20
+ f.use Faraday::CrawlyflowerErrors::Middleware
21
+ f.response :follow_redirects
22
+ f.adapter Faraday.default_adapter
23
+ end
24
+
25
+ conn.headers['Accept'] = @accept
26
+ conn.headers[:user_agent] = make_user_agent
27
+ conn.headers["X-USER-AGENT"] = make_user_agent
28
+
29
+ res = conn.get endpoint, @options
30
+
31
+ # WoRMS returns 204 for "nothing found"
32
+ return nil if res.status == 204
33
+
34
+ begin
35
+ MultiJson.load(res.body)
36
+ rescue MultiJson::ParseError
37
+ res.body
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # From https://raw.githubusercontent.com/sckott/serrano/main/lib/serrano/utils.rb
4
+
5
+ def make_user_agent
6
+ requa = "Faraday/v" + Faraday::VERSION
7
+ habua = "Crawlyflower/v" + Crawlyflower::VERSION
8
+ ua = requa + " " + habua
9
+ ua
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crawlyflower
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,346 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+ require_relative "crawlyflower/error"
5
+ require_relative "crawlyflower/version"
6
+ require_relative "crawlyflower/request"
7
+ require "crawlyflower/helpers/configuration"
8
+
9
+ module Crawlyflower
10
+ extend Configuration
11
+
12
+ define_setting :base_url, "https://www.marinespecies.org/rest/"
13
+
14
+ # Get the direct children (max. 50) for a given AphiaID
15
+ #
16
+ # @param id [Integer] The AphiaID to search for
17
+ # @param marine_only [Boolean] Limit to marine taxa. Default: true
18
+ # @param extant_only [Boolean] Limit to extant taxa. Default: true
19
+ # @param offset [Integer] Starting record number. Default: 1
20
+ #
21
+ # @return [Array, nil] An array of AphiaRecords or nil if nothing found
22
+ def self.children(id, marine_only: nil, extant_only: nil, offset: nil, verbose: false)
23
+ endpoint = "AphiaChildrenByAphiaID/#{id}"
24
+ opts = { marine_only: marine_only, extant_only: extant_only, offset: offset }.compact
25
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
26
+ end
27
+
28
+ # Get the complete classification for one taxon
29
+ #
30
+ # @param id [Integer] The AphiaID to search for
31
+ #
32
+ # @return [Hash, nil] A classification hash or nil if nothing found
33
+ def self.classification(id, verbose: false)
34
+ endpoint = "AphiaClassificationByAphiaID/#{id}"
35
+ Request.new(endpoint: endpoint, verbose: verbose).perform
36
+ end
37
+
38
+ # Get all distributions for a given AphiaID
39
+ #
40
+ # @param id [Integer] The AphiaID to search for
41
+ #
42
+ # @return [Array, nil] An array of distributions or nil if nothing found
43
+ def self.distributions(id, verbose: false)
44
+ endpoint = "AphiaDistributionsByAphiaID/#{id}"
45
+ Request.new(endpoint: endpoint, verbose: verbose).perform
46
+ end
47
+
48
+ # Get any external identifier(s) for a given AphiaID
49
+ #
50
+ # @param id [Integer] The AphiaID to search for
51
+ # @param type [String] Type of external identifier (algaebase, bold, dyntaxa, fishbase, iucn, lsid, ncbi, tsn, gisd)
52
+ #
53
+ # @return [Array, nil] An array of external identifiers or nil if nothing found
54
+ def self.external_id(id, type: nil, verbose: false)
55
+ endpoint = "AphiaExternalIDByAphiaID/#{id}"
56
+ opts = { type: type }.compact
57
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
58
+ end
59
+
60
+ # Get the AphiaID for a given name
61
+ #
62
+ # @param name [String] Name to search for
63
+ # @param marine_only [Boolean] Limit to marine taxa. Default: true
64
+ # @param extant_only [Boolean] Limit to extant taxa. Default: true
65
+ #
66
+ # @return [Integer, nil] An AphiaID, -999 for multiple matches, or nil if nothing found
67
+ def self.aphia_id_by_name(name, marine_only: nil, extant_only: nil, verbose: false)
68
+ endpoint = "AphiaIDByName/#{ERB::Util.url_encode(name)}"
69
+ opts = { marine_only: marine_only, extant_only: extant_only }.compact
70
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
71
+ end
72
+
73
+ # Get the name for a given AphiaID
74
+ #
75
+ # @param id [Integer] The AphiaID to search for
76
+ #
77
+ # @return [String, nil] The scientific name or nil if nothing found
78
+ def self.name(id, verbose: false)
79
+ endpoint = "AphiaNameByAphiaID/#{id}"
80
+ Request.new(endpoint: endpoint, verbose: verbose).perform
81
+ end
82
+
83
+ # Get the complete AphiaRecord for a given AphiaID
84
+ #
85
+ # @param id [Integer] The AphiaID to search for
86
+ #
87
+ # @return [Hash, nil] An AphiaRecord hash or nil if nothing found
88
+ def self.record(id, verbose: false)
89
+ endpoint = "AphiaRecordByAphiaID/#{id}"
90
+ Request.new(endpoint: endpoint, verbose: verbose).perform
91
+ end
92
+
93
+ # Get AphiaRecords for multiple AphiaIDs in one go (max: 50)
94
+ #
95
+ # @param ids [Array<Integer>] The AphiaIDs to search for
96
+ #
97
+ # @return [Array, nil] An array of AphiaRecords or nil if nothing found
98
+ def self.records_by_aphia_ids(ids, verbose: false)
99
+ endpoint = "AphiaRecordsByAphiaIDs"
100
+ opts = { "aphiaids[]": Array(ids) }
101
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
102
+ end
103
+
104
+ # Get the Aphia Record for a given external identifier
105
+ #
106
+ # @param id [String] The external identifier to search for
107
+ # @param type [String] Type of external identifier (algaebase, bold, dyntaxa, fishbase, iucn, lsid, ncbi, tsn, gisd)
108
+ #
109
+ # @return [Hash, nil] An AphiaRecord hash or nil if nothing found
110
+ def self.record_by_external_id(id, type: nil, verbose: false)
111
+ endpoint = "AphiaRecordByExternalID/#{ERB::Util.url_encode(id.to_s)}"
112
+ opts = { type: type }.compact
113
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
114
+ end
115
+
116
+ # Lists all AphiaRecords that have their last edit action during the specified period
117
+ #
118
+ # @param startdate [String] ISO 8601 formatted start date(time)
119
+ # @param enddate [String] ISO 8601 formatted end date(time)
120
+ # @param marine_only [Boolean] Limit to marine taxa
121
+ # @param extant_only [Boolean] Limit to extant taxa
122
+ # @param offset [Integer] Starting record number. Default: 1
123
+ #
124
+ # @return [Array, nil] An array of AphiaRecords or nil if nothing found
125
+ def self.records_by_date(startdate:, enddate: nil, marine_only: nil, extant_only: nil, offset: nil, verbose: false)
126
+ endpoint = "AphiaRecordsByDate"
127
+ opts = { startdate: startdate, enddate: enddate, marine_only: marine_only, extant_only: extant_only, offset: offset }.compact
128
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
129
+ end
130
+
131
+ # Try to find AphiaRecords using the TAXAMATCH fuzzy matching algorithm
132
+ #
133
+ # @param scientificnames [Array<String>] Names to search for
134
+ # @param authorships [Array<String>] The authorities of the given names
135
+ # @param marine_only [Boolean] Limit to marine taxa
136
+ # @param extant_only [Boolean] Limit to extant taxa
137
+ # @param match_authority [Boolean] Use the authority in the matching process
138
+ #
139
+ # @return [Array, nil] An array of arrays of AphiaRecords or nil if nothing found
140
+ def self.records_by_match_names(scientificnames:, authorships: nil, marine_only: nil, extant_only: nil, match_authority: nil, verbose: false)
141
+ endpoint = "AphiaRecordsByMatchNames"
142
+ opts = { "scientificnames[]": Array(scientificnames), marine_only: marine_only, extant_only: extant_only, match_authority: match_authority }
143
+ opts[:"authorships[]"] = Array(authorships) if authorships
144
+ opts = opts.compact
145
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
146
+ end
147
+
148
+ # Get one or more matching (max. 50) AphiaRecords for a given name
149
+ #
150
+ # @param name [String] Name to search for
151
+ # @param like [Boolean] Add a '%'-sign after the ScientificName. Default: true
152
+ # @param marine_only [Boolean] Limit to marine taxa
153
+ # @param extant_only [Boolean] Limit to extant taxa
154
+ # @param offset [Integer] Starting record number. Default: 1
155
+ #
156
+ # @return [Array, nil] An array of AphiaRecords or nil if nothing found
157
+ def self.records_by_name(name, like: nil, marine_only: nil, extant_only: nil, offset: nil, verbose: false)
158
+ endpoint = "AphiaRecordsByName/#{ERB::Util.url_encode(name)}"
159
+ opts = { like: like, marine_only: marine_only, extant_only: extant_only, offset: offset }.compact
160
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
161
+ end
162
+
163
+ # For each given scientific name, try to find one or more AphiaRecords (max 500 names)
164
+ #
165
+ # @param scientificnames [Array<String>] Names to search for
166
+ # @param like [Boolean] Add a '%'-sign after the ScientificName. Default: false
167
+ # @param marine_only [Boolean] Limit to marine taxa
168
+ # @param extant_only [Boolean] Limit to extant taxa
169
+ #
170
+ # @return [Array, nil] An array of arrays of AphiaRecords or nil if nothing found
171
+ def self.records_by_names(scientificnames:, like: nil, marine_only: nil, extant_only: nil, verbose: false)
172
+ endpoint = "AphiaRecordsByNames"
173
+ opts = { "scientificnames[]": Array(scientificnames), like: like, marine_only: marine_only, extant_only: extant_only }.compact
174
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
175
+ end
176
+
177
+ # Get one or more Aphia Records (max. 50) for a given vernacular
178
+ #
179
+ # @param name [String] The vernacular to find records for
180
+ # @param like [Boolean] Add a '%'-sign before and after the input. Default: false
181
+ # @param offset [Integer] Starting record number. Default: 1
182
+ #
183
+ # @return [Array, nil] An array of AphiaRecords or nil if nothing found
184
+ def self.records_by_vernacular(name, like: nil, offset: nil, verbose: false)
185
+ endpoint = "AphiaRecordsByVernacular/#{ERB::Util.url_encode(name)}"
186
+ opts = { like: like, offset: offset }.compact
187
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
188
+ end
189
+
190
+ # Get all synonyms for a given AphiaID
191
+ #
192
+ # @param id [Integer] The AphiaID to search for
193
+ # @param offset [Integer] Starting record number. Default: 1
194
+ #
195
+ # @return [Array, nil] An array of AphiaRecords or nil if nothing found
196
+ def self.synonyms(id, offset: nil, verbose: false)
197
+ endpoint = "AphiaSynonymsByAphiaID/#{id}"
198
+ opts = { offset: offset }.compact
199
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
200
+ end
201
+
202
+ # Get all vernaculars for a given AphiaID
203
+ #
204
+ # @param id [Integer] The AphiaID to search for
205
+ #
206
+ # @return [Array, nil] An array of vernaculars or nil if nothing found
207
+ def self.vernaculars(id, verbose: false)
208
+ endpoint = "AphiaVernacularsByAphiaID/#{id}"
209
+ Request.new(endpoint: endpoint, verbose: verbose).perform
210
+ end
211
+
212
+ # Get one or more sources/references including links, for one AphiaID
213
+ #
214
+ # @param id [Integer] The AphiaID to search for
215
+ #
216
+ # @return [Array, nil] An array of sources or nil if nothing found
217
+ def self.sources(id, verbose: false)
218
+ endpoint = "AphiaSourcesByAphiaID/#{id}"
219
+ Request.new(endpoint: endpoint, verbose: verbose).perform
220
+ end
221
+
222
+ # Get taxonomic ranks by their identifier
223
+ #
224
+ # @param id [Integer] A taxonomic rank identifier. Default: -1
225
+ # @param aphia_id [Integer] The AphiaID of the kingdom
226
+ #
227
+ # @return [Array, nil] An array of taxonomic ranks or nil if nothing found
228
+ def self.taxon_ranks_by_id(id, aphia_id: nil, verbose: false)
229
+ endpoint = "AphiaTaxonRanksByID/#{id}"
230
+ opts = { AphiaID: aphia_id }.compact
231
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
232
+ end
233
+
234
+ # Get taxonomic ranks by their name
235
+ #
236
+ # @param name [String] A taxonomic rank name
237
+ # @param aphia_id [Integer] The AphiaID of the kingdom
238
+ #
239
+ # @return [Array, nil] An array of taxonomic ranks or nil if nothing found
240
+ def self.taxon_ranks_by_name(name, aphia_id: nil, verbose: false)
241
+ endpoint = "AphiaTaxonRanksByName/#{ERB::Util.url_encode(name)}"
242
+ opts = { AphiaID: aphia_id }.compact
243
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
244
+ end
245
+
246
+ # Get the AphiaRecords for a given taxonRankID (max 50)
247
+ #
248
+ # @param id [Integer] A taxonomic rank identifier
249
+ # @param belongs_to [Integer] Limit the results to descendants of the given AphiaID
250
+ # @param offset [Integer] Starting record number. Default: 1
251
+ #
252
+ # @return [Array, nil] An array of AphiaRecords or nil if nothing found
253
+ def self.records_by_taxon_rank_id(id, belongs_to: nil, offset: nil, verbose: false)
254
+ endpoint = "AphiaRecordsByTaxonRankID/#{id}"
255
+ opts = { belongsTo: belongs_to, offset: offset }.compact
256
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
257
+ end
258
+
259
+ FULL_RECORD_FORMATS = {
260
+ jsonld: 'application/ld+json',
261
+ rdf: 'application/rdf+xml',
262
+ turtle: 'text/turtle',
263
+ ntriples: 'application/n-triples'
264
+ }.freeze
265
+
266
+ # Get the complete AphiaFullRecord (linked open data) for a given AphiaID
267
+ #
268
+ # @param id [Integer] The AphiaID to search for
269
+ # @param format [Symbol] Response format: :jsonld (default), :rdf, :turtle, :ntriples
270
+ #
271
+ # @return [Hash, String, nil] The full record or nil if nothing found
272
+ def self.full_record(id, format: :jsonld, verbose: false)
273
+ endpoint = "AphiaRecordFullByAphiaID/#{id}"
274
+ accept = FULL_RECORD_FORMATS[format] || FULL_RECORD_FORMATS[:jsonld]
275
+ Request.new(endpoint: endpoint, verbose: verbose, accept: accept).perform
276
+ end
277
+
278
+ # Get attribute definitions
279
+ #
280
+ # @param id [Integer] The attribute definition id to search for. Use 0 for root items
281
+ # @param include_children [Boolean] Include the tree of children. Default: true
282
+ #
283
+ # @return [Array, nil] An array of attribute keys or nil if nothing found
284
+ def self.attribute_keys(id, include_children: nil, verbose: false)
285
+ endpoint = "AphiaAttributeKeysByID/#{id}"
286
+ opts = { include_children: include_children }.compact
287
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
288
+ end
289
+
290
+ # Get list values that are grouped by a CategoryID
291
+ #
292
+ # @param id [Integer] The CategoryID to search for
293
+ #
294
+ # @return [Array, nil] An array of attribute values or nil if nothing found
295
+ def self.attribute_values_by_category(id, verbose: false)
296
+ endpoint = "AphiaAttributeValuesByCategoryID/#{id}"
297
+ Request.new(endpoint: endpoint, verbose: verbose).perform
298
+ end
299
+
300
+ # Get a list of AphiaIDs (max 50) with attribute tree for a given attribute definition ID
301
+ #
302
+ # @param id [Integer] The attribute definition id to search for
303
+ # @param offset [Integer] Starting record number. Default: 1
304
+ #
305
+ # @return [Array, nil] An array of AphiaAttributeSets or nil if nothing found
306
+ def self.aphia_ids_by_attribute_key(id, offset: nil, verbose: false)
307
+ endpoint = "AphiaIDsByAttributeKeyID/#{id}"
308
+ opts = { offset: offset }.compact
309
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
310
+ end
311
+
312
+ # Get a list of attributes for a given AphiaID
313
+ #
314
+ # @param id [Integer] The AphiaID to search for
315
+ # @param include_inherited [Boolean] Include attributes inherited from parent(s). Default: false
316
+ #
317
+ # @return [Array, nil] An array of attributes or nil if nothing found
318
+ def self.attributes(id, include_inherited: nil, verbose: false)
319
+ endpoint = "AphiaAttributesByAphiaID/#{id}"
320
+ opts = { include_inherited: include_inherited }.compact
321
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
322
+ end
323
+
324
+ # Get taxa suggestions for a given prefix of a taxon name
325
+ #
326
+ # @param name_part [String] The prefix to use to search for taxa
327
+ # @param rank_min [Integer] The minimum rank of the returned suggestion. Default: 10
328
+ # @param rank_max [Integer] The maximum rank of the returned suggestion. Default: 280
329
+ # @param max_matches [Integer] The maximum number of suggestions to return. Default: 20, Max: 50
330
+ # @param excluded_ids [Array<Integer>] AphiaIDs to exclude from the result set
331
+ # @param combine_vernaculars [Boolean] When true the name can also match vernaculars. Default: false
332
+ # @param marine_only [Boolean] Limit to marine taxa. Default: true
333
+ # @param fossil_id [Integer] Determines the search behavior for fossil taxa. Default: 0
334
+ # @param languages [Array<String>] List of ISO 639-3 language codes to filter search results
335
+ #
336
+ # @return [Array, nil] An array of suggestion records or nil if nothing found
337
+ def self.suggest(name_part, rank_min: nil, rank_max: nil, max_matches: nil, excluded_ids: nil, combine_vernaculars: nil, marine_only: nil, fossil_id: nil, languages: nil, verbose: false)
338
+ endpoint = "AjaxAphiaRecordsByNamePart/#{ERB::Util.url_encode(name_part)}"
339
+ opts = { rank_min: rank_min, rank_max: rank_max, max_matches: max_matches,
340
+ combine_vernaculars: combine_vernaculars, marine_only: marine_only, fossil_id: fossil_id }
341
+ opts[:"excluded_ids[]"] = Array(excluded_ids) if excluded_ids
342
+ opts[:"languages[]"] = Array(languages) if languages
343
+ opts = opts.compact
344
+ Request.new(endpoint: endpoint, verbose: verbose, options: opts).perform
345
+ end
346
+ end
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crawlyflower
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Geoff Ower
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: bundler
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.1'
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: 2.1.4
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '2.1'
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 2.1.4
32
+ - !ruby/object:Gem::Dependency
33
+ name: rake
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '13.0'
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 13.0.1
42
+ type: :development
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '13.0'
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 13.0.1
52
+ - !ruby/object:Gem::Dependency
53
+ name: test-unit
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "~>"
57
+ - !ruby/object:Gem::Version
58
+ version: '3.3'
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.3.6
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 3.3.6
72
+ - !ruby/object:Gem::Dependency
73
+ name: vcr
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - "~>"
77
+ - !ruby/object:Gem::Version
78
+ version: '6.0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '6.0'
86
+ - !ruby/object:Gem::Dependency
87
+ name: webmock
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '3.18'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '3.18'
100
+ - !ruby/object:Gem::Dependency
101
+ name: faraday
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '2.2'
107
+ type: :runtime
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '2.2'
114
+ - !ruby/object:Gem::Dependency
115
+ name: faraday-follow_redirects
116
+ requirement: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0.1'
121
+ - - "<"
122
+ - !ruby/object:Gem::Version
123
+ version: '0.4'
124
+ type: :runtime
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0.1'
131
+ - - "<"
132
+ - !ruby/object:Gem::Version
133
+ version: '0.4'
134
+ - !ruby/object:Gem::Dependency
135
+ name: multi_json
136
+ requirement: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - "~>"
139
+ - !ruby/object:Gem::Version
140
+ version: '1.15'
141
+ type: :runtime
142
+ prerelease: false
143
+ version_requirements: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: '1.15'
148
+ description: crawlyflower is a low-level wrapper around the WoRMS (World Register
149
+ of Marine Species) REST API.
150
+ email:
151
+ - gdower@illinois.edu
152
+ executables: []
153
+ extensions: []
154
+ extra_rdoc_files: []
155
+ files:
156
+ - ".github/workflows/main.yml"
157
+ - ".gitignore"
158
+ - CHANGELOG.md
159
+ - CODE_OF_CONDUCT.md
160
+ - Gemfile
161
+ - LICENSE.txt
162
+ - README.md
163
+ - Rakefile
164
+ - bin/console
165
+ - bin/setup
166
+ - crawlyflower.gemspec
167
+ - crawlyflower.png
168
+ - lib/crawlyflower.rb
169
+ - lib/crawlyflower/error.rb
170
+ - lib/crawlyflower/faraday.rb
171
+ - lib/crawlyflower/helpers/configuration.rb
172
+ - lib/crawlyflower/request.rb
173
+ - lib/crawlyflower/utils.rb
174
+ - lib/crawlyflower/version.rb
175
+ homepage: https://github.com/SpeciesFileGroup/crawlyflower
176
+ licenses:
177
+ - MIT
178
+ metadata:
179
+ homepage_uri: https://github.com/SpeciesFileGroup/crawlyflower
180
+ source_code_uri: https://github.com/SpeciesFileGroup/crawlyflower
181
+ changelog_uri: https://github.com/SpeciesFileGroup/crawlyflower/releases/tag/v0.0.1
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: 2.5.0
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubygems_version: 3.6.9
197
+ specification_version: 4
198
+ summary: WoRMS REST API Client
199
+ test_files: []