Class: Dude::Toggl::StopTimeEntry

Inherits:
Base
  • Object
show all
Defined in:
lib/dude/time_trackers/toggl/stop_time_entry.rb

Instance Method Summary collapse

Methods inherited from Base

#projects_response, #toggl_api

Instance Method Details

#callObject



8
9
10
11
12
13
# File 'lib/dude/time_trackers/toggl/stop_time_entry.rb', line 8

def call
  stop_current_time_entry
  print_success_message
rescue NoMethodError
  print_error_message
end

#current_time_entryObject



19
20
21
# File 'lib/dude/time_trackers/toggl/stop_time_entry.rb', line 19

def current_time_entry
  JSON.parse(toggl_api.get('api/v8/time_entries/current').body)['data']
end


27
28
29
# File 'lib/dude/time_trackers/toggl/stop_time_entry.rb', line 27

def print_error_message
  puts 'No runned time entries in Toggl'.colorize(:yellow)
end


23
24
25
# File 'lib/dude/time_trackers/toggl/stop_time_entry.rb', line 23

def print_success_message
  puts 'Suspended current time entry in Toggl'.colorize(:green)
end

#stop_current_time_entryObject



15
16
17
# File 'lib/dude/time_trackers/toggl/stop_time_entry.rb', line 15

def stop_current_time_entry
  toggl_api.put("api/v8/time_entries/#{current_time_entry['id']}/stop", '')
end