Sha256: c4ab696fecc62a72502030ccc4461bac87c1350fe310e84e0a4c03ffb8c9be2a
Contents?: true
Size: 1.04 KB
Versions: 1
Compression:
Stored size: 1.04 KB
Contents
# frozen_string_literal: true require "faraday" require "tty-table" 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 end def list puts TTY::Table.new(headers, rows).render(:ascii, resize: true) end private def conn @conn ||= Faraday.new({ url: BASE_URL, params: { noko_token: NOKO_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 def headers %w[date minutes description] end def rows current_user_entries.map { |entry| row(entry) } end def row(entry) [entry["date"], entry["minutes"], entry["description"]] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
noko_cli-0.1.2 | lib/noko_cli/entries.rb |