colrapi 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: 45d0b45d7d61f0ef91fda1d02f2f90eef26296a0f9dde8621637a03d3616469e
4
+ data.tar.gz: ba27842e25d7727443e69481e03b75af7649dd53d917136cbd1b6883a4b8cd4f
5
+ SHA512:
6
+ metadata.gz: 24197d4e95bb99ed80189ce7263781ec212c04b733cb98f188b496a78f1ec42ca3cdf14e3cd73e64acdd520e89047c9502785beaf5f53582b2cbed7740af0747
7
+ data.tar.gz: c80b544c93a171ba2f768468a262175dcae973df961e88e0d28639596d876c3237e714af3e1b8b530c009a3932b7c8f5698991009ecb2dde93e794cae29acbab
@@ -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,10 @@
1
+ .byebug_history
2
+ .idea
3
+ /.bundle/
4
+ /.yardoc
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /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,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in colrapi.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem 'rubyzip'
data/Gemfile.lock ADDED
@@ -0,0 +1,75 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ colrapi (0.1.0)
5
+ faraday (~> 1.0)
6
+ faraday_middleware (~> 1.2)
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 (1.9.3)
18
+ faraday-em_http (~> 1.0)
19
+ faraday-em_synchrony (~> 1.0)
20
+ faraday-excon (~> 1.1)
21
+ faraday-httpclient (~> 1.0)
22
+ faraday-multipart (~> 1.0)
23
+ faraday-net_http (~> 1.0)
24
+ faraday-net_http_persistent (~> 1.0)
25
+ faraday-patron (~> 1.0)
26
+ faraday-rack (~> 1.0)
27
+ faraday-retry (~> 1.0)
28
+ ruby2_keywords (>= 0.0.4)
29
+ faraday-em_http (1.0.0)
30
+ faraday-em_synchrony (1.0.0)
31
+ faraday-excon (1.1.0)
32
+ faraday-httpclient (1.0.1)
33
+ faraday-multipart (1.0.3)
34
+ multipart-post (>= 1.2, < 3)
35
+ faraday-net_http (1.0.1)
36
+ faraday-net_http_persistent (1.2.0)
37
+ faraday-patron (1.0.0)
38
+ faraday-rack (1.0.0)
39
+ faraday-retry (1.0.3)
40
+ faraday_middleware (1.2.0)
41
+ faraday (~> 1.0)
42
+ hashdiff (1.0.1)
43
+ minitest (5.15.0)
44
+ multi_json (1.15.0)
45
+ multipart-post (2.1.1)
46
+ power_assert (2.0.1)
47
+ public_suffix (5.0.1)
48
+ rake (13.0.6)
49
+ rexml (3.2.5)
50
+ ruby2_keywords (0.0.5)
51
+ rubyzip (2.3.2)
52
+ test-unit (3.5.3)
53
+ power_assert
54
+ vcr (6.0.0)
55
+ webmock (3.18.1)
56
+ addressable (>= 2.8.0)
57
+ crack (>= 0.3.2)
58
+ hashdiff (>= 0.4.0, < 2.0.0)
59
+
60
+ PLATFORMS
61
+ x86_64-linux
62
+
63
+ DEPENDENCIES
64
+ bundler (~> 2.1, >= 2.1.4)
65
+ byebug
66
+ colrapi!
67
+ minitest (~> 5.0)
68
+ rake (~> 13.0)
69
+ rubyzip
70
+ test-unit (~> 3.3, >= 3.3.6)
71
+ vcr (~> 6.0)
72
+ webmock (~> 3.18)
73
+
74
+ BUNDLED WITH
75
+ 2.3.24
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 mjy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # colrapi
2
+
3
+ This is a wrapper on the Catalogue of Life 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 'colrapi'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install colrapi
20
+
21
+ ## Usage
22
+
23
+ In development, this is it for now:
24
+ ```ruby
25
+ res = Colrapi.nameusage(q: 'Homo sapiens') # => MultiJson object
26
+ ```
27
+
28
+ ## Development
29
+
30
+ 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.
31
+
32
+ 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).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mjy/colrapi. 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/species_file_group/colrapi/blob/main/CODE_OF_CONDUCT.md).
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [NCSA/Illinois](https://opensource.org/licenses/NCSA).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Colrapi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/species_file_group/colrapi/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 "colrapi"
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
data/colrapi.gemspec ADDED
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/colrapi/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "colrapi"
7
+ s.version = Colrapi::VERSION
8
+ s.authors = ["Matt Yoder, Geoff Ower"]
9
+ s.email = ["diapriid@gmail.com"]
10
+
11
+ s.summary = "Catalog of Life Client"
12
+ s.description = "colrapi (a play on Kholrabi) is a low-level wrapper around the Catalog of Life API."
13
+ s.homepage = "https://github.com/SpeciesFileGroup/colrapi"
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/colrapi"
21
+ s.metadata["changelog_uri"] = "https://github.com/SpeciesFileGroup/colrapi/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", "~> 1.0"
46
+ s.add_runtime_dependency "faraday_middleware", "~> 1.2" # requires 1.0
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
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday_middleware"
5
+ require "multi_json"
6
+
7
+ # @private
8
+ module FaradayMiddleware
9
+ # @private
10
+ class RaiseHttpException < 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 Colrapi::BadRequest, error_message_400(response)
16
+ when 404
17
+ raise Colrapi::NotFound, error_message_400(response)
18
+ when 500
19
+ raise Colrapi::InternalServerError, error_message_500(response, "Something is technically wrong.")
20
+ when 502
21
+ raise Colrapi::BadGateway, error_message_500(response, "The server returned an invalid or incomplete response.")
22
+ when 503
23
+ raise Colrapi::ServiceUnavailable, error_message_500(response, "Crossref is rate limiting your requests.")
24
+ when 504
25
+ raise Colrapi::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
+ elseif body["message"].length == 1
48
+ body = body["message"]
49
+ else
50
+ body = body["message"].collect { |x| x["message"] }.join("; ")
51
+ end
52
+ end
53
+ end
54
+
55
+ if body.nil?
56
+ nil
57
+ else
58
+ ": #{body}"
59
+ end
60
+ end
61
+
62
+ def error_message_500(response, body = nil)
63
+ "#{response[:method].to_s.upcase} #{response[:url]}: #{[response[:status].to_s + ":", body].compact.join(" ")}"
64
+ end
65
+
66
+ def json?(string)
67
+ MultiJson.load(string)
68
+ true
69
+ rescue MultiJson::ParseError
70
+ false
71
+ end
72
+ end
73
+ end
74
+
@@ -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,169 @@
1
+ require_relative "faraday" # !! Potential ruby 3.0 difference in module loading? relative differs from Serrano
2
+ require "faraday_middleware"
3
+ require_relative "utils"
4
+
5
+ module Colrapi
6
+ class Request
7
+ attr_accessor :endpoint
8
+ attr_accessor :q
9
+ attr_accessor :verbose
10
+
11
+ attr_accessor :options
12
+
13
+ def initialize(**args)
14
+ @endpoint = args[:endpoint]
15
+ @verbose = args[:verbose]
16
+ @url = args[:url]
17
+ @q = Array(args[:q]) if args[:q]
18
+ @id = args[:id]
19
+ @format = args[:format]
20
+ @regexp = args[:regexp]
21
+ @content = Array(args[:content]) if args[:content]
22
+ @name = args[:name]
23
+ @authorship = args[:authorship]
24
+ @code = args[:code]
25
+ @type = Array(args[:type]) if args[:type]
26
+ @rank = Array(args[:rank]) if args[:rank]
27
+ @facet = Array(args[:facet]) if args[:facet]
28
+ @min_rank = args[:min_rank]
29
+ @max_rank = args[:max_rank]
30
+ @parent_rank = args[:parent_rank]
31
+ @root_id = Array(args[:root_id]) if args[:root_id]
32
+ @root2_id = Array(args[:root2_id]) if args[:root2_id]
33
+ @include_parent = args[:include_parent]
34
+ @include_synonyms = args[:include_synonyms]
35
+ @dataset_id_filter = args[:dataset_id_filter]
36
+ @project_id = args[:project_id]
37
+ @short_title = args[:short_title]
38
+ @private = args[:private]
39
+ @released_from = args[:released_from]
40
+ @contributes_to = args[:contributes_to]
41
+ @has_source_dataset = args[:has_source_dataset]
42
+ @has_gbif_id = args[:has_gbif_id]
43
+ @gbif_id = args[:gbif_id]
44
+ @gbif_publisher_id = args[:gbif_publisher_id]
45
+ @editor = args[:editor]
46
+ @reviewer = args[:reviewer]
47
+ @modified_by = args[:modified_by]
48
+ @origin = Array(args[:origin]) if args[:origin]
49
+ @original = args[:original]
50
+ @not_current_only = args[:not_current_only]
51
+ @license = Array(args[:license]) if args[:license]
52
+ @row_type = Array(args[:row_type]) if args[:row_type]
53
+ @created_after = args[:created_after]
54
+ @created_before = args[:created_before]
55
+ @issue = Array(args[:issue]) if args[:issue]
56
+ @term = Array(args[:term]) if args[:term]
57
+ @term_operator = args[:term_operator]
58
+ @issued = args[:issued]
59
+ @issued_before = args[:issued]
60
+ @modified_after = args[:modified_after]
61
+ @modified_before = args[:modified_before]
62
+ @last_synced_before = args[:last_synced_before]
63
+ @min = args[:min]
64
+ @max = args[:max]
65
+ @min_size = args[:min_size]
66
+ @size = args[:size]
67
+ @within_superkingdom = args[:within_superkingdom]
68
+ @within_kingdom = args[:within_kingdom]
69
+ @within_subkingdom = args[:within_subkingdom]
70
+ @within_superphylum = args[:within_superphylum]
71
+ @within_phylum = args[:within_phylum]
72
+ @within_subphylum = args[:within_subphylum]
73
+ @within_superclass = args[:within_superclass]
74
+ @within_class = args[:within_class]
75
+ @within_subclass = args[:within_subclass]
76
+ @within_superorder = args[:within_superorder]
77
+ @within_order = args[:within_order]
78
+ @within_suborder = args[:within_suborder]
79
+ @within_superfamily = args[:within_superfamily]
80
+ @within_family = args[:within_family]
81
+ @within_subfamily = args[:within_subfamily]
82
+ @within_tribe = args[:within_tribe]
83
+ @within_subtribe = args[:within_subtribe]
84
+ @within_genus = args[:within_genus]
85
+ @within_subgenus = args[:within_subgenus]
86
+ @within_section = args[:within_section]
87
+ @within_species = args[:within_species]
88
+ @without_data = args[:without_data]
89
+ @broken = args[:broken]
90
+ @subject_dataset_id = args[:subject_dataset_id]
91
+ @mode = args[:mode]
92
+ @decision_mode = args[:decision_mode]
93
+ @subject = args[:subject]
94
+ @nidx_id = args[:nidx_id]
95
+ @sort_by = args[:sort_by]
96
+ @reverse = args[:reverse]
97
+ @limit = args[:limit]
98
+ @offset = args[:offset]
99
+ @status = args[:status]
100
+ @state = Array(args[:state]) if args[:state]
101
+ @running = args[:running]
102
+ @user = args[:user]
103
+ @password = args[:password]
104
+ @token = args[:token]
105
+ @options = args[:options] # TODO: not added at colrapi.rb
106
+ end
107
+
108
+ def perform
109
+
110
+ args = { q: @q, regex: @regexp, content: @content, name: @name, authorship: @authorship, code: @code, type: @type,
111
+ rank: @rank, minRank: @min_rank, maxRank: @max_rank, parentRank: @parent_rank, projectKey: @project_id,
112
+ term: @term, termOp: @term_operator, status: @status, decisionMode: @decision_mode,
113
+ alias: @short_title, private: @private, releasedFrom: @released_from, contributesTo: @contributes_to,
114
+ hasSourceDataset: @has_source_dataset, hasGbifKey: @has_gbif_id, gbifKey: @gbif_id,
115
+ gbifPublisherKey: @gbif_publisher_id, editor: @editor, reviewer: @reviewer, modifiedBy: @modified_by,
116
+ id: @id, format: @format, root: @root_id, root2: @root2_id, synonyms: @include_synonyms,
117
+ showParent: @include_parent, origin: @origin, original: @original, license: @license, rowType: @row_type,
118
+ created: @created_after, createdBefore: @created_before, issued: @issued, issuedBefore: @issued_before,
119
+ modified: @modified_after, modifiedBefore: @modified_before, lastSync: @last_synced_before,
120
+ minSize: @min_size, size: @size, issue: @issue, min: @min, max: @max, datasetKey: @dataset_id_filter,
121
+ withoutData: @without_data, superkingdom: @within_superkingdom, kingdom: @within_kingdom,
122
+ subkingdom: @within_subkingdom, superphylum: @within_superphylum, phylum: @within_phylum,
123
+ subphylum: @within_subphylum, superclass: @within_superclass, class: @within_class,
124
+ subclass: @within_subclass, superorder: @within_superorder, order: @within_order,
125
+ suborder: @within_suborder, superfamily: @within_superfamily,
126
+ family: @within_family, subfamily: @within_subfamily,
127
+ tribe: @within_tribe, subtribe: @within_subtribe, genus: @within_genus,
128
+ subgenus: @within_subgenus, section: @within_section, species: @within_species,
129
+ nidx: @nidx_id, state: @state, running: @running, notCurrentOnly: @not_current_only,
130
+ broken: @broken, subjectDatasetKey: @subject_dataset_id, mode: @mode, subject: @subject,
131
+ sortBy: @sort_by, reverse: @reverse, url: @url, offset: @offset, limit: @limit}
132
+ opts = args.delete_if { |_k, v| v.nil? }
133
+
134
+ conn = if verbose
135
+ Faraday.new(url: Colrapi.base_url, request: { params_encoder: Faraday::FlatParamsEncoder }) do |f|
136
+ if !@user.nil? and !@password.nil?
137
+ f.request(:basic_auth, @user, @password)
138
+ end
139
+ f.response :logger
140
+ f.use FaradayMiddleware::RaiseHttpException
141
+ f.adapter Faraday.default_adapter
142
+ end
143
+ else
144
+ Faraday.new(url: Colrapi.base_url, request: { params_encoder: Faraday::FlatParamsEncoder }) do |f|
145
+ if !@user.nil? and !@password.nil?
146
+ f.request(:basic_auth, @user, @password)
147
+ end
148
+ f.use FaradayMiddleware::RaiseHttpException
149
+ f.adapter Faraday.default_adapter
150
+ end
151
+ end
152
+
153
+ conn.headers['Authorization'] = "Bearer #{@token}" unless @token.nil?
154
+ conn.headers['Accept'] = 'application/json,*/*'
155
+ conn.headers[:user_agent] = make_user_agent
156
+ conn.headers["X-USER-AGENT"] = make_user_agent
157
+
158
+ res = conn.get endpoint, opts
159
+
160
+ # Handles ChecklistBank endpoints that do not return JSON
161
+ begin
162
+ MultiJson.load(res.body)
163
+ rescue MultiJson::ParseError
164
+ res.body
165
+ end
166
+
167
+ end
168
+ end
169
+ end