Class: FreshBooks::Project
- Inherits:
-
Object
- Object
- FreshBooks::Project
- Defined in:
- lib/freshbooks/extensions/project.rb
Constant Summary collapse
- TYPE_MAPPINGS =
{ 'project_id' => Fixnum, 'client_id' => Fixnum, 'rate' => Float }
Class Method Summary collapse
- .delete(project_id) ⇒ Object
- .find_by_name(name) ⇒ Object
- .get(project_id) ⇒ Object
- .list(options = {}) ⇒ Object
Instance Method Summary collapse
- #client ⇒ Object
- #create ⇒ Object
- #delete ⇒ Object
- #tasks ⇒ Object
- #time_entries ⇒ Object
- #update ⇒ Object
Class Method Details
.delete(project_id) ⇒ Object
25 26 27 28 |
# File 'lib/freshbooks/extensions/project.rb', line 25 def delete(project_id) resp = FreshBooks.call_api('project.delete', 'project_id' => project_id) resp.success? end |
.find_by_name(name) ⇒ Object
21 22 23 |
# File 'lib/freshbooks/extensions/project.rb', line 21 def find_by_name(name) list.detect { |p| p.name == name } end |
.get(project_id) ⇒ Object
8 9 10 11 12 |
# File 'lib/freshbooks/extensions/project.rb', line 8 def get(project_id) resp = FreshBooks.call_api('project.get', 'project_id' => project_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/project.rb', line 14 def list( = {}) resp = FreshBooks.call_api('project.list', ) return nil unless resp.success? list_elements = resp.elements[1].elements list_elements.collect { |elem| new_from_xml(elem) } end |
Instance Method Details
#client ⇒ Object
47 48 49 |
# File 'lib/freshbooks/extensions/project.rb', line 47 def client Client.get(client_id) end |
#create ⇒ Object
31 32 33 34 35 36 |
# File 'lib/freshbooks/extensions/project.rb', line 31 def create resp = FreshBooks.call_api('project.create', 'project' => self) if resp.success? self.project_id = resp.elements[1].text.to_i end end |
#delete ⇒ Object
43 44 45 |
# File 'lib/freshbooks/extensions/project.rb', line 43 def delete self.class.delete(project_id) end |
#tasks ⇒ Object
51 52 53 |
# File 'lib/freshbooks/extensions/project.rb', line 51 def tasks Task.list('project_id' => project_id) end |
#time_entries ⇒ Object
55 56 57 |
# File 'lib/freshbooks/extensions/project.rb', line 55 def time_entries TimeEntry.list('project_id' => project_id) end |
#update ⇒ Object
38 39 40 41 |
# File 'lib/freshbooks/extensions/project.rb', line 38 def update resp = FreshBooks.call_api('project.update', 'project' => self) resp.success? end |