class Dude::Toggl::StartTimeEntry

Attributes

project[R]
task_title[R]

Public Instance Methods

call(task_title:, project:) click to toggle source
# File lib/dude/time_trackers/toggl/start_time_entry.rb, line 8
def call(task_title:, project:)
  @task_title = task_title
  @project = project

  start_time_entry
  print_message
end

Private Instance Methods

parsed_response() click to toggle source
# File lib/dude/time_trackers/toggl/start_time_entry.rb, line 45
def parsed_response
  JSON.parse(projects_response.body)
end
print_message() click to toggle source
project_id() click to toggle source
# File lib/dude/time_trackers/toggl/start_time_entry.rb, line 34
def project_id
  projects_array.each do |arr|
    return arr.last if arr.first.eql?(project.downcase)
  end
  nil
end
projects_array() click to toggle source
# File lib/dude/time_trackers/toggl/start_time_entry.rb, line 41
def projects_array
  parsed_response.map { |a| [a['name'].downcase.gsub(/\s/, '-'), a['id']] }
end
start_time_entry() click to toggle source
# File lib/dude/time_trackers/toggl/start_time_entry.rb, line 20
def start_time_entry
  toggl_api.post('/api/v8/time_entries/start', time_entry_params(task_title))
end
time_entry_params(title) click to toggle source
# File lib/dude/time_trackers/toggl/start_time_entry.rb, line 24
def time_entry_params(title)
  {
    time_entry: {
      description: title,
      pid: project_id,
      created_with: 'dude'
    }
  }.to_json
end