Sha256: 2462a40ff9e53684505fdbacea9ede37c78e12180867666ed214ecd0326d95f8

Contents?: true

Size: 918 Bytes

Versions: 24

Compression:

Stored size: 918 Bytes

Contents

class Mite::Tracker < Mite::Base
  
  self.collection_name = "tracker"
  
  def self.current
    tracking_time_entry = connection.get(collection_path, headers)["tracking_time_entry"]
    tracking_time_entry ? instantiate_record(tracking_time_entry) : nil
  end
  
  def self.start(time_entry_or_id)
    id = time_entry_or_id.is_a?(Mite::TimeEntry) ? time_entry_or_id.id : time_entry_or_id
    self.new(:id => id).start
  end
  
  def self.stop
    tracker = current 
    tracker ? tracker.stop : false
  end
  
  def start
    response = connection.put(element_path(prefix_options), encode, self.class.headers)
    load(self.class.format.decode(response.body)["tracking_time_entry"])
    response.is_a?(Net::HTTPSuccess) ? self : false
  end
  
  def stop
    connection.delete(element_path, self.class.headers).is_a?(Net::HTTPSuccess) ? self : false
  end
  
  def time_entry
    Mite::TimeEntry.find(id)
  end
  
end

Version data entries

24 entries across 24 versions & 5 rubygems

Version Path
mite-rb-0.2.2 lib/mite/tracker.rb
mite-rb-0.2.1 lib/mite/tracker.rb
mite-rb-0.2.0 lib/mite/tracker.rb
mite-rb-0.1.0 lib/mite/tracker.rb