Class: FreshBooks::Project

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

Constant Summary collapse

TYPE_MAPPINGS =
{ 'project_id' => Fixnum, 'client_id' => Fixnum, 'rate' => Float }

Class Method Summary collapse

Instance Method Summary collapse

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(options = {})
  resp = FreshBooks.call_api('project.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

#clientObject



47
48
49
# File 'lib/freshbooks/extensions/project.rb', line 47

def client
  Client.get(client_id)
end

#createObject



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

#deleteObject



43
44
45
# File 'lib/freshbooks/extensions/project.rb', line 43

def delete
  self.class.delete(project_id)
end

#tasksObject



51
52
53
# File 'lib/freshbooks/extensions/project.rb', line 51

def tasks
  Task.list('project_id' => project_id)
end

#time_entriesObject



55
56
57
# File 'lib/freshbooks/extensions/project.rb', line 55

def time_entries
  TimeEntry.list('project_id' => project_id)
end

#updateObject



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