diff --git a/lib/plants.rb b/lib/plants.rb index 3b93971..7716c0e 100644 --- a/lib/plants.rb +++ b/lib/plants.rb @@ -5,4 +5,30 @@ require "plants/version" module Plants + class << self + + # @param new_value [String] + # @return [void] + def token=(new_value) + client.config.token = new_value + end + + # @return [Plants::Config] + def config + client.config + end + + # GET /plants + # @return [HTTP::Response] + def plants + client.plants + end + + private + + # @return [Plants::Client] + def client + @_client ||= Client.new + end + end end diff --git a/spec/plants_spec.rb b/spec/plants_spec.rb index b97330a..d8145bd 100644 --- a/spec/plants_spec.rb +++ b/spec/plants_spec.rb @@ -4,4 +4,37 @@ it "has a version number" do expect(Plants::VERSION).not_to be nil end + + describe '.token=' do + after(:each) { Plants.token = nil } + + subject { Plants.token = 'secret' } + + it do + subject + expect(Plants.config.token).to eql 'secret' + end + end + + describe '.config' do + subject { Plants.config } + + it do + expect(subject).to be_instance_of(Plants::Config) + end + end + + describe '.plants' do + before(:each) do + stub_request(:get, "#{Plants::Client::URL}/plants") + .to_return(status: 200, body: '{}') + end + + subject { Plants.plants } + + it do + expect(subject).to be_instance_of(HTTP::Response) + expect(a_request(:get, "#{Plants::Client::URL}/plants")).to have_been_made + end + end end