diff --git a/lib/plants/client.rb b/lib/plants/client.rb index b7f2018..f1b6010 100644 --- a/lib/plants/client.rb +++ b/lib/plants/client.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true require 'http' +require 'plants/config' require 'plants/version' +require 'plants/client/resource' module Plants # HTTP Client @@ -10,11 +12,13 @@ module Plants # @return [Plants::Config] # class Client - # Trefle API URL - URL = "https://trefle.io/api/v1".freeze + include Resource + + # @return [String] Trefle API URL + URL = 'https://trefle.io/api/v1' # @param config [Plants::Config] - def initialize(config) + def initialize(config = Config.new) @config = config end attr_reader :config @@ -24,7 +28,7 @@ def initialize(config) # @param params [Hash] # @return [HTTP::Response] def get(resource, params: {}) - params.merge({ token: config.token }) if config.token.is_a?(String) + params.merge({ token: config.token }) if config.token http.get("#{URL}/#{resource}", params: params) end @@ -34,7 +38,7 @@ def get(resource, params: {}) def http HTTP .timeout(5) - .headers({ 'User-Agent' => "Plants #{Plants::VERSION} ruby-#{RUBY_VERSION}" }) + .headers({ 'User-Agent' => "Plants #{::Plants::VERSION} ruby-#{RUBY_VERSION}" }) end end end \ No newline at end of file diff --git a/lib/plants/client/resource.rb b/lib/plants/client/resource.rb new file mode 100644 index 0000000..3e2ce3f --- /dev/null +++ b/lib/plants/client/resource.rb @@ -0,0 +1,10 @@ +require 'plants/client/resource/plants' + +module Plants + class Client + # Resource 'container' module + module Resource + include Plants + end + end +end \ No newline at end of file diff --git a/lib/plants/client/resource/plants.rb b/lib/plants/client/resource/plants.rb new file mode 100644 index 0000000..78ea53c --- /dev/null +++ b/lib/plants/client/resource/plants.rb @@ -0,0 +1,14 @@ +module Plants + class Client + module Resource + # Plants resource + module Plants + # GET /plants + # @return [HTTP::Response] + def plants + get('plants') + end + end + end + end +end \ No newline at end of file