diff --git a/lib/noko_cli/config.rb b/lib/noko_cli/config.rb index 327705e..7d8289d 100644 --- a/lib/noko_cli/config.rb +++ b/lib/noko_cli/config.rb @@ -4,13 +4,24 @@ module NokoCli class Config # :nodoc: - attr_reader :token, :url, :adapter, :stubs + attr_reader :adapter, :stubs, :token, :url - def initialize(adapter: Faraday.default_adapter, stubs: nil) - @token = ENV.fetch("NOKO_TOKEN", nil) - @url = "https://api.nokotime.com/v2" + def initialize(adapter: Faraday.default_adapter, stubs: nil, token: ENV.fetch("NOKO_TOKEN", nil)) @adapter = adapter @stubs = stubs + @token = token + @url = "https://api.nokotime.com/v2" + end + + def conn + @conn ||= + Faraday.new({ url: url, params: { noko_token: token } }) do |f| + unless stubs + f.request :json + f.response :json, content_type: "application/json" + end + f.adapter adapter, stubs + end end end end diff --git a/lib/noko_cli/entries.rb b/lib/noko_cli/entries.rb index 7ebf54b..b4c931a 100644 --- a/lib/noko_cli/entries.rb +++ b/lib/noko_cli/entries.rb @@ -1,16 +1,14 @@ # frozen_string_literal: true -require "faraday" require "tty-table" module NokoCli # This is an entry resource, which could be listed class Entries + attr_reader :conn + def initialize(config:) - @token = config.token - @url = config.url - @adapter = config.adapter - @stubs = config.stubs + @conn = config.conn end def list @@ -19,16 +17,6 @@ def list private - def conn - @conn ||= Faraday.new({ url: @url, params: { noko_token: @token } }) do |f| - unless @stubs - f.request :json - f.response :json, content_type: "application/json" - end - f.adapter @adapter, @stubs - end - end - def current_user_entries conn.get("current_user/entries").body end