Skip to content

Commit

Permalink
feat(entry): Add new entry
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
JuanVqz committed Sep 1, 2024
1 parent bc77e1f commit 6a5e03f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ DEPENDENCIES
rubocop-rspec (~> 2.20.0)

BUNDLED WITH
2.3.26
2.4.4
2 changes: 1 addition & 1 deletion exe/noko_cli
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

require "noko_cli"

NokoCli::Entries.new.list
NokoCli::Run.call
16 changes: 16 additions & 0 deletions lib/noko_cli/config.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 6 additions & 7 deletions lib/noko_cli/entries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions lib/noko_cli/run.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion spec/noko_cli/entries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit 6a5e03f

Please sign in to comment.