Class: Taxa::EOLClassic::Client
- Inherits:
-
Object
- Object
- Taxa::EOLClassic::Client
- Defined in:
- lib/taxa/eol_classic/client.rb
Overview
API client for Open Tree of Life
Instance Attribute Summary collapse
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #collections(id, **parameters) ⇒ Object
- #data_objects(id, **parameters) ⇒ Object
- #hierarchy_entries(id, **parameters) ⇒ Object
-
#initialize(**options) ⇒ Client
constructor
A new instance of Client.
- #pages(id, **parameters) ⇒ Object
- #search(query, **parameters) ⇒ Object
Constructor Details
#initialize(**options) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 |
# File 'lib/taxa/eol_classic/client.rb', line 10 def initialize(**) @options = @http_client = [:http_client] || Faraday.new end |
Instance Attribute Details
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
8 9 10 |
# File 'lib/taxa/eol_classic/client.rb', line 8 def http_client @http_client end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/taxa/eol_classic/client.rb', line 7 def @options end |
Instance Method Details
#collections(id, **parameters) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/taxa/eol_classic/client.rb', line 24 def collections(id, **parameters) raise ArgumentError, 'id can not be nil' if id.nil? url = "https://eol.org/api/collections/1.0/#{id}.json" response = @http_client.get(url, parameters, { 'Accept' => 'application/json' }) parse_response(response) end |
#data_objects(id, **parameters) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/taxa/eol_classic/client.rb', line 40 def data_objects(id, **parameters) raise ArgumentError, 'id can not be nil' if id.nil? url = "https://eol.org/api/data_objects/1.0/#{id}.json" response = @http_client.get(url, parameters, { 'Accept' => 'application/json' }) parse_response(response) end |
#hierarchy_entries(id, **parameters) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/taxa/eol_classic/client.rb', line 48 def hierarchy_entries(id, **parameters) raise ArgumentError, 'id can not be nil' if id.nil? url = "https://eol.org/api/hierarchy_entries/1.0/#{id}.json" response = @http_client.get(url, parameters, { 'Accept' => 'application/json' }) parse_response(response) end |
#pages(id, **parameters) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/taxa/eol_classic/client.rb', line 32 def pages(id, **parameters) raise ArgumentError, 'id can not be nil' if id.nil? url = "https://eol.org/api/pages/1.0/#{id}.json" response = @http_client.get(url, parameters, { 'Accept' => 'application/json' }) parse_response(response) end |
#search(query, **parameters) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/taxa/eol_classic/client.rb', line 16 def search(query, **parameters) raise ArgumentError, 'query can not be nil' if query.nil? url = 'https://eol.org/api/search/1.0.json' response = @http_client.get(url, { q: query }.merge(parameters), { 'Accept' => 'application/json' }) parse_response(response) end |