Class: QTimetrap::Services::TimetrapGateway

Inherits:
Object
  • Object
show all
Includes:
TimetrapGatewayQueryHelpers, TimetrapGatewayStartHelpers, TimetrapGatewayUpdateNoteHelpers, TimetrapGatewayUpdateTaskHelpers, TimetrapGatewayUpdateTimeHelpers
Defined in:
app/services/timetrap_gateway.rb

Overview

Integrates with Timetrap via Ruby API or CLI fallback.

Instance Method Summary collapse

Methods included from TimetrapGatewayUpdateNoteHelpers

#update_note

Methods included from TimetrapGatewayUpdateTimeHelpers

#update_time

Methods included from TimetrapGatewayUpdateTaskHelpers

#update_task

Constructor Details

#initialize(bin: ENV.fetch('TIMETRAP_BIN', 't'), logger: TimetrapGatewayLogger.new) ⇒ TimetrapGateway

Returns a new instance of TimetrapGateway.



22
23
24
25
# File 'app/services/timetrap_gateway.rb', line 22

def initialize(bin: ENV.fetch('TIMETRAP_BIN', 't'), logger: TimetrapGatewayLogger.new)
  @bin = bin
  @logger = logger
end

Instance Method Details

#active_started_atObject



38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/timetrap_gateway.rb', line 38

def active_started_at
  if api_available?
    logger.log_api(operation: 'active_started_at', input: {}, output: 'requested')
    result = active_started_at_from_api
    logger.log_api(operation: 'active_started_at', input: {}, output: result&.iso8601)
    return result
  end

  _active, started_at = active_from_cli
  started_at
end

#entriesObject



27
28
29
30
31
32
33
34
35
36
# File 'app/services/timetrap_gateway.rb', line 27

def entries
  if api_available?
    logger.log_api(operation: 'entries', input: {}, output: 'requested')
    result = entries_from_api
    logger.log_api(operation: 'entries', input: {}, output: { count: result.size })
    return result
  end

  entries_from_cli
end

#start(sheet, checkin_note = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/services/timetrap_gateway.rb', line 50

def start(sheet, checkin_note = nil)
  normalized_sheet, normalized_checkin_note = normalize_start_inputs(sheet, checkin_note)
  return if normalized_sheet.empty?

  if api_available?
    logger.log_api(
      operation: 'start',
      input: { sheet: normalized_sheet, checkin_note: normalized_checkin_note },
      output: 'requested'
    )
    result = start_via_api(normalized_sheet, normalized_checkin_note)
    logger.log_api(operation: 'start', input: {}, output: result.to_s)
    return result
  end

  start_via_cli(normalized_sheet, normalized_checkin_note)
end

#stopObject



68
69
70
71
72
73
74
75
76
77
78
# File 'app/services/timetrap_gateway.rb', line 68

def stop
  if api_available?
    logger.log_api(operation: 'stop', input: {}, output: 'requested')
    active = Timetrap::Timer.active_entry
    Timetrap::Timer.stop(active) if active
    logger.log_api(operation: 'stop', input: {}, output: active ? 'stopped' : 'noop')
    return
  end

  run('out')
end