From 6a5e03f20b18cc5387605d4c889d8240e2740c02 Mon Sep 17 00:00:00 2001 From: Juan Vasquez Date: Fri, 20 Jan 2023 23:45:52 -0600 Subject: [PATCH] feat(entry): Add new entry Closes #2 --- Gemfile.lock | 2 +- exe/noko_cli | 2 +- lib/noko_cli/config.rb | 16 ++++++++++++++++ lib/noko_cli/entries.rb | 13 ++++++------- lib/noko_cli/run.rb | 10 ++++++++++ spec/noko_cli/entries_spec.rb | 3 ++- 6 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 lib/noko_cli/config.rb create mode 100644 lib/noko_cli/run.rb diff --git a/Gemfile.lock b/Gemfile.lock index 4b20e74..a9c58b3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -103,4 +103,4 @@ DEPENDENCIES rubocop-rspec (~> 2.20.0) BUNDLED WITH - 2.3.26 + 2.4.4 diff --git a/exe/noko_cli b/exe/noko_cli index 1bb88c2..a8105a7 100755 --- a/exe/noko_cli +++ b/exe/noko_cli @@ -3,4 +3,4 @@ require "noko_cli" -NokoCli::Entries.new.list +NokoCli::Run.call diff --git a/lib/noko_cli/config.rb b/lib/noko_cli/config.rb new file mode 100644 index 0000000..327705e --- /dev/null +++ b/lib/noko_cli/config.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require "faraday" + +module NokoCli + class Config # :nodoc: + attr_reader :token, :url, :adapter, :stubs + + def initialize(adapter: Faraday.default_adapter, stubs: nil) + @token = ENV.fetch("NOKO_TOKEN", nil) + @url = "https://api.nokotime.com/v2" + @adapter = adapter + @stubs = stubs + end + end +end diff --git a/lib/noko_cli/entries.rb b/lib/noko_cli/entries.rb index 0221019..7ebf54b 100644 --- a/lib/noko_cli/entries.rb +++ b/lib/noko_cli/entries.rb @@ -6,12 +6,11 @@ module NokoCli # This is an entry resource, which could be listed class Entries - BASE_URL = "https://api.nokotime.com/v2" - NOKO_TOKEN = ENV.fetch("NOKO_TOKEN", nil) - - def initialize(adapter: Faraday.default_adapter, stubs: nil) - @adapter = adapter - @stubs = stubs + def initialize(config:) + @token = config.token + @url = config.url + @adapter = config.adapter + @stubs = config.stubs end def list @@ -21,7 +20,7 @@ def list private def conn - @conn ||= Faraday.new({ url: BASE_URL, params: { noko_token: NOKO_TOKEN } }) do |f| + @conn ||= Faraday.new({ url: @url, params: { noko_token: @token } }) do |f| unless @stubs f.request :json f.response :json, content_type: "application/json" diff --git a/lib/noko_cli/run.rb b/lib/noko_cli/run.rb new file mode 100644 index 0000000..b704880 --- /dev/null +++ b/lib/noko_cli/run.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module NokoCli + class Run # :nodoc: + def self.call + @config ||= Config.new + Entries.new(config: @config).list + end + end +end diff --git a/spec/noko_cli/entries_spec.rb b/spec/noko_cli/entries_spec.rb index cb99474..60ae94e 100644 --- a/spec/noko_cli/entries_spec.rb +++ b/spec/noko_cli/entries_spec.rb @@ -8,7 +8,8 @@ let(:stubs) do stub_request("current_user/entries", response: stub_response(fixture: "entries/list")) end - let(:entries) { described_class.new(adapter: :test, stubs: stubs) } + let(:config) { NokoCli::Config.new(adapter: :test, stubs: stubs) } + let(:entries) { described_class.new(config: config) } it "includes headers" do headers = /date |minutes |project |description/