Skip to content

Commit

Permalink
begin to plot out how resources will take shape
Browse files Browse the repository at this point in the history
  • Loading branch information
one-m1nd committed Feb 28, 2024
1 parent 9185a0a commit fd29638
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/plants/client.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true
require 'http'

require 'plants/config'
require 'plants/version'
require 'plants/client/resource'

module Plants
# HTTP Client
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
10 changes: 10 additions & 0 deletions lib/plants/client/resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'plants/client/resource/plants'

module Plants
class Client
# Resource 'container' module
module Resource
include Plants
end
end
end
14 changes: 14 additions & 0 deletions lib/plants/client/resource/plants.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fd29638

Please sign in to comment.