Class: Taxa::EOLClassic::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/taxa/eol_classic/client.rb

Overview

API client for Open Tree of Life

Instance Attribute Summary collapse

Instance Method Summary collapse

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)
  @options = options

  @http_client = options[:http_client] || Faraday.new
end

Instance Attribute Details

#http_clientObject (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

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/taxa/eol_classic/client.rb', line 7

def options
  @options
end

Instance Method Details

#collections(id, **parameters) ⇒ Object

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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