plazucchini 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e946e49b0d7b0431723f4e71290c92b1f56590e754f908f12e03c7f9f9b12a7f
4
+ data.tar.gz: b907310367f61a0fd5c4a9813ae95e225ebaaeadd85907d4c8ad08e38962fd28
5
+ SHA512:
6
+ metadata.gz: 740695167b8db361fbc8ff11a07f238e935929062439aa6d29062e5e8449d37de85165b17083122aad7356b1f30c6dda3236800a05994ba3bfb8f04270fe672e
7
+ data.tar.gz: df3d1a11d3c630618e149d3c98ee7cf684789dcd84ed98b90dc06f95bb1a27a723e806c97343f9a612af65c055b98aeee292f56770c1720a3a7c3ea07a3399a0
@@ -0,0 +1,16 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.3.4
14
+ bundler-cache: true
15
+ - name: Run the default task
16
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .byebug_history
2
+ .vscode
3
+ .idea
4
+ /.bundle/
5
+ /.yardoc
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+ *.gem
13
+ Gemfile.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.0.1] - 2026-01-27
9
+
10
+ ### Added
11
+ - Initial release
12
+ - Plazi API wrapper based on checkerberry structure
13
+ - TreatmentsForTaxon endpoint
14
+ - Fetch treatment endpoint
@@ -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 plazucchini.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2024 Species File Group
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Plazucchini
2
+
3
+ Plazucchini is a Ruby wrapper on the [Plazi's TreatmentBank](https://api.plazi.org) API. Code follows the spirit/approach of the Gem [serrano](https://github.com/sckott/serrano), and indeed much of the wrapping utility is copied 1:1 from that repo, thanks [@sckott](https://github.com/sckott).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'plazucchini'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install plazucchini
20
+
21
+ ## Usage
22
+
23
+ All Plazi API endpoints are wrapped. Please see the tests for usage examples. Here are a few examples:
24
+
25
+ ### [Search by DOI](http://api.plazi.org/GgSrvApi/v1#Treatments.searchByDOI)
26
+
27
+ Get treatments for a taxon:
28
+ ```ruby
29
+ Plazucchini.treatments_search_by_doi(doi: '10.5281/zenodo.8117062', limit: 1)
30
+ ```
31
+
32
+ ### [Treatments for Taxon](http://api.plazi.org/GgSrvApi/v1#Treatments.fetch)
33
+
34
+ Get treatments for a taxon:
35
+ ```ruby
36
+ Plazucchini.treatments_for_taxon(genus: 'Arboridia', species: 'septempunctata', limit: 1)
37
+ ```
38
+
39
+ ## Development
40
+
41
+ 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.
42
+
43
+ To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, update the CHANGELOG.md, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SpeciesFileGroup/plazucchini. 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/plazucchini/blob/main/CODE_OF_CONDUCT.md).
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT license](https://github.com/SpeciesFileGroup/plazucchini/blob/main/LICENSE.txt). You can learn more about the MIT license on [Wikipedia](https://en.wikipedia.org/wiki/MIT_License) and compare it with other open source licenses at the [Open Source Initiative](https://opensource.org/license/mit/).
52
+
53
+ ## Code of Conduct
54
+
55
+ Everyone interacting in the Plazucchini project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/SpeciesFileGroup/plazucchini/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 "plazucchini"
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,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plazucchini
4
+ class Error < StandardError; end
5
+ class RequestError < Error; end
6
+ class Unauthorized < Error; end
7
+ class NotFound < Error; end
8
+ class InternalServerError < Error; end
9
+ class BadGateway < Error; end
10
+ class ServiceUnavailable < Error; end
11
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+
5
+ module Faraday
6
+ class PlazucchiniErrors < Faraday::Middleware
7
+ def on_complete(env)
8
+ @env = env
9
+ case env[:status]
10
+ when 400
11
+ raise Plazucchini::RequestError, error_message
12
+ when 401
13
+ raise Plazucchini::Unauthorized, error_message
14
+ when 404
15
+ raise Plazucchini::NotFound, error_message
16
+ when 500
17
+ raise Plazucchini::InternalServerError, error_message
18
+ when 502
19
+ raise Plazucchini::BadGateway, error_message
20
+ when 503
21
+ raise Plazucchini::ServiceUnavailable, error_message
22
+ end
23
+ end
24
+
25
+ def error_message
26
+ "#{@env[:method].to_s.upcase} #{@env[:url]}: #{@env[:status]} - #{@env[:body]}"
27
+ end
28
+
29
+ class Middleware < PlazucchiniErrors
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,25 @@
1
+ # taken from https://raw.githubusercontent.com/sckott/serrano/main/lib/serrano/helpers/configuration.rb
2
+ # taken from: https://viget.com/extend/easy-gem-configuration-variables-with-defaults
3
+ module Configuration
4
+ def configuration
5
+ yield self
6
+ end
7
+
8
+ def define_setting(name, default = nil)
9
+ class_variable_set("@@#{name}", default)
10
+ define_class_method "#{name}=" do |value|
11
+ class_variable_set("@@#{name}", value)
12
+ end
13
+ define_class_method name do
14
+ class_variable_get("@@#{name}")
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def define_class_method(name, &block)
21
+ (class << self; self; end).instance_eval do
22
+ define_method name, &block
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,96 @@
1
+ require_relative "faraday"
2
+ require "faraday/follow_redirects"
3
+ require_relative "utils"
4
+ require_relative "xml_parser"
5
+ require "plazucchini/error"
6
+ require "multi_json"
7
+
8
+ module Plazucchini
9
+ class Request
10
+ include Utils
11
+ attr_accessor :endpoint, :verbose
12
+
13
+ def initialize(**args)
14
+ @endpoint = args[:endpoint]
15
+ @verbose = args[:verbose]
16
+ @method = args[:method] || :get
17
+ @format = args[:format] || :json
18
+ @limit = args[:limit]
19
+ @order_mode = args[:order_mode]
20
+ @author = args[:author]
21
+ @collector = args[:collector]
22
+ @doi = args[:doi]
23
+ @uuid = args[:uuid]
24
+ @user = args[:user]
25
+ @status = args[:status]
26
+ @collection_code = args[:collection_code]
27
+ @journal = args[:journal]
28
+ @kingdom_epithet = args[:kingdom_epithet]
29
+ @phylum_epithet = args[:phylum_epithet]
30
+ @class_epithet = args[:class_epithet]
31
+ @order_epithet = args[:order_epithet]
32
+ @family_epithet = args[:family_epithet]
33
+ @genus_epithet = args[:genus_epithet]
34
+ @species_epithet = args[:species_epithet]
35
+ end
36
+
37
+ def perform
38
+ args = {
39
+ limit: @limit,
40
+ orderMode: @order_mode,
41
+ DOI: @doi,
42
+ UUID: @uuid,
43
+ author: @author,
44
+ collector: @collector,
45
+ user: @user,
46
+ status: @status,
47
+ collectionCode: @collection_code,
48
+ journal: @journal,
49
+ kingdom: @kingdom_epithet,
50
+ phylum: @phylum_epithet,
51
+ class: @class_epithet,
52
+ order: @order_epithet,
53
+ family: @family_epithet,
54
+ genus: @genus_epithet,
55
+ species: @species_epithet
56
+ }
57
+ # Only include format param for JSON (XML endpoints don't accept format param)
58
+ args[:format] = @format if @format == :json
59
+ opts = args.delete_if { |_k, v| v.nil? }
60
+
61
+ conn = Faraday.new(url: Plazucchini.base_url) do |f|
62
+ f.request :json
63
+ f.response :logger if @verbose
64
+ f.use Faraday::PlazucchiniErrors::Middleware
65
+ f.adapter Faraday.default_adapter
66
+ end
67
+
68
+ conn.headers['Accept'] = @format == :xml ? 'application/xml' : 'application/json'
69
+ conn.headers['Content-Type'] = 'application/json' if @method == :post
70
+ conn.headers[:user_agent] = make_user_agent
71
+ conn.headers["X-USER-AGENT"] = make_user_agent
72
+
73
+ res = if @method == :post
74
+ conn.post(endpoint, opts.to_json)
75
+ else
76
+ conn.get(endpoint, opts)
77
+ end
78
+
79
+ parse_response(res.body)
80
+ end
81
+
82
+ private
83
+
84
+ def parse_response(body)
85
+ if @format == :xml
86
+ XmlParser.parse(body)
87
+ else
88
+ begin
89
+ deep_transform_keys(MultiJson.load(body))
90
+ rescue MultiJson::ParseError
91
+ body
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plazucchini
4
+ module Utils
5
+ def make_user_agent
6
+ requa = "Faraday/v" + Faraday::VERSION
7
+ habua = "Plazucchini/v" + Plazucchini::VERSION
8
+ if Plazucchini.mailto
9
+ mailto = "mailto:" + Plazucchini.mailto
10
+ ua = requa + " " + habua + " " + mailto
11
+ else
12
+ ua = requa + " " + habua
13
+ end
14
+ ua
15
+ end
16
+
17
+ def to_snake_case(str)
18
+ str.to_s
19
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
20
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
21
+ .gsub(/[-.]/, '_')
22
+ .downcase
23
+ end
24
+
25
+ def deep_transform_keys(obj)
26
+ case obj
27
+ when Hash
28
+ obj.each_with_object({}) do |(key, value), result|
29
+ result[to_snake_case(key)] = deep_transform_keys(value)
30
+ end
31
+ when Array
32
+ obj.map { |item| deep_transform_keys(item) }
33
+ else
34
+ obj
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plazucchini
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "nokogiri"
4
+ require_relative "utils"
5
+
6
+ module Plazucchini
7
+ module XmlParser
8
+ class << self
9
+ include Utils
10
+
11
+ def parse(xml_string)
12
+ doc = Nokogiri::XML(xml_string)
13
+ doc.remove_namespaces!
14
+ node_to_hash(doc.root)
15
+ end
16
+
17
+ private
18
+
19
+ def node_to_hash(node)
20
+ return nil if node.nil?
21
+
22
+ result = {}
23
+
24
+ # Add attributes with snake_case keys
25
+ node.attributes.each do |name, attr|
26
+ result[to_snake_case(name)] = attr.value
27
+ end
28
+
29
+ # Group child elements by name
30
+ children_by_name = {}
31
+ node.element_children.each do |child|
32
+ name = to_snake_case(child.name)
33
+ children_by_name[name] ||= []
34
+ children_by_name[name] << child
35
+ end
36
+
37
+ # Process child elements
38
+ children_by_name.each do |name, children|
39
+ if children.length == 1
40
+ result[name] = node_to_hash(children.first)
41
+ else
42
+ result[name] = children.map { |child| node_to_hash(child) }
43
+ end
44
+ end
45
+
46
+ # Handle text content
47
+ text = node.children.select(&:text?).map(&:text).join.strip
48
+ if text.length > 0
49
+ if result.empty?
50
+ return text
51
+ else
52
+ result["text"] = text unless text.empty?
53
+ end
54
+ end
55
+
56
+ result.empty? ? nil : result
57
+ end
58
+ end
59
+ end
60
+ end