eol 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2662b8d0df748e74e3a92a3b540c0608623f89ed
4
+ data.tar.gz: 50b0ff770d5ab2f8cf7ddc901a1df9e1cd631c19
5
+ SHA512:
6
+ metadata.gz: ece05a50c31c0c369bb467fb7c244e0167341c607b00475e50ecb8ce9d9b9f75948c3d8422d4600c3ebca6dacf4e72310d5ebdd2856d0ce989284fc48cded616
7
+ data.tar.gz: b284bd2bf417542905c86addead556a988d4b2d2a261ea767440b553b7975756530e2924343ed5138d38052146636d31f62531e51a9367e317dfd7835c80e452
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,6 @@
1
+ sudo: false
2
+ dist: trusty
3
+ language: ruby
4
+ rvm:
5
+ - 2.3.0
6
+ before_install: gem install bundler -v 1.14.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at romanrob2003@yahoo.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eol.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Rob Roman
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.
@@ -0,0 +1,61 @@
1
+ # Encyclopedia of Life API Wrapper
2
+
3
+ [![Build Status](https://travis-ci.org/itroman/eol.svg?branch=master)](https://travis-ci.org/itroman/eol)
4
+
5
+ ## Description
6
+
7
+ A wrapper for the Encyclopedia of Life API. It provides simple methods to call all of the available EOL API endpoints.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'eol'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install eol
24
+
25
+ ## Examples
26
+
27
+ #### Search for some orchids
28
+ ```ruby
29
+ # create a search
30
+ search = Eol.search("tolumnia")
31
+
32
+ # decide to modify the search
33
+ search = Eol.search("tolumnia", exact: true)
34
+
35
+ # print links to your results
36
+ search.each do |search|
37
+ puts search.link
38
+ end
39
+ ```
40
+ #### Make requests with or without options
41
+ ```ruby
42
+ # get collections
43
+ collections = Eol.collections("176")
44
+
45
+ # get sorted and cached collections
46
+ collections = Eol.collections('176', sort_by: 'oldest', cache_ttl: 30)
47
+ ```
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/itroman/eol. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
56
+
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
61
+
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task default: :spec
5
+ rescue LoadError
6
+ # rspec not available
7
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "eol"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eol/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "eol"
8
+ spec.version = Eol::VERSION
9
+ spec.authors = ["Rob Roman"]
10
+ spec.email = ["rob@romancoding.com"]
11
+
12
+ spec.summary = "A comprehensive Encyclopedia of Life API wrapper"
13
+ spec.description = "A wrapper for the Encyclopedia of Life API. It provides simple methods to call all of the available EOL API endpoints."
14
+ spec.homepage = "http://github.com/itroman/eol-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.required_ruby_version = '>= 2.0.0'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.6"
27
+ spec.add_development_dependency "vcr", "~> 3.0"
28
+ spec.add_development_dependency "webmock", "~> 3.0"
29
+ spec.add_development_dependency "rubocop", "~> 0.49.1"
30
+ spec.add_development_dependency "yard", "~> 0.9"
31
+ spec.add_development_dependency "simplecov", "~> 0.10"
32
+
33
+ spec.add_dependency "httparty", "~> 0.15"
34
+ end
@@ -0,0 +1,285 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'eol/version'
4
+ require_relative 'eol/search'
5
+ require_relative 'eol/ping'
6
+ require_relative 'eol/pages'
7
+ require_relative 'eol/collections'
8
+ require_relative 'eol/data_objects'
9
+ require_relative 'eol/hierarchy_entries'
10
+ require_relative 'eol/hierarchies'
11
+ require_relative 'eol/provider_hierarchies'
12
+ require_relative 'eol/search_by_provider'
13
+ require 'httparty'
14
+
15
+ # The Eol namespace holds all methods and classes that interact with the
16
+ # Encyclopedia of Life API.
17
+ module Eol
18
+ include HTTParty
19
+
20
+ base_uri 'eol.org/api'
21
+
22
+ # Pings the EOL API
23
+ #
24
+ # @see http://www.eol.org/api/docs/ping
25
+ # @example
26
+ # Eol.ping ==> #<Eol::Ping:0x000000027ffcb8 @message="Success">
27
+ # @return [Eol::Ping] Success or failure results
28
+ def self.ping
29
+ response = get('/ping/1.0.json')
30
+ response.code == 200 ? Eol::Ping.new(response['response']['message']) : bad_response(response)
31
+ end
32
+
33
+ # Returns one page of results from the EOL API search
34
+ #
35
+ # @see http://www.eol.org/api/docs/search
36
+ # @param [String] query The species you're looking for.
37
+ # @param [Hash] query_options
38
+ # @option query_options [Integer] :page a maximum of 30 results are returned
39
+ # per page. This parameter allows you to fetch more pages of results if
40
+ # there are more than 30 matches
41
+ # @option query_options [String] :exact will find taxon pages if the preferred
42
+ # name or any synonym or common name exactly matches the search term, `true`
43
+ # or `false`
44
+ # @option query_options [Integer] :filter_by_taxon_concept_id given an EOL
45
+ # page ID, search results will be limited to members of that taxonomic group
46
+ # @option query_options [Integer] :filter_by_hierarchy_entry_id given a
47
+ # Hierarchy Entry ID, search results will be limited to members of that
48
+ # taxonomic group
49
+ # @option query_options [String] :filter_by_string given a search term, an
50
+ # exact search will be made and that matching page will be used as the
51
+ # taxonomic group against which to filter search results
52
+ # @option query_options [Integer] :cache_ttl the number of seconds you wish to
53
+ # have the response cached
54
+ # @example
55
+ # Eol.search("dendrophylax", 'exact':true) ==> [#<Eol::Search:0x000000023e0a10 @id=37413, @title="Dendrophylax", @link= ...>]
56
+ # @return [Array<Eol::Search>]
57
+ def self.search(query, query_options = {})
58
+ @query = { q: query }.merge!(query_options)
59
+ response = get('/search/1.0.json', query: @query)
60
+ response.code == 200 ? response['results'].map { |item| Eol::Search.new(item) } : bad_response(response)
61
+ end
62
+
63
+ # Returns all results from an EOL API search
64
+ #
65
+ # @see http://www.eol.org/api/docs/search
66
+ # @param [String] query The species you're looking for.
67
+ # @note this method does not accept query options, for a more customized search
68
+ # use Eol.search
69
+ # @example
70
+ # Eol.search_all("dendrophylax") ==> [#<Eol::Search:0x000000023e0a10 @id=37413, @title="Dendrophylax", @link= ...>]
71
+ # @return (see search)
72
+ def self.search_all(query)
73
+ @query = { q: query }
74
+ response = get('/search/1.0.json', query: @query)
75
+ response.code == 200 ? all_pages(query, response) : bad_response(response)
76
+ end
77
+
78
+ # This method takes an EOL page identifier and returns the scientific name for
79
+ # that page, and optionally returns information about common names, media
80
+ # (text, images and videos), and references to the hierarchies which
81
+ # recognize the taxon described on the page.
82
+ #
83
+ # @see http://eol.org/api/docs/pages
84
+ # @param [String] id identifier for node in hierarchies which EOL indexes
85
+ # @param [Hash] query_options
86
+ # @option query_options [Boolean] :batch (False) returns either a batch or not
87
+ # @option query_options [0-75] :images_per_page limits the number of returned
88
+ # image objects
89
+ # @option query_options [Integer] :images_page (1) images page
90
+ # @option query_options [0-75] :videos_per_page limits the number of returned
91
+ # @option query_options [Integer] :videos_page (1) videos page
92
+ # @option query_options [0-75] :sounds_per_page limits the number of returned
93
+ # @option query_options [Integer] :sounds_page (1) sounds page
94
+ # @option query_options [0-75] :maps_per_page limits the number of returned
95
+ # @option query_options [Integer] :maps_page (1) maps page
96
+ # @option query_options [0-75] :texts_per_page limites the number of returned
97
+ # @option query_options [Integer] :texts_page (1) texts page
98
+ # @option query_options [String] :subjects
99
+ # 'overview' to return the overview text (if exists), a pipe | delimited
100
+ # list of subject names from the list of EOL accepted subjects (e.g.
101
+ # TaxonBiology, FossilHistory), or 'all' to get text in any subject.
102
+ # options at: http://eol.org/info/toc_subjects
103
+ # @option query_options [cc-by, cc-by-nc, cc-by-sa, cc-by-nc-sa, pd [public
104
+ # domain], na [not applicable], all] :license (all) a pipe | delimited
105
+ # list of licenses or 'all' to get objects under any license. Licenses
106
+ # abbreviated cc- are all Creative Commons licenses.
107
+ # @option query_options [Boolean] :details (false) include all metadata for
108
+ # data objects
109
+ # @option query_options [Boolean] :common_names (false) return all common
110
+ # names for the page's taxon
111
+ # @option query_options [Boolean] :synonyms (false) return all synonyms for
112
+ # the page's taxon
113
+ # @option query_options [Boolean] :references (false) return all references
114
+ # for the page's taxon
115
+ # @option query_options [Boolean] :taxonomy (true) return any taxonomy details
116
+ # from different taxon hierarchy providers, in an array named
117
+ # "taxonConcepts"
118
+ # @option query_options [0,1,2,3,4] :vetted (0) If 'vetted' is given a value
119
+ # of '1', then only trusted content will be returned. If 'vetted' is '2',
120
+ # then only trusted and unreviewed content will be returned (untrusted
121
+ # content will not be returned). If 'vetted' is '3', then only unreviewed
122
+ # content will be returned. If 'vetted' is '4', then only untrusted content
123
+ # will be returned.The default is to return all content.
124
+ # @option query_options [Integer] :cache_ttl the number of seconds you wish to
125
+ # have the response cached
126
+ # @option query_options [ms, de, en, es, fr, gl, it, nl, nb, oc, pt-BR, sv,
127
+ # tl, mk, sr, uk, ar, zh-Hans, zh-Hant, ko] :language (en) provides the
128
+ # results in the specified language.
129
+ # @example
130
+ # Eol.pages('1045608', images_per_page: 10, cache_ttl: 30) ==> #<Eol::Pages:0x00000001024058 @scientific_name="Apis mellifera Linnaeus 1758"...>
131
+ # @return <Eol::Pages>
132
+ def self.pages(id, query_options = {})
133
+ @query = { id: id }.merge!(query_options)
134
+ response = get('/pages/1.0.json', query: @query)
135
+ response.code == 200 ? Eol::Pages.new(response) : bad_response(response)
136
+ end
137
+
138
+ # Given the identifier for a collection this API will return all metadata
139
+ # about the collection and the items it contains.
140
+ #
141
+ # @see http://eol.org/api/docs/collections
142
+ # @param [Integer] id any integer
143
+ # @param [Hash] query_options
144
+ # @option query_options [Integer] :page (1) fetches page of results
145
+ # @option query_options [0-500] :per_page (50) sets number of results per page
146
+ # @option query_options [articles, collections, communities, images, sounds,
147
+ # taxa, users, video] :filter filters search results
148
+ # @option query_options [recently_added, oldest, alphabetical,
149
+ # reverse_alphabetical, richness, rating, sort_field, reverse_sort_field]
150
+ # :sort_by (recently_added) sorts results
151
+ # @option query_options [String] :sort_field If a sort_field parameter is
152
+ # included, only collection items whose sort field exactly matches the given
153
+ # string will be returned
154
+ # @option query_options [Integer] :cache_ttl the number of seconds you wish to
155
+ # have the response cached
156
+ # @option query_options [ms, de, en, es, fr, gl, it, nl, nb, oc, pt-BR, sv,
157
+ # tl, mk, sr, uk, ar, zh-Hans, zh-Hant, ko] :language (en) provides the
158
+ # results in the specified language.
159
+ # @example
160
+ # Eol.collections('176', sort_by: 'oldest', cache_ttl: 30) ==> #<Eol::Collections:0x0000000147d078 @name="EOL Group on Flickr", @description="This group...>
161
+ # @return <Eol::Collections>
162
+ def self.collections(id, query_options = {})
163
+ @query = { id: id }.merge!(query_options)
164
+ response = get('/collections/1.0.json', query: @query)
165
+ response.code == 200 ? Eol::Collections.new(response) : bad_response(response)
166
+ end
167
+
168
+ # Given the identifier for a data object this API will return all metadata
169
+ # about the object as submitted to EOL by the contributing content partner
170
+ #
171
+ # @see http://eol.org/api/docs/data_objects
172
+ # @param [String] id the ID parameter can either be an integer (a DataObject
173
+ # version ID) or a 16 character GUID which will return the latest version of
174
+ # that object
175
+ # @param [Hash] query_options
176
+ # @option query_options [Boolean] :taxonomy (true) return any taxonomy details
177
+ # from different taxon hierarchy providers, in an array named
178
+ # "taxonConcepts"
179
+ # @option query_options [Integer] :cache_ttl the number of seconds you wish to
180
+ # have the response cached
181
+ # @opation query_options [ms, de, en, es, fr, gl, it, nl, nb, oc, pt-BR, sv,
182
+ # tl, mk, sr, uk, ar, zh-Hans, zh-Hant, ko] :language (en) provides the
183
+ # results in the specified language
184
+ # @example
185
+ # Eol.data_objects('30073527', language: 'it', cache_ttl: 30) ==> #<Eol::DataObjects:0x00000000fc75b0 @identifier=1045608...>
186
+ # @return <Eol::DataObjects>
187
+ def self.data_objects(id, query_options = {})
188
+ @query = { id: id }.merge!(query_options)
189
+ response = get('/data_objects/1.0.json', query: @query)
190
+ response.code == 200 ? Eol::DataObjects.new(response) : bad_response(response)
191
+ end
192
+
193
+ # Gives access to a single hierarchy and its internal relationships
194
+ #
195
+ # @see http://eol.org/api/docs/hierarchy_entries
196
+ # @param [Integer] id any integer
197
+ # @param [Hash] query_options
198
+ # @option query_options [Boolean] :common_names (false) return all common
199
+ # names for this taxon
200
+ # @option query_options [Boolean] :synonyms (false) return all synonyms for
201
+ # this taxon
202
+ # @option query_options [Integer] :cache_ttl the number of seconds you wish to
203
+ # have the response cached
204
+ # @option query_options [ms, de, en, es, fr, gl, it, nl, nb, oc, pt-BR, sv,
205
+ # tl, mk, sr, uk, ar, zh-Hans, zh-Hant, ko] :language (en) provides the
206
+ # results in the specified language
207
+ # @example
208
+ # Eol.hierarchy_entries('30408282', common_names: true) ==> #<Eol::HierarchyEntries:0x000000015b8c08 @source_identifier="taxon:142651"...>
209
+ # @return <Eol::HierarchyEntries>
210
+ def self.hierarchy_entries(id, query_options = {})
211
+ @query = { id: id }.merge!(query_options)
212
+ response = get('/hierarchy_entries/1.0.json', query: @query)
213
+ response.code == 200 ? Eol::HierarchyEntries.new(response) : bad_response(response)
214
+ end
215
+
216
+ # Lists metadata about a hierarchy such as the provider name and source URL,
217
+ # as well as lists all the taxa which are the root taxa of the taxonomic tree
218
+ #
219
+ # @see http://eol.org/api/docs/hierarchies
220
+ # @param [Integer] id any integer
221
+ # @param [Hash] query_options
222
+ # @option query_options [Integer] :cache_ttl the number of seconds you wish to
223
+ # have the response cached
224
+ # @option query_options [ms, de, en, es, fr, gl, it, nl, nb, oc, pt-BR, sv,
225
+ # tl, mk, sr, uk, ar, zh-Hans, zh-Hant, ko] :language (en) provides the
226
+ # results in the specified language
227
+ # @example
228
+ # Eol.hierarchies('1188', language: 'de', cache_ttl: 30) ==> #<Eol::Hierarchies:0x000000015e7a08 @title="Species 2000 & ITIS Catalogue of Life: April 2013"...>
229
+ # @return <Eol::Hierarchies>
230
+ def self.hierarchies(id, query_options = {})
231
+ @query = { id: id }.merge!(query_options)
232
+ response = get('/hierarchies/1.0.json', query: @query)
233
+ response.code == 200 ? Eol::Hierarchies.new(response) : bad_response(response)
234
+ end
235
+
236
+ # This method will return references to all hierarchies supplied by EOL
237
+ # Content Partners. The response will include the label of the hierarchy and
238
+ # the EOL unique ID representing the hierarchy
239
+ #
240
+ # @see http://eol.org/api/docs/provider_hierarchies
241
+ # @example
242
+ # Eol.provider_hierarchies ==> [#<Eol::ProviderHierarchies:0x000000016080f0 @id=121, @label="AntWeb (Ant Species)">...]
243
+ # @return [Array<Eol::ProviderHierarchies>]
244
+ def self.provider_hierarchies
245
+ response = get('/provider_hierarchies/1.0.json')
246
+ response.code == 200 ? response.map { |item| Eol::ProviderHierarchies.new(item) } : bad_response(response)
247
+ end
248
+
249
+ # This method takes an integer or string which is the unique identifier for a
250
+ # taxon from some provider's database, and a hierarchy_id which represents the
251
+ # provider and returns the EOL page ID for that taxon.
252
+ #
253
+ # @see http://eol.org/api/docs/search_by_provider
254
+ # @param [String] id any string
255
+ # @param [Integer] hierarchy_id the ID of the provider's hierarchy you are
256
+ # searching within.
257
+ # @param [Hash] query_options
258
+ # @option query_options [Boolean] :batch (false) returns either a batch or not
259
+ # @option query_options [Integer] :cache_ttl the number of seconds you wish to
260
+ # have the response cached
261
+ # @example
262
+ # Eol.search_by_provider('180542', 903) ==> [#<Eol::SearchByProvider:0x000000022bf3c0 @eol_page_id=328580>, #<Eol::SearchByProvider:0x000000022bf398...>]
263
+ # @return [Array<Eol::SearchByProvider>]
264
+ def self.search_by_provider(id, hierarchy_id, query_options = {})
265
+ @query = { id: id, hierarchy_id: hierarchy_id }.merge!(query_options)
266
+ response = get('/search_by_provider/1.0.json?', query: @query)
267
+ response.code == 200 ? response.map { |item| Eol::SearchByProvider.new(item) } : bad_response(response)
268
+ end
269
+
270
+ def self.all_pages(query, response)
271
+ @n = 0
272
+ total = (response['totalResults'] / 30.to_f).ceil
273
+ total.times.collect {
274
+ response = get('/search/1.0.json', query: { q: query, page: (@n += 1) })
275
+ response['results'].map { |item| Eol::Search.new(item) }
276
+ }.flatten
277
+ end
278
+
279
+ def self.bad_response(response)
280
+ raise Error, "Error code #{response.code}" if response.class == HTTParty::Response
281
+ raise StandardError, 'Unknown Error'
282
+ end
283
+
284
+ private_class_method :all_pages, :bad_response
285
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eol
4
+ # Contains metadata about the collection and the items it contains
5
+ class Collections
6
+ include Enumerable
7
+ # @return [String] collections name
8
+ attr_accessor :name
9
+ # @return [String] collections description
10
+ attr_accessor :description
11
+ # @return [String] a hyperlink to the logo
12
+ attr_accessor :logo_url
13
+ # @return [String] created timestamp
14
+ attr_accessor :created
15
+ # @return [String] modified timestamp
16
+ attr_accessor :modified
17
+ # @return [Integer] total collections items
18
+ attr_accessor :total_items
19
+ # @return [Array] an Array of Hashes
20
+ attr_accessor :item_types
21
+ # @return [Array] an Array of Hashes
22
+ attr_accessor :collection_items
23
+
24
+ def initialize(response)
25
+ self.name = response['name']
26
+ self.description = response['description']
27
+ self.logo_url = response['logo_url']
28
+ self.created = response['created']
29
+ self.modified = response['modified']
30
+ self.total_items = response['total_items']
31
+ self.item_types = response['item_types']
32
+ self.collection_items = response['collection_items']
33
+ end
34
+
35
+ def each
36
+ yield @name
37
+ yield @description
38
+ yield @logo_url
39
+ yield @created
40
+ yield @modified
41
+ yield @total_items
42
+ yield @item_types
43
+ yield @collection_items
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eol
4
+ # Contains all metadata about the object as submitted to EOL by the
5
+ # contributing content partner.
6
+ class DataObjects
7
+ include Enumerable
8
+ # @return [Integer] an identifier number
9
+ attr_accessor :identifier
10
+ # @return [String]the binomial nomenclature in zoology
11
+ attr_accessor :scientific_name
12
+ # @return [FalseClass or TrueClass] status of exemplar
13
+ attr_accessor :exemplar
14
+ # @return [Integer]
15
+ # EOL has developed a 'Richness Score' for taxon pages which provides a
16
+ # simple summary number for comparing the amount of information available
17
+ # for different pages.
18
+ # @see http://eol.org/info/521
19
+ attr_accessor :richness_score
20
+ # @return [Array] An Array of Hashes
21
+ attr_accessor :taxon_concepts
22
+ # @return [Array] An Array of Hashes
23
+ attr_accessor :data_objects
24
+
25
+ def initialize(response)
26
+ self.identifier = response['identifier']
27
+ self.scientific_name = response['scientificName']
28
+ self.exemplar = response['exemplar']
29
+ self.richness_score = response['richness_score']
30
+ self.taxon_concepts = response['taxonConcepts']
31
+ self.data_objects = response['dataObjects']
32
+ end
33
+
34
+ def each
35
+ yield @identifier
36
+ yield @scientific_name
37
+ yield @exemplar
38
+ yield @richness_score
39
+ yield @taxon_concepts
40
+ yield @data_objects
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eol
4
+ # Contains metadata about a hierarchy such as the provider name and source URL,
5
+ # as well as lists all the taxa which are the root taxa of the taxonomic tree
6
+ class Hierarchies
7
+ include Enumerable
8
+ # @return [String] the Hierarchies title
9
+ attr_accessor :title
10
+ # @return [String] the name of the Hierarchies contributor
11
+ attr_accessor :contributor
12
+ # @return [String] date of submission
13
+ attr_accessor :date_submitted
14
+ # @return [String] the Hierarchies source
15
+ attr_accessor :source
16
+ # @return [Array] An Array of Hashes
17
+ attr_accessor :roots
18
+
19
+ def initialize(response)
20
+ self.title = response['title']
21
+ self.contributor = response['contributor']
22
+ self.date_submitted = response['dateSubmitted']
23
+ self.source = response['source']
24
+ self.roots = response['roots']
25
+ end
26
+
27
+ def each
28
+ yield @title
29
+ yield @contributor
30
+ yield @date_submitted
31
+ yield @source
32
+ yield @roots
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eol
4
+ # Contains data on a single hierarchy and its internal relationships
5
+ class HierarchyEntries
6
+ include Enumerable
7
+ # @return [String]
8
+ attr_accessor :source_identifier
9
+ # @return [Integer]
10
+ attr_accessor :parent_name_usage_id
11
+ # @return [Integer]
12
+ attr_accessor :taxon_concept_id
13
+ # @return [String] binomial nomenclature in zoology
14
+ attr_accessor :scientific_name
15
+ # @return [String] a link
16
+ attr_accessor :source
17
+ # @return [Array]
18
+ attr_accessor :name_according_to
19
+ # @return [Array]
20
+ attr_accessor :vernacular_names
21
+ # @return [Array]
22
+ attr_accessor :synonyms
23
+ # @return [Array]
24
+ attr_accessor :ancestors
25
+ # @return [Array]
26
+ attr_accessor :children
27
+
28
+ def initialize(response)
29
+ self.source_identifier = response['sourceIdentifier']
30
+ self.parent_name_usage_id = response['parentNameUsageID']
31
+ self.taxon_concept_id = response['taxonConceptID']
32
+ self.scientific_name = response['scientificName']
33
+ self.source = response['source']
34
+ self.name_according_to = response['nameAccordingTo']
35
+ self.vernacular_names = response['vernacularNames']
36
+ self.synonyms = response['synonyms']
37
+ self.ancestors = response['ancestors']
38
+ self.children = response['children']
39
+ end
40
+
41
+ def each
42
+ yield @source_identifier
43
+ yield @parent_name_usage_id
44
+ yield @taxon_concept_id
45
+ yield @scientific_name
46
+ yield @source
47
+ yield @name_according_to
48
+ yield @vernacular_names
49
+ yield @synonyms
50
+ yield @ancestors
51
+ yield @children
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eol
4
+ # Contains returns the scientific name for that page, and optionally contains
5
+ # information about common names, media (text, images and videos),
6
+ # and references to the hierarchies which recognize the taxon described on
7
+ # the page.
8
+ class Pages
9
+ include Enumerable
10
+ # @return [String] binomial nomenclature in zoology
11
+ attr_accessor :scientific_name
12
+ # @return [Integer]
13
+ # EOL has developed a 'Richness Score' for taxon pages which provides a
14
+ # simple summary number for comparing the amount of information available
15
+ # for different pages.
16
+ # @see http://eol.org/info/521
17
+ attr_accessor :richness_score
18
+ # @return [Array] an Array of Hashes
19
+ attr_accessor :taxon_concepts
20
+ # @return [Array] an Array of Hashes
21
+ attr_accessor :data_objects
22
+
23
+ def initialize(response)
24
+ self.scientific_name = response['scientificName']
25
+ self.richness_score = response['richness_score']
26
+ self.taxon_concepts = response['taxonConcepts']
27
+ self.data_objects = response['dataObjects']
28
+ end
29
+
30
+ def each
31
+ yield @scientific_name
32
+ yield @richness_score
33
+ yield @taxon_concepts
34
+ yield @data_objects
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eol
4
+ # Contains response message indicating API status
5
+ class Ping
6
+ # @return [String] success or failure message
7
+ attr_accessor :message
8
+
9
+ def initialize(response)
10
+ self.message = response
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eol
4
+ # Contains references to all hierarchies supplied by EOL Content Partners.
5
+ class ProviderHierarchies
6
+ include Enumerable
7
+ # @return [Integer]
8
+ attr_accessor :id
9
+ # @return [String]
10
+ attr_accessor :label
11
+
12
+ def initialize(response)
13
+ self.id = response['id']
14
+ self.label = response['label']
15
+ end
16
+
17
+ def each
18
+ yield @id
19
+ yield @label
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eol
4
+ # Contains search results from the Encyclopedia of Life database.
5
+ class Search
6
+ include Enumerable
7
+ # @return [Integer] the id of the species
8
+ attr_accessor :id
9
+ # @return [String] title of the entry
10
+ attr_accessor :title
11
+ # @return [String] link to article on the EOL homepage
12
+ attr_accessor :link
13
+ # @return [String] classification content
14
+ attr_accessor :content
15
+
16
+ def initialize(response)
17
+ self.id = response['id']
18
+ self.title = response['title']
19
+ self.link = response['link']
20
+ self.content = response['content']
21
+ end
22
+
23
+ def each
24
+ yield @id
25
+ yield @title
26
+ yield @link
27
+ yield @content
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eol
4
+ # Contains the EOL page ID and link for taxon queried.
5
+ class SearchByProvider
6
+ include Enumerable
7
+ # @return [Integer]
8
+ attr_accessor :eol_page_id
9
+ # @return [String]
10
+ attr_accessor :eol_page_link
11
+
12
+ def initialize(response)
13
+ self.eol_page_id = response['eol_page_id'] if response['eol_page_id'] != nil
14
+ self.eol_page_link = response['eol_page_link'] if response['eol_page_link'] != nil
15
+ end
16
+
17
+ def each
18
+ yield @eol_page_id
19
+ yield @eol_page_link
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eol
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eol
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rob Roman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-21 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: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.49.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.49.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.9'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.10'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.10'
125
+ - !ruby/object:Gem::Dependency
126
+ name: httparty
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.15'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.15'
139
+ description: A wrapper for the Encyclopedia of Life API. It provides simple methods
140
+ to call all of the available EOL API endpoints.
141
+ email:
142
+ - rob@romancoding.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".travis.yml"
149
+ - CODE_OF_CONDUCT.md
150
+ - Gemfile
151
+ - LICENSE.txt
152
+ - README.md
153
+ - Rakefile
154
+ - bin/console
155
+ - bin/setup
156
+ - eol.gemspec
157
+ - lib/eol.rb
158
+ - lib/eol/collections.rb
159
+ - lib/eol/data_objects.rb
160
+ - lib/eol/hierarchies.rb
161
+ - lib/eol/hierarchy_entries.rb
162
+ - lib/eol/pages.rb
163
+ - lib/eol/ping.rb
164
+ - lib/eol/provider_hierarchies.rb
165
+ - lib/eol/search.rb
166
+ - lib/eol/search_by_provider.rb
167
+ - lib/eol/version.rb
168
+ homepage: http://github.com/itroman/eol-ruby
169
+ licenses:
170
+ - MIT
171
+ metadata: {}
172
+ post_install_message:
173
+ rdoc_options: []
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: 2.0.0
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubyforge_project:
188
+ rubygems_version: 2.5.1
189
+ signing_key:
190
+ specification_version: 4
191
+ summary: A comprehensive Encyclopedia of Life API wrapper
192
+ test_files: []