From dc9dc047af26f52b665ceaa06d608180c3ef21e4 Mon Sep 17 00:00:00 2001 From: Xero Date: Wed, 28 Feb 2024 14:47:38 -0500 Subject: [PATCH] subkingdoms endpoint --- lib/plants/resources.rb | 2 ++ lib/plants/resources/subkingdoms.rb | 19 +++++++++++++++++++ spec/plants_spec.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 lib/plants/resources/subkingdoms.rb diff --git a/lib/plants/resources.rb b/lib/plants/resources.rb index 89666a0..4c50360 100644 --- a/lib/plants/resources.rb +++ b/lib/plants/resources.rb @@ -2,6 +2,7 @@ require 'plants/resources/genus' require 'plants/resources/kingdoms' require 'plants/resources/plants' +require 'plants/resources/subkingdoms' module Plants # Resources 'container' module @@ -10,5 +11,6 @@ module Resources include Genus include Kingdoms include Plants + include Subkingdoms end end \ No newline at end of file diff --git a/lib/plants/resources/subkingdoms.rb b/lib/plants/resources/subkingdoms.rb new file mode 100644 index 0000000..eb5801e --- /dev/null +++ b/lib/plants/resources/subkingdoms.rb @@ -0,0 +1,19 @@ +module Plants + module Resources + # Subkingdoms module + # @see https://docs.trefle.io/reference#tag/Subkingdoms + module Subkingdoms + # GET /subkingdoms + # @return [::HTTP::Response] + def list_subkingdoms + client.get('subkingdoms') + end + + # @param kingdom [String] + # @return [::HTTP::Response] + def find_subkingdom(kingdom) + client.get("subkingdoms/#{kingdom}") + end + end + end +end \ No newline at end of file diff --git a/spec/plants_spec.rb b/spec/plants_spec.rb index 776ff5e..59a710b 100644 --- a/spec/plants_spec.rb +++ b/spec/plants_spec.rb @@ -179,4 +179,32 @@ expect(a_request(:get, "#{Plants::Client::URL}/kingdoms/foobar")).to have_been_made end end + + describe '.list_subkingdoms' do + before(:each) do + stub_request(:get, "#{Plants::Client::URL}/subkingdoms") + .to_return(status: 200, body: '{}') + end + + subject { Plants.list_subkingdoms } + + it do + expect(subject).to be_instance_of(HTTP::Response) + expect(a_request(:get, "#{Plants::Client::URL}/subkingdoms")).to have_been_made + end + end + + describe '.find_subkingdom' do + before(:each) do + stub_request(:get, "#{Plants::Client::URL}/subkingdoms/foobar") + .to_return(status: 200, body: '{}') + end + + subject { Plants.find_subkingdom('foobar') } + + it do + expect(subject).to be_instance_of(HTTP::Response) + expect(a_request(:get, "#{Plants::Client::URL}/subkingdoms/foobar")).to have_been_made + end + end end