Class: TimeCamp::Timer

Inherits:
Resource show all
Defined in:
lib/ruby-timecamp/resources/timer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Resource

#attributes, #initialize

Constructor Details

This class inherits a constructor from TimeCamp::Resource

Instance Attribute Details

#elapsedObject (readonly)

Returns the value of attribute elapsed.



3
4
5
# File 'lib/ruby-timecamp/resources/timer.rb', line 3

def elapsed
  @elapsed
end

#entry_idObject (readonly)

Returns the value of attribute entry_id.



3
4
5
# File 'lib/ruby-timecamp/resources/timer.rb', line 3

def entry_id
  @entry_id
end

#entry_timeObject (readonly)

Returns the value of attribute entry_time.



3
4
5
# File 'lib/ruby-timecamp/resources/timer.rb', line 3

def entry_time
  @entry_time
end

#external_task_idObject (readonly)

Returns the value of attribute external_task_id.



3
4
5
# File 'lib/ruby-timecamp/resources/timer.rb', line 3

def external_task_id
  @external_task_id
end

#isTimerRunningObject (readonly)

Returns the value of attribute isTimerRunning.



3
4
5
# File 'lib/ruby-timecamp/resources/timer.rb', line 3

def isTimerRunning
  @isTimerRunning
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/ruby-timecamp/resources/timer.rb', line 3

def name
  @name
end

#new_timer_idObject (readonly)

Returns the value of attribute new_timer_id.



3
4
5
# File 'lib/ruby-timecamp/resources/timer.rb', line 3

def new_timer_id
  @new_timer_id
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



3
4
5
# File 'lib/ruby-timecamp/resources/timer.rb', line 3

def start_time
  @start_time
end

#task_idObject (readonly)

Returns the value of attribute task_id.



3
4
5
# File 'lib/ruby-timecamp/resources/timer.rb', line 3

def task_id
  @task_id
end

#timer_idObject (readonly)

Returns the value of attribute timer_id.



3
4
5
# File 'lib/ruby-timecamp/resources/timer.rb', line 3

def timer_id
  @timer_id
end

Class Method Details

.getObject



15
16
17
18
# File 'lib/ruby-timecamp/resources/timer.rb', line 15

def self.get
  response = TimeCamp::Request.post(resource_name, {}, { action: 'status' })
  return Timer.new(response)
end

.resource_nameObject

override because the path for this resource is not plural for some reason



11
12
13
# File 'lib/ruby-timecamp/resources/timer.rb', line 11

def self.resource_name
  return 'timer'
end

.start(opts = {}) ⇒ Object

optional :task_id, :entry_id, :started_at



21
22
23
24
25
26
27
# File 'lib/ruby-timecamp/resources/timer.rb', line 21

def self.start(opts={})
  data_keys = [:task_id, :entry_id, :started_at]
  data, opts = opts.partition{ |k, v| data_keys.include?(k) }.map(&:to_h)
  data.merge!(action: 'start')
  response = TimeCamp::Request.post(resource_name, opts, data)
  return Timer.new(response)
end

.stop(opts = {}) ⇒ Object

required :timer_id, :stopped_at



30
31
32
33
34
35
36
# File 'lib/ruby-timecamp/resources/timer.rb', line 30

def self.stop(opts={})
  data_keys = [:timer_id, :stopped_at]
  data, opts = opts.partition{ |k, v| data_keys.include?(k) }.map(&:to_h)
  data.merge!(action: 'stop')
  response = TimeCamp::Request.post(resource_name, opts, data)
  return Timer.new(response)
end