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
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 561a6110f77e9efed535f748c4a52d337cfd3793b92afc92b462e3c8b3808216
|
|
4
|
+
data.tar.gz: aa1ab89a77ccc23b3d47592b92fdc8d7ed67e895241d5361b499ed9c406a78b6
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6bdb026cf7f540f37cbdc79c59e49cefba7a8cd4991d5c8a8623a47a26a92db98f382cf6750c57408532e2a58580c353904bac51c217ee6a0c8c08f3fa0f2f72
|
|
7
|
+
data.tar.gz: 70ac333d17c161e9f03fcb9b54b4bc3afd06c2125a77f9a840a87d137da1f56749214b9a7467ec9062829b1b9d20d1f5f9e72ce49bf40c69adc4af8c1b73ef6f
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 3.1
|
|
3
|
+
NewCops: enable
|
|
4
|
+
Exclude:
|
|
5
|
+
- "examples/**/*"
|
|
6
|
+
- "tmp/**/*"
|
|
7
|
+
|
|
8
|
+
Style/StringLiterals:
|
|
9
|
+
EnforcedStyle: double_quotes
|
|
10
|
+
|
|
11
|
+
Style/StringLiteralsInInterpolation:
|
|
12
|
+
EnforcedStyle: double_quotes
|
|
13
|
+
|
|
14
|
+
Metrics/AbcSize:
|
|
15
|
+
Max: 60
|
|
16
|
+
|
|
17
|
+
Metrics/BlockLength:
|
|
18
|
+
Max: 40
|
|
19
|
+
Exclude:
|
|
20
|
+
- "spec/**/*"
|
|
21
|
+
|
|
22
|
+
Metrics/ClassLength:
|
|
23
|
+
Max: 250
|
|
24
|
+
|
|
25
|
+
Metrics/CyclomaticComplexity:
|
|
26
|
+
Max: 30
|
|
27
|
+
|
|
28
|
+
Metrics/MethodLength:
|
|
29
|
+
Max: 60
|
|
30
|
+
|
|
31
|
+
Metrics/ParameterLists:
|
|
32
|
+
Max: 10
|
|
33
|
+
|
|
34
|
+
Metrics/PerceivedComplexity:
|
|
35
|
+
Max: 30
|
|
36
|
+
|
|
37
|
+
Style/Documentation:
|
|
38
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official email address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
[INSERT CONTACT METHOD].
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Reka Pap
|
|
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,201 @@
|
|
|
1
|
+
# powo_ruby
|
|
2
|
+
|
|
3
|
+
`powo_ruby` is a small, defensive, **unofficial** Ruby client for the Plants of the World Online (POWO) API.
|
|
4
|
+
|
|
5
|
+
## Disclaimer
|
|
6
|
+
|
|
7
|
+
- This gem is **not** an official Kew product.
|
|
8
|
+
- POWO's API is **undocumented and may change or break** at any time.
|
|
9
|
+
- The API is publicly accessible and does not require authentication, but you should use it responsibly.
|
|
10
|
+
|
|
11
|
+
**Attribution**: Data and service provided by the Royal Botanic Gardens, Kew (POWO: Plants of the World Online).
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Add to your Gemfile:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
gem "powo_ruby"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Then:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
bundle install
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or install directly:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
gem install powo_ruby
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Convenience clients (recommended)
|
|
36
|
+
|
|
37
|
+
This gem exposes two convenience client constructors:
|
|
38
|
+
|
|
39
|
+
- `PowoRuby.powo` (POWO allow-list + POWO group keys)
|
|
40
|
+
- `PowoRuby.ipni` (IPNI allow-list + IPNI group keys)
|
|
41
|
+
|
|
42
|
+
Both return a configured `PowoRuby::Client` instance (memoized per-thread unless you pass overrides).
|
|
43
|
+
|
|
44
|
+
#### Basic search (POWO)
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
require "powo_ruby"
|
|
48
|
+
|
|
49
|
+
response = PowoRuby.powo.search.query(
|
|
50
|
+
query: "Apocynaceae",
|
|
51
|
+
filters: {
|
|
52
|
+
family: "Apocynaceae",
|
|
53
|
+
accepted: true
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
response.total_count #=> Integer or nil
|
|
58
|
+
response.results #=> Array of result hashes
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### Lookup by POWO/IPNI identifier
|
|
62
|
+
|
|
63
|
+
```ruby
|
|
64
|
+
taxon = PowoRuby.powo.taxa.lookup("urn:lsid:ipni.org:names:30000618-2")
|
|
65
|
+
taxon.raw #=> Hash (schema may change)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Advanced search (structured)
|
|
69
|
+
|
|
70
|
+
`advanced_search` only accepts parameters defined in `docs/POWO_SEARCH_TERMS.md`.
|
|
71
|
+
|
|
72
|
+
Flat form:
|
|
73
|
+
|
|
74
|
+
```ruby
|
|
75
|
+
response = PowoRuby.powo.search.advanced(
|
|
76
|
+
family: "Fabaceae",
|
|
77
|
+
accepted: true,
|
|
78
|
+
limit: 24
|
|
79
|
+
)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Grouped form:
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
response = PowoRuby.powo.search.advanced(
|
|
86
|
+
name: { family: "Fabaceae", genus: "Acacia" },
|
|
87
|
+
geography: { country: "Brazil" },
|
|
88
|
+
accepted: true
|
|
89
|
+
)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### Pagination (Enumerator-based)
|
|
93
|
+
|
|
94
|
+
POWO uses a cursor for paging. For most use-cases, prefer the `*_each` enumerators.
|
|
95
|
+
|
|
96
|
+
```ruby
|
|
97
|
+
PowoRuby.powo.search.each(query: "Acacia", filters: { accepted: true }).take(50)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Or for advanced search:
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
enum = PowoRuby.powo.search.advanced_each(name: { family: "Fabaceae" }, accepted: true)
|
|
104
|
+
enum.each do |row|
|
|
105
|
+
puts row["name"]
|
|
106
|
+
end
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## IPNI mode
|
|
110
|
+
|
|
111
|
+
IPNI is exposed at the same level as POWO, and validates parameters against the **IPNI term list** found in `docs/POWO_SEARCH_TERMS.md`:
|
|
112
|
+
|
|
113
|
+
```ruby
|
|
114
|
+
response = PowoRuby.ipni.search.query(query: "Poa annua", filters: { family: "Poaceae" })
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Note: POWO's API does not expose a clearly documented `/ipni/...` endpoint under `/api/2`. This gem therefore uses the same `/search` and `/taxon/<id>` endpoints but validates parameters against the IPNI allow-list.
|
|
118
|
+
|
|
119
|
+
## Configuration
|
|
120
|
+
|
|
121
|
+
```ruby
|
|
122
|
+
PowoRuby.configure do |c|
|
|
123
|
+
c.base_url = "https://powo.science.kew.org/api/2"
|
|
124
|
+
c.timeout = 10
|
|
125
|
+
c.open_timeout = 5
|
|
126
|
+
c.retries = true
|
|
127
|
+
end
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Logger support
|
|
131
|
+
|
|
132
|
+
Pass any logger responding to `warn`:
|
|
133
|
+
|
|
134
|
+
```ruby
|
|
135
|
+
require "logger"
|
|
136
|
+
|
|
137
|
+
PowoRuby.configure do |c|
|
|
138
|
+
c.logger = Logger.new($stdout)
|
|
139
|
+
end
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Caching support (optional adapter)
|
|
143
|
+
|
|
144
|
+
Provide an object that responds to `fetch(key, options = nil) { ... }`:
|
|
145
|
+
|
|
146
|
+
```ruby
|
|
147
|
+
cache = {}
|
|
148
|
+
adapter = Object.new
|
|
149
|
+
def adapter.fetch(key)
|
|
150
|
+
@store ||= {}
|
|
151
|
+
return @store[key] if @store.key?(key)
|
|
152
|
+
@store[key] = yield
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
PowoRuby.configure do |c|
|
|
156
|
+
c.cache = adapter
|
|
157
|
+
end
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
You can also pass cache options (e.g. TTL) and a namespace for cache keys:
|
|
161
|
+
|
|
162
|
+
```ruby
|
|
163
|
+
PowoRuby.configure do |c|
|
|
164
|
+
c.cache = Rails.cache
|
|
165
|
+
c.cache_options = { expires_in: 60 } # seconds
|
|
166
|
+
c.cache_namespace = "my_app"
|
|
167
|
+
end
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## CLI (optional)
|
|
171
|
+
|
|
172
|
+
After installation:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
powo_ruby search "Acacia" --filter accepted=true --filter family=Fabaceae
|
|
176
|
+
powo_ruby lookup "urn:lsid:ipni.org:names:30000618-2"
|
|
177
|
+
powo_ruby ipni-search "Poa annua" --filter family=Poaceae
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Development
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
bin/setup
|
|
184
|
+
bundle exec rspec
|
|
185
|
+
bundle exec rubocop
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Examples
|
|
189
|
+
|
|
190
|
+
Examples (including a tiny Sinatra app with basic views for search + taxon lookup) live in the separate repo [`rekapap/powo_ruby_examples`](https://github.com/rekapap/powo_ruby_examples).
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
git clone https://github.com/rekapap/powo_ruby_examples.git
|
|
194
|
+
cd powo_ruby_examples/basic_app
|
|
195
|
+
bundle install
|
|
196
|
+
bundle exec rackup
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## License
|
|
200
|
+
|
|
201
|
+
MIT. See `LICENSE.txt`.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# POWO Search Terms
|
|
2
|
+
|
|
3
|
+
## Name Terms
|
|
4
|
+
- full_name
|
|
5
|
+
- scientific_name
|
|
6
|
+
- genus
|
|
7
|
+
- species
|
|
8
|
+
- infraspecific
|
|
9
|
+
- family
|
|
10
|
+
- common_name
|
|
11
|
+
- author
|
|
12
|
+
- rank
|
|
13
|
+
- status
|
|
14
|
+
|
|
15
|
+
## Characteristic Terms
|
|
16
|
+
- summary
|
|
17
|
+
- appearance
|
|
18
|
+
- flower
|
|
19
|
+
- fruit
|
|
20
|
+
- leaf
|
|
21
|
+
- habit
|
|
22
|
+
- habitat
|
|
23
|
+
- use
|
|
24
|
+
- conservation
|
|
25
|
+
|
|
26
|
+
## Geography Terms
|
|
27
|
+
- distribution
|
|
28
|
+
- native_distribution
|
|
29
|
+
- introduced_distribution
|
|
30
|
+
- region
|
|
31
|
+
- continent
|
|
32
|
+
- country
|
|
33
|
+
|
|
34
|
+
## Additional Filters
|
|
35
|
+
- accepted (boolean)
|
|
36
|
+
- images (boolean)
|
|
37
|
+
- page (pagination)
|
|
38
|
+
- limit (pagination)
|
|
39
|
+
- sort (ordering)
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
# IPNI Search Terms
|
|
44
|
+
|
|
45
|
+
## Name Terms
|
|
46
|
+
- genus
|
|
47
|
+
- species
|
|
48
|
+
- infraspecific_rank
|
|
49
|
+
- infraspecific_name
|
|
50
|
+
- family
|
|
51
|
+
- publication_year
|
|
52
|
+
- full_name
|
|
53
|
+
|
|
54
|
+
## Author Terms
|
|
55
|
+
- author
|
|
56
|
+
- standard_form
|
|
57
|
+
- collaboration
|
|
58
|
+
|
|
59
|
+
## Publication Terms
|
|
60
|
+
- publication_title
|
|
61
|
+
- publication_year
|
|
62
|
+
- publication_place
|
|
63
|
+
- publisher
|
data/exe/powo_ruby
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "json"
|
|
5
|
+
require "optparse"
|
|
6
|
+
require "powo_ruby"
|
|
7
|
+
|
|
8
|
+
def parse_kv_pairs(pairs)
|
|
9
|
+
pairs.each_with_object({}) do |pair, out|
|
|
10
|
+
key, value = pair.split("=", 2)
|
|
11
|
+
raise ArgumentError, "Invalid filter '#{pair}' (expected key=value)" if key.to_s.empty?
|
|
12
|
+
|
|
13
|
+
out[key.to_sym] =
|
|
14
|
+
case value
|
|
15
|
+
when "true" then true
|
|
16
|
+
when "false" then false
|
|
17
|
+
when /\A\d+\z/ then Integer(value)
|
|
18
|
+
else
|
|
19
|
+
value
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
options = {
|
|
25
|
+
base_url: PowoRuby.config.base_url,
|
|
26
|
+
timeout: PowoRuby.config.timeout,
|
|
27
|
+
open_timeout: PowoRuby.config.open_timeout,
|
|
28
|
+
retries: PowoRuby.config.retries,
|
|
29
|
+
pretty: true,
|
|
30
|
+
cursor: "*",
|
|
31
|
+
per_page: 24
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
parser = OptionParser.new do |opts|
|
|
35
|
+
opts.banner = <<~BANNER
|
|
36
|
+
Usage: powo_ruby [options] <command> [args]
|
|
37
|
+
|
|
38
|
+
Commands:
|
|
39
|
+
search <query>
|
|
40
|
+
lookup <id>
|
|
41
|
+
ipni-search <query>
|
|
42
|
+
BANNER
|
|
43
|
+
|
|
44
|
+
opts.on("--base-url URL", "API base URL (default: #{options[:base_url]})") { |v| options[:base_url] = v }
|
|
45
|
+
opts.on("--timeout SECONDS", Integer, "Request timeout (default: #{options[:timeout]})") { |v| options[:timeout] = v }
|
|
46
|
+
opts.on("--open-timeout SECONDS", Integer, "Open timeout (default: #{options[:open_timeout]})") do |v|
|
|
47
|
+
options[:open_timeout] = v
|
|
48
|
+
end
|
|
49
|
+
opts.on("--no-retries", "Disable retry/backoff") { options[:retries] = false }
|
|
50
|
+
opts.on("--[no-]pretty", "Pretty-print JSON output (default: true)") { |v| options[:pretty] = v }
|
|
51
|
+
opts.on("-h", "--help", "Show this help") do
|
|
52
|
+
puts opts
|
|
53
|
+
exit 0
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
parser.order!
|
|
58
|
+
|
|
59
|
+
command = ARGV.shift
|
|
60
|
+
raise ArgumentError, "Command is required. Use --help." if command.to_s.empty?
|
|
61
|
+
|
|
62
|
+
client = PowoRuby::Client.new(
|
|
63
|
+
base_url: options[:base_url],
|
|
64
|
+
timeout: options[:timeout],
|
|
65
|
+
open_timeout: options[:open_timeout],
|
|
66
|
+
retries: options[:retries]
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
case command
|
|
70
|
+
when "search"
|
|
71
|
+
query = ARGV.shift
|
|
72
|
+
raise ArgumentError, "search requires <query>" if query.to_s.empty?
|
|
73
|
+
|
|
74
|
+
filters = []
|
|
75
|
+
OptionParser.new do |opts|
|
|
76
|
+
opts.on("--cursor CURSOR", "Cursor for pagination (default: '*')") { |v| options[:cursor] = v }
|
|
77
|
+
opts.on("--per-page N", Integer, "Results per page (default: 24)") { |v| options[:per_page] = v }
|
|
78
|
+
opts.on("--filter KEY=VALUE", "Repeatable filter (e.g. family=Fabaceae accepted=true)") { |v| filters << v }
|
|
79
|
+
end.parse!(ARGV)
|
|
80
|
+
|
|
81
|
+
response =
|
|
82
|
+
client.search.query(
|
|
83
|
+
query: query,
|
|
84
|
+
filters: parse_kv_pairs(filters),
|
|
85
|
+
cursor: options[:cursor],
|
|
86
|
+
per_page: options[:per_page]
|
|
87
|
+
)
|
|
88
|
+
output = { total: response.total_count, results: response.results }
|
|
89
|
+
when "lookup"
|
|
90
|
+
id = ARGV.shift
|
|
91
|
+
raise ArgumentError, "lookup requires <id>" if id.to_s.empty?
|
|
92
|
+
|
|
93
|
+
response = client.taxa.lookup(id)
|
|
94
|
+
output = response.raw
|
|
95
|
+
when "ipni-search"
|
|
96
|
+
query = ARGV.shift
|
|
97
|
+
raise ArgumentError, "ipni-search requires <query>" if query.to_s.empty?
|
|
98
|
+
|
|
99
|
+
filters = []
|
|
100
|
+
OptionParser.new do |opts|
|
|
101
|
+
opts.on("--cursor CURSOR", "Cursor for pagination (default: '*')") { |v| options[:cursor] = v }
|
|
102
|
+
opts.on("--per-page N", Integer, "Results per page (default: 24)") { |v| options[:per_page] = v }
|
|
103
|
+
opts.on("--filter KEY=VALUE", "Repeatable filter (validated against IPNI term list)") { |v| filters << v }
|
|
104
|
+
end.parse!(ARGV)
|
|
105
|
+
|
|
106
|
+
ipni_client =
|
|
107
|
+
PowoRuby::Client.new(
|
|
108
|
+
mode: :ipni,
|
|
109
|
+
base_url: options[:base_url],
|
|
110
|
+
timeout: options[:timeout],
|
|
111
|
+
open_timeout: options[:open_timeout],
|
|
112
|
+
retries: options[:retries]
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
response =
|
|
116
|
+
ipni_client.search.query(
|
|
117
|
+
query: query,
|
|
118
|
+
filters: parse_kv_pairs(filters),
|
|
119
|
+
cursor: options[:cursor],
|
|
120
|
+
per_page: options[:per_page]
|
|
121
|
+
)
|
|
122
|
+
output = { total: response.total_count, results: response.results }
|
|
123
|
+
else
|
|
124
|
+
raise ArgumentError, "Unknown command '#{command}'. Use --help."
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
json =
|
|
128
|
+
if options[:pretty]
|
|
129
|
+
JSON.pretty_generate(output)
|
|
130
|
+
else
|
|
131
|
+
JSON.dump(output)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
puts json
|