bananomia 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 48e0800c6a9ffdb8246a78a685a2117c23c8210f16e06c80ccae905a774897d6
4
+ data.tar.gz: 31f8e82c05f848423df644b365a923af0faa4f03b38e19dcffeafe0d5b680232
5
+ SHA512:
6
+ metadata.gz: '09faf121be5e1d1329bad96caac27976e768ee95c784d3ab185c35a84309be1282d3ff11f331de8e0f78b821c7f1bbe407a40eebe9af292e7bb56214b77035a7'
7
+ data.tar.gz: 8a1709dfed31dd27c2b83aad10bdfcc20c5ccc5ccd3689902904e66d5f7ca829ee385bc13ef2627c414610a5e3ac11347300b61ca38489c168d59d3d914b8944
@@ -0,0 +1,19 @@
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.1.3
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 }}
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .idea
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-01-20
4
+
5
+ - Initial release
@@ -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 bananomia.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bananomia (0.1.0)
5
+ faraday (~> 2.2)
6
+ faraday-follow_redirects (>= 0.1, < 0.4)
7
+ multi_json (~> 1.15)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.8.1)
13
+ public_suffix (>= 2.0.2, < 6.0)
14
+ byebug (11.1.3)
15
+ crack (0.4.5)
16
+ rexml
17
+ faraday (2.7.10)
18
+ faraday-net_http (>= 2.0, < 3.1)
19
+ ruby2_keywords (>= 0.0.4)
20
+ faraday-follow_redirects (0.3.0)
21
+ faraday (>= 1, < 3)
22
+ faraday-net_http (3.0.2)
23
+ hashdiff (1.0.1)
24
+ minitest (5.15.0)
25
+ multi_json (1.15.0)
26
+ power_assert (2.0.1)
27
+ public_suffix (5.0.1)
28
+ rake (13.0.6)
29
+ rexml (3.2.5)
30
+ ruby2_keywords (0.0.5)
31
+ test-unit (3.5.3)
32
+ power_assert
33
+ vcr (6.0.0)
34
+ webmock (3.18.1)
35
+ addressable (>= 2.8.0)
36
+ crack (>= 0.3.2)
37
+ hashdiff (>= 0.4.0, < 2.0.0)
38
+
39
+ PLATFORMS
40
+ x86_64-linux
41
+
42
+ DEPENDENCIES
43
+ bananomia!
44
+ bundler (~> 2.1, >= 2.1.4)
45
+ byebug
46
+ minitest (~> 5.0)
47
+ rake (~> 13.0)
48
+ test-unit (~> 3.3, >= 3.3.6)
49
+ vcr (~> 6.0)
50
+ webmock (~> 3.18)
51
+
52
+ BUNDLED WITH
53
+ 2.3.24
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright © 2023 Species File Group. All rights reserved.
2
+
3
+ Developed by: Species File Group
4
+ Illinois Natural History Survey
5
+ https://github.com/SpeciesFileGroup/bananomia
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal with 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:
8
+
9
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.
10
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution.
11
+ Neither the names of <Name of Development Group, Name of Institution>, nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission.
12
+
13
+ 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 CONTRIBUTORS 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 WITH THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,129 @@
1
+ # Bananomia
2
+
3
+ This is a Ruby wrapper on the [Bionomia](https://bionomia.net) API. Code follow 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).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bananomia'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bananomia
20
+
21
+ ## Usage
22
+
23
+
24
+ ---
25
+ ### Suggest Collector Names
26
+ Get collector name suggestions with a limit of 5:
27
+ ```ruby
28
+ Bananomia.suggest('Smith, Ja', limit: 5) # => MultiJson object
29
+ ```
30
+ Filter suggestions to only public profiles
31
+ ```ruby
32
+ Bananomia.suggest('Smith, Ja', is_public: true) # => MultiJson object
33
+ ```
34
+ Filter suggestions to only people that have occurrences associated with them:
35
+ ```ruby
36
+ Bananomia.suggest('Smith, Ja', has_occurrences: true) # => MultiJson object
37
+ ```
38
+
39
+ ---
40
+ ### Search Collectors
41
+ Search for a collector by name:
42
+ ```ruby
43
+ Bananomia.search_people('Thomas McElrath') # => MultiJson object
44
+ ```
45
+
46
+ Filter the people search by taxonomic families_collected or taxonomic families_identified. If strict is set to true, then matches must include the taxonomic families.
47
+ ```ruby
48
+ Bananomia.search_people('Thomas McElrath', families_collected: 'Monotomidae', strict: true) # => MultiJson object
49
+ ```
50
+ ```ruby
51
+ Bananomia.search_people('Thomas McElrath', families_identified: 'Monotomidae', strict: true) # => MultiJson object
52
+ ```
53
+
54
+ Filter the search by whether the person was living on the specimen collection/identification date. If strict is set to true, it requires that they were alive on the date.
55
+ ```ruby
56
+ Bananomia.search_people('Smith', date: '1580-01-02', strict: true) # => MultiJson object
57
+ ```
58
+
59
+ Setting the callback parameter returns [JSON-P](https://en.wikipedia.org/wiki/JSONP) wrapped in the provided callback string.
60
+ ```ruby
61
+ Bananomia.search_people('Smith', callback: 'myFunction') # => JSON-P object
62
+ ```
63
+
64
+ Use the page parameter for pagination of the search results:
65
+ ```ruby
66
+ Bananomia.search_people('Smith', page: 2) # => MultiJson object
67
+ ```
68
+
69
+ ---
70
+ ### Search Occurrences
71
+ Search for occurrences by [GBIF](https://gbif.org) [datasetID](https://www.gbif.org/dataset/f86a681d-7db8-483b-819a-248def18b70a) and [occurrenceID](https://www.gbif.org/occurrence/1804069383):
72
+ ```ruby
73
+ Bananomia.search_occurrences('f86a681d-7db8-483b-819a-248def18b70a', '7a1daa39-8d7c-d7c4-968f-799d58b3c7b0') # => MultiJson object
74
+ ```
75
+ Setting the callback parameter returns [JSON-P](https://en.wikipedia.org/wiki/JSONP) wrapped in the provided callback string.
76
+ ```ruby
77
+ Bananomia.search_occurrences('f86a681d-7db8-483b-819a-248def18b70a', '7a1daa39-8d7c-d7c4-968f-799d58b3c7b0', callback: 'myFunction') # => JSON-P object
78
+ ```
79
+
80
+ ---
81
+ ### Collectors
82
+ Get a person's profile by their [ORCID](https://orcid.org/) or [WikiData](https://wikidata.org) identifiers:
83
+ ```ruby
84
+ Bananomia.person('0000-0001-7618-5230') # => JSON-LD object
85
+ ```
86
+ ---
87
+ ### Specimens
88
+ Get a person's specimens by their [ORCID](https://orcid.org/) or [WikiData](https://wikidata.org) identifiers. Use the page parameter for pagination.
89
+ ```ruby
90
+ Bananomia.person('0000-0001-7618-5230', specimens: true) # => JSON-LD object
91
+ ```
92
+
93
+ ```ruby
94
+ Bananomia.person('0000-0001-7618-5230', specimens: true, csv: true) # => comma-separated values
95
+ ```
96
+ ---
97
+ ### Occurrences
98
+ Get an occurrence with a [GBIF](https://www.gbif.org/occurrence/search) occurrenceID:
99
+ ```ruby
100
+ Bananomia.occurrence('477976412') # => JSON-LD object
101
+ ```
102
+ ---
103
+ ### Parsing human names
104
+ **Note:** [Bionomia](https://bionomia.net) provides a RESTful API for the human name parsing [dwc_agent](https://rubygems.org/gems/dwc_agent) gem which uses the [namae](https://rubygems.org/gems/namae) gem, and you likely will get better performance using those gems directly if parsing a large number of human names.
105
+
106
+ Parse authorships with names separated by `;` and each authorship set separated by `\r\n`:
107
+ ```ruby
108
+ Bananomia.parse(names: 'Henry Robert Nicollon des Abbayes; Groom Q\r\nMrs. John Errol Chandos Aberdeen') # => MultiJson object
109
+ ```
110
+
111
+ ---
112
+
113
+ ## Development
114
+
115
+ 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.
116
+
117
+ 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`, 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](https://rubygems.org).
118
+
119
+ ## Contributing
120
+
121
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SpeciesFileGroup/bananomia. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/SpeciesFileGroup/bananomia/blob/main/CODE_OF_CONDUCT.md).
122
+
123
+ ## License
124
+
125
+ The gem is available as open source under the terms of the [NCSA/Illinois](https://github.com/SpeciesFileGroup/bananomia/blob/main/LICENSE.txt) license. You can learn more about the NCSA license on [Wikipedia](https://en.wikipedia.org/wiki/University_of_Illinois/NCSA_Open_Source_License) and compare it with other open source licenses at the [Open Source Initiative](https://opensource.org/license/uoi-ncsa-php/).
126
+
127
+ ## Code of Conduct
128
+
129
+ Everyone interacting in the Bananomia project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/SpeciesFileGroup/bananomia/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/bananomia.gemspec ADDED
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/bananomia/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "bananomia"
7
+ s.version = Bananomia::VERSION
8
+ s.authors = ["Geoff Ower, Matt Yoder"]
9
+ s.email = ["gdower@illinois.edu"]
10
+
11
+ s.summary = "Bionomia Client"
12
+ s.description = "Bananomia is a low-level wrapper around the Bionomia API."
13
+ s.homepage = "https://github.com/SpeciesFileGroup/bananomia"
14
+ s.license = "NCSA"
15
+ s.required_ruby_version = ">= 2.4.0"
16
+
17
+ # s.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
18
+
19
+ s.metadata["homepage_uri"] = s.homepage
20
+ s.metadata["source_code_uri"] = "https://github.com/SpeciesFileGroup/bananomia"
21
+ s.metadata["changelog_uri"] = "https://github.com/SpeciesFileGroup/bananomia/releases/tag/v#{s.version}"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ s.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|s|features)/}) }
27
+ end
28
+ s.bindir = "exe"
29
+ s.executables = s.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ s.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # s.add_dependency "example-gem", "~> 1.0"
34
+
35
+ s.add_development_dependency "bundler", "~> 2.1", ">= 2.1.4"
36
+ # s.add_development_dependency "codecov", "~> 0.5.0"
37
+ # s.add_development_dependency "json", "~> 2.3", ">= 2.3.1"
38
+ s.add_development_dependency "rake", "~> 13.0", ">= 13.0.1"
39
+ # s.add_development_dependency "standard", "~> 1.0"
40
+ # s.add_development_dependency "simplecov", "~> 0.21.2"
41
+ s.add_development_dependency "test-unit", "~> 3.3", ">= 3.3.6"
42
+ s.add_development_dependency "vcr", "~> 6.0"
43
+ s.add_development_dependency "webmock", "~> 3.18"
44
+
45
+ s.add_runtime_dependency "faraday", "~> 2.2"
46
+ s.add_runtime_dependency "faraday-follow_redirects", ">= 0.1", "< 0.4"
47
+ s.add_runtime_dependency "multi_json", "~> 1.15"
48
+
49
+ # TODO: comment out
50
+ s.add_development_dependency "byebug"
51
+
52
+ # s.add_runtime_dependency "thor", "~> 1.0", ">= 1.0.1"
53
+
54
+ # For more information and examples about making a new gem, checkout our
55
+ # guide at: https://bundler.io/guides/creating_gem.html
56
+ end
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 "bananomia"
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,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bananomia
4
+ # Custom error class for rescuing from all Bananomia errors
5
+ class Error < StandardError; end
6
+
7
+ # Raised when Bionomia returns the HTTP status code 400
8
+ class BadRequest < Error; end
9
+
10
+ # Raised when Bionomia returns the HTTP status code 404
11
+ class NotFound < Error; end
12
+
13
+ # Raised when Bionomia returns the HTTP status code 500
14
+ class InternalServerError < Error; end
15
+
16
+ # Raised when Bionomia returns the HTTP status code 502
17
+ class BadGateway < Error; end
18
+
19
+ # Raised when Bionomia returns the HTTP status code 503
20
+ class ServiceUnavailable < Error; end
21
+
22
+ # Raised when Bionomia returns the HTTP status code 504
23
+ class GatewayTimeout < Error; end
24
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "multi_json"
5
+
6
+ # @private
7
+ module Faraday
8
+ module ColrapiErrors
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 Bananomia::BadRequest, error_message_400(response)
16
+ when 404
17
+ raise Bananomia::NotFound, error_message_400(response)
18
+ when 500
19
+ raise Bananomia::InternalServerError, error_message_500(response, "Something is technically wrong.")
20
+ when 502
21
+ raise Bananomia::BadGateway, error_message_500(response, "The server returned an invalid or incomplete response.")
22
+ when 503
23
+ raise Bananomia::ServiceUnavailable, error_message_500(response, "Crossref is rate limiting your requests.")
24
+ when 504
25
+ raise Bananomia::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
73
+
@@ -0,0 +1,26 @@
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
26
+
@@ -0,0 +1,82 @@
1
+ require_relative "faraday" # !! Potential ruby 3.0 difference in module loading? relative differs from Serrano
2
+ require "faraday/follow_redirects"
3
+ require_relative "utils"
4
+
5
+ module Bananomia
6
+
7
+ class Request
8
+ attr_accessor :endpoint
9
+ attr_accessor :q
10
+ attr_accessor :verbose
11
+
12
+ attr_accessor :options
13
+
14
+ def initialize(**args)
15
+ @endpoint = args[:endpoint]
16
+ @verbose = args[:verbose]
17
+ @q = args[:q]
18
+ @families_collected = args[:families_collected]
19
+ @families_identified = args[:families_identified]
20
+ @date = args[:date]
21
+ @strict = args[:strict]
22
+ @callback = args[:callback]
23
+ @is_public = args[:is_public]
24
+ @has_occurrences = args[:has_occurrences]
25
+ @dataset_id = args[:dataset_id]
26
+ @occurrence_id = args[:occurrence_id]
27
+ @names = args[:names]&.gsub('\n', "\n")&.gsub('\r', "\r")
28
+ @limit = args[:limit]
29
+ @page = args[:page]
30
+ @options = args[:options] # TODO: not added at bananomia.rb
31
+ end
32
+
33
+ def perform
34
+
35
+ args = {
36
+ q: @q,
37
+ families_collected: @families_collected,
38
+ families_identified: @families_identified,
39
+ date: @date,
40
+ strict: @strict,
41
+ callback: @callback,
42
+ names: @names,
43
+ is_public: @is_public,
44
+ has_occurrences: @has_occurrences,
45
+ datasetKey: @dataset_id,
46
+ occurrenceID: @occurrence_id,
47
+ limit: @limit,
48
+ page: @page
49
+ }
50
+ opts = args.delete_if { |_k, v| v.nil? }
51
+
52
+ Faraday::Utils.default_space_encoding = "+"
53
+
54
+ conn = if verbose
55
+ Faraday.new(url: Bananomia.base_url) do |f|
56
+ f.response :logger
57
+ f.use Faraday::ColrapiErrors::Middleware
58
+ f.adapter Faraday.default_adapter
59
+ end
60
+ else
61
+ Faraday.new(url: Bananomia.base_url) do |f|
62
+ f.use Faraday::ColrapiErrors::Middleware
63
+ f.adapter Faraday.default_adapter
64
+ end
65
+ end
66
+
67
+ conn.headers['Accept'] = 'application/ld+json,*/*'
68
+ conn.headers[:user_agent] = make_user_agent
69
+ conn.headers["X-USER-AGENT"] = make_user_agent
70
+
71
+ res = conn.get(endpoint, opts)
72
+
73
+ # Handles ChecklistBank endpoints that do not return JSON
74
+ begin
75
+ MultiJson.load(res.body)
76
+ rescue MultiJson::ParseError
77
+ res.body
78
+ end
79
+
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,38 @@
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 = "Bananomia/v" + Bananomia::VERSION
8
+ ua = requa + " " + habua
9
+ if Bananomia.mailto
10
+ ua += " (mailto:%s)" % Bananomia.mailto
11
+ end
12
+ # ua += format(' (mailto:%s)', Bananomia.mailto) if Bananomia.mailto
13
+ ua
14
+ end
15
+
16
+ def field_query_handler(x)
17
+ tmp = x.keep_if { |z| z.match(/query_/) }
18
+ rename_query_filters(tmp)
19
+ end
20
+
21
+ def rename_query_filters(foo)
22
+ foo = foo.tostrings
23
+ foo = foo.map { |x, y| [x.to_s.sub("container_title", "container-title"), y] }.to_h
24
+ foo.map { |x, y| [x.to_s.sub("query_", "query."), y] }.to_h
25
+ end
26
+
27
+ class Hash
28
+ def tostrings
29
+ map { |(k, v)| [k.to_s, v] }.to_h
30
+ end
31
+ end
32
+
33
+ class Hash
34
+ def tosymbols
35
+ map { |(k, v)| [k.to_sym, v] }.to_h
36
+ end
37
+ end
38
+
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bananomia
4
+ VERSION = "0.1.0"
5
+ end
data/lib/bananomia.rb ADDED
@@ -0,0 +1,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+ require_relative "bananomia/error"
5
+ require_relative "bananomia/version"
6
+ require_relative "bananomia/request"
7
+ require "bananomia/helpers/configuration"
8
+
9
+ module Bananomia
10
+ extend Configuration
11
+
12
+ define_setting :base_url, "https://api.bionomia.net/"
13
+ define_setting :mailto, ENV["BIONOMIA_API_EMAIL"]
14
+
15
+ # Parse human names
16
+ #
17
+ # @param names [String] Human name(s) separated by \r\n
18
+ #
19
+ # @param verbose [Boolean] Print headers to STDOUT
20
+ #
21
+ # @return [Array, Boolean] An array of hashes
22
+ def self.parse(names, verbose: false)
23
+ endpoint = "parse"
24
+ Request.new(
25
+ endpoint: endpoint,
26
+ names: names,
27
+ verbose: verbose
28
+ ).perform
29
+ end
30
+
31
+ # Get a person's profile by ID or specimens
32
+ # @param id [String] An ORCID or WikiData identifier
33
+ # @param specimens [Boolean, nil] Get the person's specimens
34
+ # @param csv [Boolean, nil] For specimens, whether to return a csv
35
+ #
36
+ # @param page [Integer, nil] Pagination for the results list
37
+ # @param verbose [Boolean] Print headers to STDOUT
38
+ #
39
+ # @return [Hash, String, Boolean] A JSON-LD hash or CSV
40
+ def self.person(id, csv: nil, specimens: nil, page: nil, verbose: false)
41
+ if csv and specimens
42
+ extension = '.csv'
43
+ else
44
+ extension = '.jsonld'
45
+ end
46
+
47
+ if specimens
48
+ endpoint = "#{id}/specimens#{extension}"
49
+ else
50
+ endpoint = "#{id}#{extension}"
51
+ end
52
+ Request.new(endpoint: endpoint, page: page, verbose: verbose).perform
53
+ end
54
+
55
+ # Get and occurrence record
56
+ # @param id [String] An occurence ID from Global Biodiversity Information Facility
57
+ #
58
+ # @param verbose [Boolean] Print headers to STDOUT
59
+ #
60
+ # @return [Hash, Boolean] A JSON-LD hash
61
+ def self.occurrence(id, verbose: false)
62
+ endpoint = "occurrence/#{id}.jsonld"
63
+ Request.new(endpoint: endpoint, verbose: verbose).perform
64
+ end
65
+
66
+ # Search human names
67
+ # @param q [String] A single human name
68
+ # @param families_collected [Boolean, nil] Comma-separated list of taxonomic families collected
69
+ # @param families_identified [Boolean, nil] Comma-separated list of taxonomic families identified
70
+ # @param date [String, nil] Filters to alive during date (format: YYYY-MM-DD, YYYY-MM, or YYYY)
71
+ # e.g., Captain John Smith was alive from 1580-01-01 through 1631-06-21, so setting date to any value between
72
+ # their birth/death date will include Captain John in the search results
73
+ # Warning: Setting exactly equal to a person's birthdate, excludes them from search!
74
+ # @param strict [Boolean, nil] Must include vs should include on families_identified, families_collected, date
75
+ # @param callback [String, nil] A string to produce a JSONP response instead of a JSON-LD response
76
+ #
77
+ # @param page [Integer, nil] Pagination for the results list
78
+ # @param verbose [Boolean] Print headers to STDOUT
79
+ #
80
+ # @return [Array, Boolean] An array of hashes
81
+ def self.search_people(q, families_collected: nil, families_identified: nil, date: nil, page: nil,
82
+ strict: nil, callback: nil, verbose: false)
83
+ endpoint = 'users/search'
84
+ Request.new(
85
+ endpoint: endpoint,
86
+ q: q,
87
+ families_collected: families_collected,
88
+ families_identified: families_identified,
89
+ date: date,
90
+ page: page,
91
+ strict: strict,
92
+ callback: callback,
93
+ verbose: verbose
94
+ ).perform
95
+ end
96
+
97
+ # Search occurrences
98
+ # @param dataset_id [String] a registered dataset UUID provided by the Global Biodiversity Information Facility
99
+ # @param occurrence_id [String] identifier from the data provider
100
+ # @param callback [String, nil] A string to produce a JSONP response instead of a JSON-LD response
101
+ #
102
+ # @param page [Integer, nil] Pagination for the results list
103
+ # @param verbose [Boolean] Print headers to STDOUT
104
+ #
105
+ # @return [Array, Boolean] An array of hashes
106
+ def self.search_occurrences(dataset_id, occurrence_id, callback: nil, verbose: false)
107
+ endpoint = 'occurrences/search'
108
+ Request.new(
109
+ endpoint: endpoint,
110
+ dataset_id: dataset_id,
111
+ occurrence_id: occurrence_id,
112
+ callback: callback,
113
+ verbose: verbose
114
+ ).perform
115
+ end
116
+
117
+ # Suggest human names (autocomplete widget)
118
+ # @param q [String] Part of a human name
119
+ # @param is_public [Boolean, nil] Filters results to public profiles
120
+ # @param has_occurrences [Boolean, nil] Filters results to profiles with occurrences
121
+ #
122
+ # @param limit [Integer, nil] The number of results to return
123
+ # @param verbose [Boolean] Print headers to STDOUT
124
+ #
125
+ # @return [Array, Boolean] An array of hashes
126
+ def self.suggest(q, is_public: nil, has_occurrences: nil, limit: nil, verbose: false)
127
+ endpoint = 'user.json'
128
+ Request.new(
129
+ endpoint: endpoint,
130
+ q: q,
131
+ is_public: is_public,
132
+ has_occurrences: has_occurrences,
133
+ limit: limit,
134
+ verbose: verbose
135
+ ).perform
136
+ end
137
+ end
metadata ADDED
@@ -0,0 +1,215 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bananomia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Geoff Ower, Matt Yoder
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-08-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.1.4
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.1.4
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '13.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 13.0.1
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '13.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 13.0.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: test-unit
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.3'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.3.6
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.3'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.3.6
73
+ - !ruby/object:Gem::Dependency
74
+ name: vcr
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '6.0'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '6.0'
87
+ - !ruby/object:Gem::Dependency
88
+ name: webmock
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '3.18'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '3.18'
101
+ - !ruby/object:Gem::Dependency
102
+ name: faraday
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '2.2'
108
+ type: :runtime
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: '2.2'
115
+ - !ruby/object:Gem::Dependency
116
+ name: faraday-follow_redirects
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0.1'
122
+ - - "<"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.4'
125
+ type: :runtime
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0.1'
132
+ - - "<"
133
+ - !ruby/object:Gem::Version
134
+ version: '0.4'
135
+ - !ruby/object:Gem::Dependency
136
+ name: multi_json
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: '1.15'
142
+ type: :runtime
143
+ prerelease: false
144
+ version_requirements: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - "~>"
147
+ - !ruby/object:Gem::Version
148
+ version: '1.15'
149
+ - !ruby/object:Gem::Dependency
150
+ name: byebug
151
+ requirement: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ type: :development
157
+ prerelease: false
158
+ version_requirements: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ description: Bananomia is a low-level wrapper around the Bionomia API.
164
+ email:
165
+ - gdower@illinois.edu
166
+ executables: []
167
+ extensions: []
168
+ extra_rdoc_files: []
169
+ files:
170
+ - ".github/workflows/main.yml"
171
+ - ".gitignore"
172
+ - CHANGELOG.md
173
+ - CODE_OF_CONDUCT.md
174
+ - Gemfile
175
+ - Gemfile.lock
176
+ - LICENSE.txt
177
+ - README.md
178
+ - Rakefile
179
+ - bananomia.gemspec
180
+ - bin/console
181
+ - bin/setup
182
+ - lib/bananomia.rb
183
+ - lib/bananomia/error.rb
184
+ - lib/bananomia/faraday.rb
185
+ - lib/bananomia/helpers/configuration.rb
186
+ - lib/bananomia/request.rb
187
+ - lib/bananomia/utils.rb
188
+ - lib/bananomia/version.rb
189
+ homepage: https://github.com/SpeciesFileGroup/bananomia
190
+ licenses:
191
+ - NCSA
192
+ metadata:
193
+ homepage_uri: https://github.com/SpeciesFileGroup/bananomia
194
+ source_code_uri: https://github.com/SpeciesFileGroup/bananomia
195
+ changelog_uri: https://github.com/SpeciesFileGroup/bananomia/releases/tag/v0.1.0
196
+ post_install_message:
197
+ rdoc_options: []
198
+ require_paths:
199
+ - lib
200
+ required_ruby_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: 2.4.0
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ requirements: []
211
+ rubygems_version: 3.4.10
212
+ signing_key:
213
+ specification_version: 4
214
+ summary: Bionomia Client
215
+ test_files: []