taxa 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -0
  3. data/.rubocop.yml +0 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +0 -0
  6. data/CHANGELOG.md +24 -18
  7. data/CODE_OF_CONDUCT.md +0 -0
  8. data/Gemfile +0 -0
  9. data/Gemfile.lock +4 -4
  10. data/LICENSE.txt +0 -0
  11. data/README.md +8 -0
  12. data/Rakefile +0 -0
  13. data/lib/taxa.rb +1 -0
  14. data/lib/taxa/eol_classic/client.rb +0 -0
  15. data/lib/taxa/open_tree_of_life/client.rb +0 -0
  16. data/lib/taxa/open_tree_of_life/label_format_helper.rb +0 -0
  17. data/lib/taxa/open_tree_of_life/studies/base.rb +0 -0
  18. data/lib/taxa/open_tree_of_life/studies/find_studies.rb +0 -0
  19. data/lib/taxa/open_tree_of_life/studies/find_trees.rb +0 -0
  20. data/lib/taxa/open_tree_of_life/studies/properties.rb +0 -0
  21. data/lib/taxa/open_tree_of_life/studies/study.rb +0 -0
  22. data/lib/taxa/open_tree_of_life/studies/tree.rb +0 -0
  23. data/lib/taxa/open_tree_of_life/taxonomy/about.rb +0 -0
  24. data/lib/taxa/open_tree_of_life/taxonomy/base.rb +0 -0
  25. data/lib/taxa/open_tree_of_life/taxonomy/mrca.rb +0 -0
  26. data/lib/taxa/open_tree_of_life/taxonomy/subtree.rb +0 -0
  27. data/lib/taxa/open_tree_of_life/taxonomy/taxon_info.rb +0 -0
  28. data/lib/taxa/open_tree_of_life/tnrs/autocomplete_name.rb +0 -0
  29. data/lib/taxa/open_tree_of_life/tnrs/base.rb +0 -0
  30. data/lib/taxa/open_tree_of_life/tnrs/contexts.rb +0 -0
  31. data/lib/taxa/open_tree_of_life/tnrs/infer_context.rb +0 -0
  32. data/lib/taxa/open_tree_of_life/tnrs/match_names.rb +0 -0
  33. data/lib/taxa/open_tree_of_life/tree_of_life/about.rb +0 -0
  34. data/lib/taxa/open_tree_of_life/tree_of_life/base.rb +0 -0
  35. data/lib/taxa/open_tree_of_life/tree_of_life/induced_subtree.rb +0 -0
  36. data/lib/taxa/open_tree_of_life/tree_of_life/mrca.rb +0 -0
  37. data/lib/taxa/open_tree_of_life/tree_of_life/node_info.rb +0 -0
  38. data/lib/taxa/open_tree_of_life/tree_of_life/subtree.rb +0 -0
  39. data/lib/taxa/plants_of_the_world_online/client.rb +63 -0
  40. data/lib/taxa/utils.rb +14 -0
  41. data/lib/taxa/version.rb +1 -1
  42. data/taxa.gemspec +0 -0
  43. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d02a59f702859db4b8816859d1ac70a36c53840c243d58c4924b85fe1b6766e1
4
- data.tar.gz: b38261c5222c2ab544d641e9845f648edd9ff56fd94cc9a94866822de8cb8c18
3
+ metadata.gz: 2f22b781a534e5778cfe117a963ec4984f17eda86c757a05a21d012088644996
4
+ data.tar.gz: cd39b3a350ad83c26a7d1e60fece8964b7bb68fb82907305f8aec8d6c1e434d3
5
5
  SHA512:
