Class: StarTrack::TimeTracker::Freckle

Inherits:
Object
  • Object
show all
Defined in:
lib/star_track/time_tracker/freckle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFreckle

Returns a new instance of Freckle.



8
9
10
11
12
13
14
15
# File 'lib/star_track/time_tracker/freckle.rb', line 8

def initialize
  config = YAML.load_file("#{ENV['HOME']}/.star_track.yaml")["freckle"]

  @token      = config["token"]
  @project_id = config["project_id"].to_i

  @client = ::Freckle::Client.new(token: @token)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/star_track/time_tracker/freckle.rb', line 6

def client
  @client
end

Instance Method Details

#track(tasks) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/star_track/time_tracker/freckle.rb', line 17

def track(tasks)
  params = {
    description: tasks.join(" - ").gsub("#", " "),
    project_id:  @project_id,
    minutes:     billable_time,
    date:        Date.today.to_s,
  }

  begin
    client.create_entry(params)
  rescue => error
    ErrorHandler.raise(error.message)
  end
end