Skip to content

Commit

Permalink
species endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
one-m1nd committed Feb 28, 2024
1 parent 34b9e3c commit 5167ac9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/plants/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'plants/resources/genus'
require 'plants/resources/kingdoms'
require 'plants/resources/plants'
require 'plants/resources/species'
require 'plants/resources/subkingdoms'

module Plants
Expand All @@ -17,6 +18,7 @@ module Resources
include Genus
include Kingdoms
include Plants
include Species
include Subkingdoms
end
end
25 changes: 25 additions & 0 deletions lib/plants/resources/species.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Plants
module Resources
# Species module
# @see https://docs.trefle.io/reference#tag/Species
module Species
# GET /species
# @return [::HTTP::Response]
def list_species
client.get('species')
end

# @param species [String]
# @return [::HTTP::Response]
def find_species(species)
client.get("species/#{species}")
end

# @param species [String]
# @return [::HTTP::Response]s
def search_for_species(species)
client.get("species/search", params: { q: species })
end
end
end
end
43 changes: 43 additions & 0 deletions spec/plants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,47 @@
expect(a_request(:get, "#{Plants::Client::URL}/division_orders/foobar")).to have_been_made
end
end

describe '.list_species' do
before(:each) do
stub_request(:get, "#{Plants::Client::URL}/species")
.to_return(status: 200, body: '{}')
end

subject { Plants.list_species }

it do
expect(subject).to be_instance_of(HTTP::Response)
expect(a_request(:get, "#{Plants::Client::URL}/species")).to have_been_made
end
end

describe 'find_species' do
before(:each) do
stub_request(:get, "#{Plants::Client::URL}/species/foobar")
.to_return(status: 200, body: '{}')
end

subject { Plants.find_species('foobar') }

it do
expect(subject).to be_instance_of(HTTP::Response)
expect(a_request(:get, "#{Plants::Client::URL}/species/foobar")).to have_been_made
end
end

describe '.search_for_species' do
before(:each) do
stub_request(:get, "#{Plants::Client::URL}/species/search")
.with(query: { q: 'foobar' })
.to_return(status: 200, body: '{}')
end

subject { Plants.search_for_species('foobar') }

it do
expect(subject).to be_instance_of(HTTP::Response)
expect(a_request(:get, "#{Plants::Client::URL}/species/search").with(query: { q: 'foobar' })).to have_been_made
end
end
end

0 comments on commit 5167ac9

Please sign in to comment.