Class: FreshBooks::TimeEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/freshbooks/extensions/time_entry.rb

Constant Summary collapse

TYPE_MAPPINGS =
{
  'time_entry_id' => Fixnum, 'project_id' => Fixnum, 'task_id' => Fixnum,
  'hours' => Float, 'date' => Date
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.delete(time_entry_id) ⇒ Object



24
25
26
27
# File 'lib/freshbooks/extensions/time_entry.rb', line 24

def delete(time_entry_id)
  resp = FreshBooks.call_api('time_entry.delete', 'time_entry_id' => time_entry_id)
  resp.success?
end

.get(time_entry_id) ⇒ Object



11
12
13
14
15
# File 'lib/freshbooks/extensions/time_entry.rb', line 11

def get(time_entry_id)
  resp = FreshBooks.call_api('time_entry.get', 'time_entry_id' => time_entry_id)
  return nil unless resp.success?
  new_from_xml(resp.elements[1])
end

.list(options = {}) ⇒ Object



17
18
19
20
21
22
# File 'lib/freshbooks/extensions/time_entry.rb', line 17

def list(options = {})
  resp = FreshBooks.call_api('time_entry.list', options)
  return nil unless resp.success?
  list_elements = resp.elements[1].elements
  list_elements.collect { |elem|  new_from_xml(elem) }
end

Instance Method Details

#createObject



30
31
32
33
34
35
# File 'lib/freshbooks/extensions/time_entry.rb', line 30

def create
  resp = FreshBooks.call_api('time_entry.create', 'time_entry' => self)
  if resp.success?
    self.time_entry_id = resp.elements[1].text.to_i
  end
end

#deleteObject



42
43
44
# File 'lib/freshbooks/extensions/time_entry.rb', line 42

def delete
  self.class.delete(time_entry_id)
end

#projectObject



50
51
52
# File 'lib/freshbooks/extensions/time_entry.rb', line 50

def project
  Project.get(project_id)
end

#taskObject



46
47
48
# File 'lib/freshbooks/extensions/time_entry.rb', line 46

def task
  Task.get(task_id)
end

#updateObject



37
38
39
40
# File 'lib/freshbooks/extensions/time_entry.rb', line 37

def update
  resp = FreshBooks.call_api('time_entry.update', 'time_entry' => self)
  resp.success?
end