Sha256: e3ef2df7e5bbe4ce9944ccae8023db49df59e38e7c80560f588f50ac140b4d03

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

require "awesome_print"
require "date"
require "value_semantics"

require 'luxafor'
require 'togglv8'

require "luxafor/toggl/version"
require "luxafor/toggl/client"
require "luxafor/toggl/state"

# As of Apr 2020, because of a 1/2 removed awesome print dep in the gem which hasnt been released.
# See https://github.com/kanet77/togglv8/issues/17
class Logger
  def ap(*args, **kwargs, &block)
    true
  end
end

module Luxafor
  module Toggl
    class Error < StandardError; end

    extend self

    EXPECTED_ERRORS = [
      # Filelock::ExecTimeout,
      # Filelock::WaitTimeout,
      # KeyError,
      # Oj::Error,
      # Oj::ParseError,
      # Oj::DepthError,
      # Oj::LoadError,
      # ValueSemantics::MissingAttributes,
    ].freeze

    attr_writer :toggl_key, :luxafor_key, :state_file, :idle_time

    def toggl_key
      @toggl_key || ENV.fetch('TOGGL_KEY')
    end

    def luxafor_key
      @luxafor_key || ENV.fetch('LUXAFOR_KEY')
    end

    def state_file
      @state ||= ENV.fetch("LUXAFOR_TOGGL_STATE_FILE", "/tmp/#{Etc.getpwuid(Process.euid).name}-luxafor-toggl-state.json")
    end

    def idle_time
      @idle_time ||= ENV.fetch("LUXAFOR_TOGGL_IDLE_TIME", 60 * 60 * 2).to_i # Default is 2 hours before you're idle
    end

    def toggl_client
      @toggl_client ||= TogglV8::API.new(toggl_key)
    end

    def luxafor_client
      @luxafor_client ||= Luxafor::Client.new(luxafor_key)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
luxafor-toggl-1.0.1 lib/luxafor/toggl.rb
luxafor-toggl-1.0.0 lib/luxafor/toggl.rb