powo_ruby 0.1.0
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 +7 -0
- data/.rubocop.yml +38 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +201 -0
- data/Rakefile +12 -0
- data/docs/POWO_SEARCH_TERMS.md +63 -0
- data/exe/powo_ruby +134 -0
- data/lib/powo_ruby/client.rb +121 -0
- data/lib/powo_ruby/client_resolver.rb +37 -0
- data/lib/powo_ruby/configuration.rb +69 -0
- data/lib/powo_ruby/errors.rb +52 -0
- data/lib/powo_ruby/paginator.rb +41 -0
- data/lib/powo_ruby/request.rb +146 -0
- data/lib/powo_ruby/request_support/cache_key_builder.rb +80 -0
- data/lib/powo_ruby/request_support/cache_store.rb +37 -0
- data/lib/powo_ruby/request_support/response_handler.rb +82 -0
- data/lib/powo_ruby/request_support/retry_policy.rb +86 -0
- data/lib/powo_ruby/resources/search.rb +217 -0
- data/lib/powo_ruby/resources/taxa.rb +36 -0
- data/lib/powo_ruby/response.rb +71 -0
- data/lib/powo_ruby/terms.rb +149 -0
- data/lib/powo_ruby/uri_utils.rb +20 -0
- data/lib/powo_ruby/validation.rb +44 -0
- data/lib/powo_ruby/version.rb +6 -0
- data/lib/powo_ruby.rb +109 -0
- data/sig/powo_ruby.rbs +6 -0
- metadata +85 -0
data/lib/powo_ruby.rb
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "powo_ruby/version"
|
|
4
|
+
require_relative "powo_ruby/errors"
|
|
5
|
+
require_relative "powo_ruby/validation"
|
|
6
|
+
require_relative "powo_ruby/uri_utils"
|
|
7
|
+
require_relative "powo_ruby/request"
|
|
8
|
+
require_relative "powo_ruby/response"
|
|
9
|
+
require_relative "powo_ruby/terms"
|
|
10
|
+
require_relative "powo_ruby/configuration"
|
|
11
|
+
require_relative "powo_ruby/client_resolver"
|
|
12
|
+
require_relative "powo_ruby/paginator"
|
|
13
|
+
require_relative "powo_ruby/resources/search"
|
|
14
|
+
require_relative "powo_ruby/resources/taxa"
|
|
15
|
+
require_relative "powo_ruby/client"
|
|
16
|
+
|
|
17
|
+
# Unofficial, defensive Ruby client for Plants of the World Online (POWO).
|
|
18
|
+
#
|
|
19
|
+
# This gem exposes:
|
|
20
|
+
# - module-level convenience clients (`PowoRuby.powo`, `PowoRuby.ipni`)
|
|
21
|
+
# - a configurable `PowoRuby::Client` with endpoint wrappers (`#search`, `#taxa`)
|
|
22
|
+
#
|
|
23
|
+
# The underlying POWO API is undocumented and may change. This gem focuses on:
|
|
24
|
+
# - validating parameters early
|
|
25
|
+
# - providing cursor-based iteration helpers
|
|
26
|
+
# - exposing errors with useful context (method/url/status/body)
|
|
27
|
+
module PowoRuby
|
|
28
|
+
class << self
|
|
29
|
+
# Global configuration used by the convenience constructors.
|
|
30
|
+
#
|
|
31
|
+
# @return [PowoRuby::Configuration]
|
|
32
|
+
def config
|
|
33
|
+
@config ||= Configuration.new
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Configure the global `PowoRuby.config`.
|
|
37
|
+
#
|
|
38
|
+
# Calling this also resets any memoized per-thread convenience clients, so new calls
|
|
39
|
+
# to `PowoRuby.powo`/`PowoRuby.ipni` pick up the updated configuration.
|
|
40
|
+
#
|
|
41
|
+
# @yieldparam c [PowoRuby::Configuration]
|
|
42
|
+
# @return [PowoRuby::Configuration] the updated configuration
|
|
43
|
+
#
|
|
44
|
+
# @example
|
|
45
|
+
# PowoRuby.configure do |c|
|
|
46
|
+
# c.timeout = 10
|
|
47
|
+
# c.cache = Rails.cache
|
|
48
|
+
# c.cache_options = { expires_in: 60 }
|
|
49
|
+
# end
|
|
50
|
+
def configure
|
|
51
|
+
yield(config)
|
|
52
|
+
reset_clients!
|
|
53
|
+
config
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Clears memoized convenience clients for the current thread.
|
|
57
|
+
#
|
|
58
|
+
# The convenience clients (`PowoRuby.powo`, `PowoRuby.ipni`) memoize a client per-thread
|
|
59
|
+
# to avoid re-parsing terms and rebuilding Faraday connections.
|
|
60
|
+
#
|
|
61
|
+
# @return [void]
|
|
62
|
+
def reset_clients!
|
|
63
|
+
Thread.current[:powo_ruby_default_powo_client] = nil
|
|
64
|
+
Thread.current[:powo_ruby_default_ipni_client] = nil
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Convenience constructor for a POWO-mode client.
|
|
68
|
+
#
|
|
69
|
+
# Uses a per-thread memoized client unless `config:` is provided.
|
|
70
|
+
#
|
|
71
|
+
# @param config [nil, Hash, PowoRuby::Configuration, PowoRuby::Client]
|
|
72
|
+
# - `nil`: use memoized client
|
|
73
|
+
# - `Hash`: override selected config keys for this call
|
|
74
|
+
# - `PowoRuby::Configuration`: use exactly that configuration
|
|
75
|
+
# - `PowoRuby::Client`: returned as-is
|
|
76
|
+
# @return [PowoRuby::Client]
|
|
77
|
+
#
|
|
78
|
+
# @example (default client)
|
|
79
|
+
# client = PowoRuby.powo
|
|
80
|
+
# client.search.query(query: "Acacia")
|
|
81
|
+
#
|
|
82
|
+
# @example (override for a single call)
|
|
83
|
+
# client = PowoRuby.powo(config: { timeout: 2 })
|
|
84
|
+
def powo(config: nil)
|
|
85
|
+
ClientResolver.resolve(
|
|
86
|
+
Client,
|
|
87
|
+
config: config,
|
|
88
|
+
memo_key: :powo_ruby_default_powo_client,
|
|
89
|
+
default_overrides: { mode: :powo }
|
|
90
|
+
)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Convenience constructor for an IPNI-mode client.
|
|
94
|
+
#
|
|
95
|
+
# This mode validates parameters against the IPNI allow-list (terms) but still calls
|
|
96
|
+
# the same underlying POWO `/search` and `/taxon/<id>` endpoints.
|
|
97
|
+
#
|
|
98
|
+
# @param config [nil, Hash, PowoRuby::Configuration, PowoRuby::Client] see {#powo}
|
|
99
|
+
# @return [PowoRuby::Client]
|
|
100
|
+
def ipni(config: nil)
|
|
101
|
+
ClientResolver.resolve(
|
|
102
|
+
Client,
|
|
103
|
+
config: config,
|
|
104
|
+
memo_key: :powo_ruby_default_ipni_client,
|
|
105
|
+
default_overrides: { mode: :ipni }
|
|
106
|
+
)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
data/sig/powo_ruby.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: powo_ruby
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Reka Pap
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2026-02-13 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: faraday
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.0'
|
|
26
|
+
description: A small, defensive, unofficial client for the undocumented POWO API.
|
|
27
|
+
email:
|
|
28
|
+
- rekapap28@gmail.com
|
|
29
|
+
executables:
|
|
30
|
+
- powo_ruby
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- ".rubocop.yml"
|
|
35
|
+
- CHANGELOG.md
|
|
36
|
+
- CODE_OF_CONDUCT.md
|
|
37
|
+
- LICENSE.txt
|
|
38
|
+
- README.md
|
|
39
|
+
- Rakefile
|
|
40
|
+
- docs/POWO_SEARCH_TERMS.md
|
|
41
|
+
- exe/powo_ruby
|
|
42
|
+
- lib/powo_ruby.rb
|
|
43
|
+
- lib/powo_ruby/client.rb
|
|
44
|
+
- lib/powo_ruby/client_resolver.rb
|
|
45
|
+
- lib/powo_ruby/configuration.rb
|
|
46
|
+
- lib/powo_ruby/errors.rb
|
|
47
|
+
- lib/powo_ruby/paginator.rb
|
|
48
|
+
- lib/powo_ruby/request.rb
|
|
49
|
+
- lib/powo_ruby/request_support/cache_key_builder.rb
|
|
50
|
+
- lib/powo_ruby/request_support/cache_store.rb
|
|
51
|
+
- lib/powo_ruby/request_support/response_handler.rb
|
|
52
|
+
- lib/powo_ruby/request_support/retry_policy.rb
|
|
53
|
+
- lib/powo_ruby/resources/search.rb
|
|
54
|
+
- lib/powo_ruby/resources/taxa.rb
|
|
55
|
+
- lib/powo_ruby/response.rb
|
|
56
|
+
- lib/powo_ruby/terms.rb
|
|
57
|
+
- lib/powo_ruby/uri_utils.rb
|
|
58
|
+
- lib/powo_ruby/validation.rb
|
|
59
|
+
- lib/powo_ruby/version.rb
|
|
60
|
+
- sig/powo_ruby.rbs
|
|
61
|
+
homepage: https://github.com/rekapap/powo_ruby
|
|
62
|
+
licenses:
|
|
63
|
+
- MIT
|
|
64
|
+
metadata:
|
|
65
|
+
source_code_uri: https://github.com/rekapap/powo_ruby
|
|
66
|
+
changelog_uri: https://github.com/rekapap/powo_ruby/blob/main/CHANGELOG.md
|
|
67
|
+
rubygems_mfa_required: 'true'
|
|
68
|
+
rdoc_options: []
|
|
69
|
+
require_paths:
|
|
70
|
+
- lib
|
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 3.1.0
|
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - ">="
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '0'
|
|
81
|
+
requirements: []
|
|
82
|
+
rubygems_version: 3.6.3
|
|
83
|
+
specification_version: 4
|
|
84
|
+
summary: Unofficial Ruby client for Kew POWO (Plants of the World Online) API
|
|
85
|
+
test_files: []
|