diff --git a/lib/plants/resources.rb b/lib/plants/resources.rb index 6932259..e51679d 100644 --- a/lib/plants/resources.rb +++ b/lib/plants/resources.rb @@ -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 @@ -17,6 +18,7 @@ module Resources include Genus include Kingdoms include Plants + include Species include Subkingdoms end end \ No newline at end of file diff --git a/lib/plants/resources/species.rb b/lib/plants/resources/species.rb new file mode 100644 index 0000000..dc908f4 --- /dev/null +++ b/lib/plants/resources/species.rb @@ -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 diff --git a/spec/plants_spec.rb b/spec/plants_spec.rb index f5e6081..87ad8ff 100644 --- a/spec/plants_spec.rb +++ b/spec/plants_spec.rb @@ -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