class Abt::Providers::Harvest::Commands::Stop

Public Class Methods

description() click to toggle source
# File lib/abt/providers/harvest/commands/stop.rb, line 12
def self.description
  "Stop running harvest tracker"
end
usage() click to toggle source
# File lib/abt/providers/harvest/commands/stop.rb, line 8
def self.usage
  "abt stop harvest"
end

Public Instance Methods

perform() click to toggle source
# File lib/abt/providers/harvest/commands/stop.rb, line 16
def perform
  abort("No running time entry") if time_entry.nil?

  stop_time_entry

  warn("Harvest time entry stopped")
  print_task(project, task)
end

Private Instance Methods

project() click to toggle source
# File lib/abt/providers/harvest/commands/stop.rb, line 34
def project
  time_entry["project"]
end
stop_time_entry() click to toggle source
# File lib/abt/providers/harvest/commands/stop.rb, line 27
def stop_time_entry
  api.patch("time_entries/#{time_entry['id']}/stop")
rescue Abt::HttpError::HttpError => e
  warn(e)
  abort("Unable to stop time entry")
end
task() click to toggle source
# File lib/abt/providers/harvest/commands/stop.rb, line 38
def task
  time_entry["task"]
end
time_entry() click to toggle source
# File lib/abt/providers/harvest/commands/stop.rb, line 42
def time_entry
  @time_entry ||= begin
    api.get_paged(
      "time_entries",
      is_running: true,
      user_id: config.user_id
    ).first
  rescue Abt::HttpError::HttpError => e
    warn(e)
    abort("Unable to fetch running time entry")
  end
end