6
- metadata.gz: 00d336dc76b870722fc395678c1a338e5fc8f65d0339beb19896f81eca4cf896f4d7c7e9cb2af63ef2981746c4f7ff3ff622f5868967ee4151ccbb1e678d3a4c
7
- data.tar.gz: 54146c3bd2a1b52a3b9fbc4c67887d247a4da3f3c679a7e20f89668724df20ec3bb0d3486ec772f3e130a3e43561857642e61d76df34ced9f571b129e17d78a6
6
+ metadata.gz: '09e294e750b886dc5a5248c66cc5c13d5ca284dfadea44fe8cdbfd3218b3f835907fe2158f1669b12741ae186f55a7b362e0c350b2735656b1582a89c99f6fe7'
7
+ data.tar.gz: 7239b7a6efcc5d822bb78ea6ab1cd3bfecabf1373036fbf53b1fce8e267d26a7e946fd104a53ea36bb04d4e010dfcdd89cc6f75d307579163f58d587beaa9b66
data/.gitignore CHANGED
File without changes
data/.rubocop.yml CHANGED
File without changes
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.2
data/.travis.yml CHANGED
File without changes
data/CHANGELOG.md CHANGED
@@ -1,18 +1,24 @@
1
- # Taxa Changelog
2
-
3
- ## [0.1.0]
4
-
5
- ### Highlights
6
- Support for Open Tree of Life API v3
7
- https://github.com/OpenTreeOfLife/germinator/wiki/Open-Tree-of-Life-Web-APIs
8
-
9
- ## [0.2.0]
10
-
11
- ### Highlights
12
- Support for the classic API for EOL
13
- https://eol.org/docs/what-is-eol/classic-apis
14
-
15
- ## [0.2.1]
16
-
17
- ### Highlights
18
- Update JSON gem to 2.5.x
1
+ # Taxa Changelog
2
+
3
+ ## [0.1.0]
4
+
5
+ ### Highlights
6
+ Support for Open Tree of Life API v3
7
+ https://github.com/OpenTreeOfLife/germinator/wiki/Open-Tree-of-Life-Web-APIs
8
+
9
+ ## [0.2.0]
10
+
11
+ ### Highlights
12
+ Support for the classic API for EOL
13
+ https://eol.org/docs/what-is-eol/classic-apis
14
+
15
+ ## [0.2.1]
16
+
17
+ ### Highlights
18
+ Update JSON gem to 2.5.x
19
+
20
+ ## [0.3.0]
21
+
22
+ ### Highlights
23
+ Support for Plants of the World Online
24
+ http://plantsoftheworldonline.org/
data/CODE_OF_CONDUCT.md CHANGED
File without changes
data/Gemfile CHANGED
File without changes
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- taxa (0.2.0)
4
+ taxa (0.2.1)
5
5
  faraday (~> 1.1)
6
6
  json (~> 2.5)
7
7
 
@@ -13,7 +13,7 @@ GEM
13
13
  faraday-net_http (~> 1.0)
14
14
  multipart-post (>= 1.2, < 3)
15
15
  ruby2_keywords
16
- faraday-net_http (1.0.0)
16
+ faraday-net_http (1.0.1)
17
17
  json (2.5.1)
18
18
  minitest (5.14.2)
19
19
  multipart-post (2.1.1)
@@ -36,7 +36,7 @@ GEM
36
36
  rubocop-ast (1.3.0)
37
37
  parser (>= 2.7.1.5)
38
38
  ruby-progressbar (1.10.1)
39
- ruby2_keywords (0.0.2)
39
+ ruby2_keywords (0.0.4)
40
40
  unicode-display_width (1.7.0)
41
41
 
42
42
  PLATFORMS
@@ -49,4 +49,4 @@ DEPENDENCIES
49
49
  taxa!
50
50
 
51
51
  BUNDLED WITH
52
- 2.1.4
52
+ 2.2.3
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
@@ -25,8 +25,16 @@ tol_client.tnrs.match_names('Cotyledon') # can be an array or a string
25
25
 
26
26
  eol_client = Taxa::EOLClassic::Client.new
27
27
  eol_client.hierarchy_entries(7834469)
