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, 'billed' => :boolean
}
EXCLUDE_XML_ATTRIBUTES =
%w[billed]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.delete(time_entry_id) ⇒ Object



26
27
28
29
# File 'lib/freshbooks/extensions/time_entry.rb', line 26

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



13
14
15
16
17
# File 'lib/freshbooks/extensions/time_entry.rb', line 13

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



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

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



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

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



44
45
46
# File 'lib/freshbooks/extensions/time_entry.rb', line 44

def delete
  self.class.delete(time_entry_id)
end

#projectObject



52
53
54
# File 'lib/freshbooks/extensions/time_entry.rb', line 52

def project
  Project.get(project_id)
end

#taskObject



48
49
50
# File 'lib/freshbooks/extensions/time_entry.rb', line 48

def task
  Task.get(task_id)
end

#updateObject



39
40
41
42
# File 'lib/freshbooks/extensions/time_entry.rb', line 39

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