Class: Dovico::App

Inherits:
Object
  • Object
show all
Includes:
EasyAppHelper
Defined in:
lib/dovico/app.rb

Constant Summary collapse

NAME =
'Dovico Simple Client'
DESCRIPTION =
<<EOL
Simple client for Dovico TimeSheet web application.

Please refer to the README.md page to setup your client.

WARNING: --auto and --simulate options are not effective.
EOL

Instance Method Summary collapse

Constructor Details

#initializeApp

Returns a new instance of App.



17
18
19
20
21
22
23
24
25
# File 'lib/dovico/app.rb', line 17

def initialize
  config.config_file_base_name = 'dovico'
  config.describes_application app_name: NAME,
                               app_version: Dovico::VERSION,
                               app_description: DESCRIPTION
  add_script_options

  ApiClient.initialize!(config["client_token"], config["user_token"])
end

Instance Method Details

#add_script_optionsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dovico/app.rb', line 27

def add_script_options
  config.add_command_line_section('Display informations') do |slop|
    slop.on :myself, 'Display info on yourself', argument: false
    slop.on :tasks,  'Display info on tasks',    argument: false
  end
  config.add_command_line_section('Fill the timesheets') do |slop|
    slop.on :fill,         'Fill the timesheet', argument: false
  end
  config.add_command_line_section('Show the timesheets') do |slop|
    slop.on :show,         'Show the filled timesheets', argument: false
  end
  config.add_command_line_section('Submit the timesheets') do |slop|
    slop.on :submit,       'Submit timesheets', argument: false
  end
  config.add_command_line_section('Clear the timesheets') do |slop|
    slop.on :clear,        'Clear the timesheets', argument: false
  end
  config.add_command_line_section('Date options (required for --show, --fill, --submit and --clear)') do |slop|
    slop.on :current_week, 'Current week', argument: false
    slop.on :today,        'Current day',  argument: false
    slop.on :day,          'Specific day', argument: true
    slop.on :start,        'Specific start day', argument: true
    slop.on :end,          'Specific end day', argument: true
    slop.on :week,         'Specific "commercial" week. See https://www.epochconverter.com/weeks/',  argument: true, as: Integer
    slop.on :year,         '[optional] Specifiy year (for --week option), default current year',  argument: true, as: Integer
  end
end

#runObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/dovico/app.rb', line 55

def run
  settings = ConfigParser.new(config)
  start_date, end_date = settings.date_options

  if settings.needs_help?
    display_help
    exit 0
  end

  if config[:myself]
    display_myself
  end

  if config[:tasks]
    display_tasks
  end

  if config[:clear]
    clear_time_entries(start_date, end_date)
  end

  if config[:show]
    display_time_entries(start_date, end_date)
  end

  if config[:fill]
    time_entry_generator = TimeEntryGenerator.new(
      assignments: config["assignments"],
      employee_id: myself.id,
    )
    time_entries = time_entry_generator.generate(start_date, end_date)

    if time_entries.count > 0
      saved_time_entries = TimeEntry.batch_create!(time_entries)
      puts "#{saved_time_entries["TimeEntries"].count} Entries created between #{start_date} and #{end_date}"
    else
      puts "No entries to be created between #{start_date} and #{end_date}"
    end
  end

  if config[:submit]
     = TimeEntry.submit!(myself.id, start_date, end_date)
    puts "#{["TimeEntries"].count} Entries submitted between #{start_date} and #{end_date}"
  end
end