28
+
29
+ powo_client = Taxa::PlantsOfTheWorldOnline::Client.new
30
+ powo_client.search('Crassula alata')
31
+ powo_client.search('Crassula', ['species_f', 'has_images'])
32
+ powo_client.search('family:Crassulaceae', ['species_f', 'has_images'])
28
33
  ```
29
34
 
35
+ For Plants of the World Online please see their official python library for available search terms:
36
+ https://github.com/RBGKew/pykew#available-search-terms-1
37
+
30
38
  ## Development
31
39
 
32
40
  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.
data/Rakefile CHANGED
File without changes
data/lib/taxa.rb CHANGED
@@ -4,6 +4,7 @@ require 'taxa/version'
4
4
  require 'faraday'
5
5
  require_relative './taxa/open_tree_of_life/client'
6
6
  require_relative './taxa/eol_classic/client'
7
+ require_relative './taxa/plants_of_the_world_online/client'
7
8
 
8
9
  module Taxa
9
10
  # include OpenTreeOfLife
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../utils'
4
+ module Taxa
5
+ module PlantsOfTheWorldOnline
6
+ # API client for Open Tree of Life
7
+ class Client
8
+ attr_accessor :options
9
+ attr_reader :http_client
10
+
11
+ POWO_URL = 'http://www.plantsoftheworldonline.org/api/2'
12
+
13
+ FILTERS = %w[accepted_names has_images families_f genus_f species__f infraspecific_f].freeze
14
+
15
+ def initialize(**options)
16
+ @options = options
17
+ @http_client = options[:http_client] || Faraday.new
18
+ end
19
+
20
+ def search(query, options = {})
21
+ options.transform_keys!(&:to_sym)
22
+
23
+ page = options[:page] || 0
24
+ filters = Array.wrap(options[:filters])
25
+ validate_search_parameters(query, page, filters)
26
+
27
+ payload = { q: query, p: page }
28
+ payload.merge!({ f: filters.join(',') }) unless filters.empty?
29
+ response = @http_client.get("#{POWO_URL}/search", payload, { 'Accept' => 'application/json' })
30
+ parse_response(response)
31
+ end
32
+
33
+ def lookup(id, include = nil)
34
+ raise ArgumentError, 'id can not be nil' if id.nil?
35
+
36
+ include = Array.wrap(include)
37
+ payload = {}
38
+ payload.merge!({ fields: include.join(',') }) unless include.empty?
39
+ response = @http_client.get("#{POWO_URL}/taxon/#{id}", payload, { 'Accept' => 'application/json' })
40
+ parse_response(response)
41
+ end
42
+
43
+ private
44
+
45
+ def validate_search_parameters(query, page, filters)
46
+ raise ArgumentError, 'query can not be nil' if query.nil?
47
+
48
+ if !filters.empty? && (filters & FILTERS).empty?
49
+ raise ArgumentError,
50
+ "filter is invalid. It must be one of these: #{FILTERS.join(', ')} can not be nil"
51
+ end
52
+
53
+ raise ArgumentError, 'page must be an integer' unless page.is_a?(Integer)
54
+ end
55
+
56
+ def parse_response(response)
57
+ JSON.parse(response.body)
58
+ rescue StandardError
59
+ nil
60
+ end
61
+ end
62
+ end
63
+ end
data/lib/taxa/utils.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # https://stackoverflow.com/questions/18358717/ruby-elegantly-convert-variable-to-an-array-if-not-an-array-already
4
+ class Array
5
+ def self.wrap(object)
6
+ if object.nil?
7
+ []
8
+ elsif object.respond_to?(:to_ary)
9
+ object.to_ary || [object]
10
+ else
11
+ [object]
12
+ end
13
+ end
14
+ end
data/lib/taxa/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Taxa
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
data/taxa.gemspec CHANGED
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taxa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Sherman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-10 00:00:00.000000000 Z
11
+ date: 2021-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".rubocop.yml"
64
+ - ".ruby-version"
64
65
  - ".travis.yml"
65
66
  - CHANGELOG.md
66
67
  - CODE_OF_CONDUCT.md
@@ -97,6 +98,8 @@ files:
97
98
  - lib/taxa/open_tree_of_life/tree_of_life/mrca.rb
98
99
  - lib/taxa/open_tree_of_life/tree_of_life/node_info.rb
99
100
  - lib/taxa/open_tree_of_life/tree_of_life/subtree.rb
101
+ - lib/taxa/plants_of_the_world_online/client.rb
102
+ - lib/taxa/utils.rb
100
103
  - lib/taxa/version.rb
101
104
  - taxa.gemspec
102
105
  homepage: https://github.com/ssherman/taxa