Class: TogglCmd::TogglTask

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/toggl_cmd/runner.rb

Class Method Summary collapse

Class Method Details

.load_tasks(user, toggl, since, through) ⇒ Object

attr_accessor :id, :start, :stop, :duration, :client, :project, :user, :billable, :description



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/toggl_cmd/runner.rb', line 85

def self.load_tasks(user, toggl, since, through)
  client_projects = map_projects_to_clients(toggl.projects)
  task_options = {:start_date => since || '1/1/2000', :end_date => through }

  tasks = []
  toggl.tasks(task_options)["data"].each do |t|
    next if t["duration"] < 0
    task = TogglTask.new(:start => t["start"],
                         :stop => t["stop"],
                         :duration => t["duration"],
                         :client => client_projects[t["project"]["id"]],
                         :project => t["project"]["name"],
                         :user => user,
                         :billable => t["billable"],
                         :description => t["description"])
    task.id = t["id"]
    tasks << task
  end
  
  tasks
end

.map_projects_to_clients(json_obj) ⇒ Object



107
108
109
110
111
112
113
114
115
# File 'lib/toggl_cmd/runner.rb', line 107

def self.map_projects_to_clients(json_obj)
  result = Hash.new

  json_obj["data"].each do |project|
    result[project["id"]] = project["client"] == nil ? '' : project["client"]["name"]
  end

  result
end