bell_pepper 0.1.1

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: c7fa62bf46671a9dfc4d074fe51d6f59a731133410536031d486553de0bf390f
4
+ data.tar.gz: 0fad9b30019bbb243766060f2b5a7adc4803978a73fb46279e9898a060e40258
5
+ SHA512:
6
+ metadata.gz: 00c1a9f73ae73d5573346a9b546e187df2a1387c0971e6e7973f9d0f458f65d131f30586ebf101ff7e6b919440cbca642073f1cbb506ab6d1b7fb521e9e867fe
7
+ data.tar.gz: 95a418638adfff071951c1c116cc6642b3333101238d43b976becce411ff9d8e8921bb4525522ff16d5eeea98476a19a1abef7d928ed0a15be1179f53b843d25
@@ -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,11 @@
1
+ .byebug_history
2
+ .idea
3
+ /.bundle/
4
+ /.yardoc
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.gem
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.1] - 2023-04-17
4
+ - Updated Faraday version
5
+
6
+ ## [0.1.0] - 2022-01-20
7
+
8
+ - 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 bell_pepper.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,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bell_pepper (0.1.1)
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.4)
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
+ rubyzip (2.3.2)
32
+ test-unit (3.5.3)
33
+ power_assert
34
+ vcr (6.0.0)
35
+ webmock (3.18.1)
36
+ addressable (>= 2.8.0)
37
+ crack (>= 0.3.2)
38
+ hashdiff (>= 0.4.0, < 2.0.0)
39
+
40
+ PLATFORMS
41
+ x86_64-linux
42
+
43
+ DEPENDENCIES
44
+ bell_pepper!
45
+ bundler (~> 2.1, >= 2.1.4)
46
+ byebug
47
+ minitest (~> 5.0)
48
+ rake (~> 13.0)
49
+ rubyzip
50
+ test-unit (~> 3.3, >= 3.3.6)
51
+ vcr (~> 6.0)
52
+ webmock (~> 3.18)
53
+
54
+ BUNDLED WITH
55
+ 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,43 @@
1
+ # BellPepper
2
+
3
+ This is a wrapper on the [Biodiversity Enhanced Location Services (BELS) Georeference API](https://github.com/VertNet/bels). 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 'bell_pepper'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bell_pepper
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ res = BellPepper.bestgeoref(id: "1", locality: "Meadowbrook Park", city: "Urbana", state_province: "Illinois", country_code: "US") # => MultiJson object
25
+ ```
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SpeciesFileGroup/bell_pepper. 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/bell_pepper/blob/main/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [NCSA/Illinois](https://opensource.org/licenses/NCSA).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the BellPepper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/SpeciesFileGroup/bell_pepper/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
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/bell_pepper/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "bell_pepper"
7
+ s.version = BellPepper::VERSION
8
+ s.authors = ["Geoff Ower"]
9
+ s.email = ["gdower@illinois.edu"]
10
+
11
+ s.summary = "Biodiversity Enhanced Location Services (BELS) Georeference Client"
12
+ s.description = "bell_pepper is a low-level wrapper around the BELS API."
13
+ s.homepage = "https://github.com/SpeciesFileGroup/bell_pepper"
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/bell_pepper"
21
+ s.metadata["changelog_uri"] = "https://github.com/SpeciesFileGroup/bell_pepper/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 "bell_pepper"
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 BellPepper
4
+ # Custom error class for rescuing from all BellPepper errors
5
+ class Error < StandardError; end
6
+
7
+ # Raised when ChecklistBank returns the HTTP status code 400
8
+ class BadRequest < Error; end
9
+
10
+ # Raised when ChecklistBank returns the HTTP status code 404
11
+ class NotFound < Error; end
12
+
13
+ # Raised when ChecklistBank returns the HTTP status code 500
14
+ class InternalServerError < Error; end
15
+
16
+ # Raised when ChecklistBank returns the HTTP status code 502
17
+ class BadGateway < Error; end
18
+
19
+ # Raised when ChecklistBank returns the HTTP status code 503
20
+ class ServiceUnavailable < Error; end
21
+
22
+ # Raised when ChecklistBank 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 BellPepperErrors
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 BellPepper::BadRequest, error_message_400(response)
16
+ when 404
17
+ raise BellPepper::NotFound, error_message_400(response)
18
+ when 500
19
+ raise BellPepper::InternalServerError, error_message_500(response, "Something is technically wrong.")
20
+ when 502
21
+ raise BellPepper::BadGateway, error_message_500(response, "The server returned an invalid or incomplete response.")
22
+ when 503
23
+ raise BellPepper::ServiceUnavailable, error_message_500(response, "Crossref is rate limiting your requests.")
24
+ when 504
25
+ raise BellPepper::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,77 @@
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
+ require "bell_pepper/error"
5
+
6
+ module BellPepper
7
+ class Request
8
+ attr_accessor :endpoint
9
+ attr_accessor :verbose
10
+
11
+ attr_accessor :options
12
+
13
+ def initialize(**args)
14
+ @endpoint = args[:endpoint]
15
+ @verbose = args[:verbose]
16
+
17
+ @id = args[:id]
18
+
19
+ @city = args[:city]
20
+ @continent = args[:continent]
21
+ @county = args[:county]
22
+ @country = args[:country]
23
+ @country_code = args[:country_code]
24
+ @give_me = args[:give_me]
25
+ @locality = args[:locality]
26
+ @state_province = args[:state_province]
27
+
28
+ @options = args[:options] # TODO: not added at bell_pepper.rb
29
+ end
30
+
31
+ def perform
32
+
33
+ for_location = {
34
+ id: @id,
35
+ city: @city,
36
+ continent: @continent,
37
+ county: @county,
38
+ country: @country,
39
+ countrycode: @country_code,
40
+ locality: @locality,
41
+ stateprovince: @state_province
42
+ }
43
+ for_location = for_location.delete_if { |_k, v| v.nil? }
44
+ body = {"give_me": @give_me, "for_location": for_location}
45
+
46
+ conn = if verbose
47
+ Faraday.new(url: BellPepper.base_url, request: { params_encoder: Faraday::FlatParamsEncoder }) do |f|
48
+ f.response :logger
49
+ f.request :json
50
+ f.use Faraday::BellPepperErrors::Middleware
51
+ f.adapter Faraday.default_adapter
52
+ end
53
+ else
54
+ Faraday.new(url: BellPepper.base_url, request: { params_encoder: Faraday::FlatParamsEncoder }) do |f|
55
+ f.use Faraday::BellPepperErrors::Middleware
56
+ f.request :json
57
+ f.adapter Faraday.default_adapter
58
+ end
59
+ end
60
+
61
+ conn.headers['Authorization'] = "Bearer #{@token}" unless @token.nil?
62
+ conn.headers['Accept'] = 'application/json,*/*'
63
+ conn.headers[:user_agent] = make_user_agent
64
+ conn.headers["X-USER-AGENT"] = make_user_agent
65
+
66
+ res = conn.post endpoint, body.to_json
67
+
68
+ # Handles endpoints that do not return JSON
69
+ begin
70
+ MultiJson.load(res.body)
71
+ rescue MultiJson::ParseError
72
+ res.body
73
+ end
74
+
75
+ end
76
+ end
77
+ 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 = "BellPepper/v" + BellPepper::VERSION
8
+ ua = requa + " " + habua
9
+ if BellPepper.mailto
10
+ ua += " (mailto:%s)" % BellPepper.mailto
11
+ end
12
+ # ua += format(' (mailto:%s)', BellPepper.mailto) if BellPepper.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 BellPepper
4
+ VERSION = "0.1.1"
5
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+ require_relative "bell_pepper/error"
5
+ require_relative "bell_pepper/version"
6
+ require_relative "bell_pepper/request"
7
+ require "bell_pepper/helpers/configuration"
8
+
9
+ module BellPepper
10
+ extend Configuration
11
+
12
+ define_setting :base_url, "https://localityservice.uc.r.appspot.com/api/"
13
+ define_setting :mailto, ENV["BELL_PEPPER_API_EMAIL"]
14
+
15
+
16
+ # Get a georeference
17
+ #
18
+ # @param id [String] an optional identifier that will be returned with the result
19
+ #
20
+ # @param city [String] The city
21
+ # @param continent [String] The name of the continent in which the Location occurs
22
+ # @param county [String] The full, unabbreviated name of the next smaller administrative region than stateProvince (county, shire, department, etc.) in which the Location occurs
23
+ # @param country [String] The name of the country or major administrative unit in which the Location occurs
24
+ # @param country_code [String] The ISO 3166-1-alpha-2 code for the country in which the Location occurs
25
+ # @param give_me [String] The type of georeference match (BEST_GEOREF)
26
+ # @param locality [String] The specific description of the place
27
+ # @param state_province [String] The name of the next smaller administrative region than country (state, province, canton, department, region, etc.) in which the Location occurs
28
+ #
29
+ # @return [Hash] A georeference result hash
30
+ def self.bestgeoref(id: nil, city: nil, continent: nil, county: nil, country: nil, country_code: nil,
31
+ give_me: "BEST_GEOREF", island: nil, locality: nil, municipality: nil, state_province: nil, verbose: false)
32
+ endpoint = "bestgeoref"
33
+ Request.new(
34
+ endpoint: endpoint,
35
+ id: id,
36
+ city: city,
37
+ continent: continent,
38
+ county: county,
39
+ country: country,
40
+ country_code: country_code,
41
+ give_me: give_me,
42
+ locality: locality,
43
+ state_province: state_province,
44
+ verbose: verbose).perform
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,215 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bell_pepper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Geoff Ower
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-06-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: bell_pepper is a low-level wrapper around the BELS 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
+ - bell_pepper.gemspec
180
+ - bin/console
181
+ - bin/setup
182
+ - lib/bell_pepper.rb
183
+ - lib/bell_pepper/error.rb
184
+ - lib/bell_pepper/faraday.rb
185
+ - lib/bell_pepper/helpers/configuration.rb
186
+ - lib/bell_pepper/request.rb
187
+ - lib/bell_pepper/utils.rb
188
+ - lib/bell_pepper/version.rb
189
+ homepage: https://github.com/SpeciesFileGroup/bell_pepper
190
+ licenses:
191
+ - NCSA
192
+ metadata:
193
+ homepage_uri: https://github.com/SpeciesFileGroup/bell_pepper
194
+ source_code_uri: https://github.com/SpeciesFileGroup/bell_pepper
195
+ changelog_uri: https://github.com/SpeciesFileGroup/bell_pepper/releases/tag/v0.1.1
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: Biodiversity Enhanced Location Services (BELS) Georeference Client
215
+ test_files: []