Class: FreshBooks::Task
- Inherits:
-
Object
- Object
- FreshBooks::Task
- Defined in:
- lib/freshbooks/extensions/task.rb
Constant Summary collapse
- TYPE_MAPPINGS =
{ 'task_id' => Fixnum, 'rate' => Float }
Class Method Summary collapse
- .delete(task_id) ⇒ Object
- .find_by_name(name) ⇒ Object
- .get(task_id) ⇒ Object
- .list(options = {}) ⇒ Object
Instance Method Summary collapse
Class Method Details
.delete(task_id) ⇒ Object
25 26 27 28 |
# File 'lib/freshbooks/extensions/task.rb', line 25 def delete(task_id) resp = FreshBooks.call_api('task.delete', 'task_id' => task_id) resp.success? end |
.find_by_name(name) ⇒ Object
21 22 23 |
# File 'lib/freshbooks/extensions/task.rb', line 21 def find_by_name(name) list.detect { |p| p.name == name } end |
.get(task_id) ⇒ Object
8 9 10 11 12 |
# File 'lib/freshbooks/extensions/task.rb', line 8 def get(task_id) resp = FreshBooks.call_api('task.get', 'task_id' => task_id) return nil unless resp.success? new_from_xml(resp.elements[1]) end |
.list(options = {}) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/freshbooks/extensions/task.rb', line 14 def list( = {}) resp = FreshBooks.call_api('task.list', ) return nil unless resp.success? list_elements = resp.elements[1].elements list_elements.collect { |elem| new_from_xml(elem) } end |
Instance Method Details
#create ⇒ Object
31 32 33 34 35 36 |
# File 'lib/freshbooks/extensions/task.rb', line 31 def create resp = FreshBooks.call_api('task.create', 'task' => self) if resp.success? self.task_id = resp.elements[1].text.to_i end end |
#delete ⇒ Object
43 44 45 |
# File 'lib/freshbooks/extensions/task.rb', line 43 def delete self.class.delete(task_id) end |
#time_entries ⇒ Object
47 48 49 |
# File 'lib/freshbooks/extensions/task.rb', line 47 def time_entries TimeEntry.list('task_id' => task_id) end |
#update ⇒ Object
38 39 40 41 |
# File 'lib/freshbooks/extensions/task.rb', line 38 def update resp = FreshBooks.call_api('task.update', 'task' => self) resp.success? end |