Class: Nozbe::Project

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

Overview

Project class

  • In Nozbe, a project is used to group Action (or Note) together

  • The number of projects is limited by the Nozbe-account (for a free account : 5)

Constant Summary collapse

DEFAULT_PROJECT_NAME =
"Inbox"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



8
9
10
# File 'lib/nozbe/project.rb', line 8

def body
  @body
end

#body_showObject

Returns the value of attribute body_show.



8
9
10
# File 'lib/nozbe/project.rb', line 8

def body_show
  @body_show
end

#countObject

Returns the value of attribute count.



8
9
10
# File 'lib/nozbe/project.rb', line 8

def count
  @count
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/nozbe/project.rb', line 8

def id
  @id
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/nozbe/project.rb', line 8

def name
  @name
end

Class Method Details

.get_default_project(user_key) ⇒ Object

return the default Project instance : the project with its name set to DEFAULT_PROJECT_NAME



12
13
14
# File 'lib/nozbe/project.rb', line 12

def self.get_default_project(user_key)
  get_from_name(user_key, DEFAULT_PROJECT_NAME)
end

.get_from_name(user_key, project_name) ⇒ Object

return a Project instance from the given project_name

  • it may return nil if there is no matches

WARNING : the Nozbe-API doesn’t provide such a method, so we load all projects and compare the names with the given name

  • the comparison is case-insensitive (use ‘downcase’ on all names)



22
23
24
25
26
27
# File 'lib/nozbe/project.rb', line 22

def self.get_from_name(user_key, project_name)
  return nil if project_name.nil?
  projects = list(user_key)
  selected_projects = projects.select { |p| p.name.downcase == project_name.downcase }
  selected_projects.first rescue nil
end

.list(user_key) ⇒ Object

List all projects



30
31
32
# File 'lib/nozbe/project.rb', line 30

def self.list(user_key)
  ProjectsListApiCall.new(user_key).call
end

Instance Method Details

#get_actions(user_key, showdone = false) ⇒ Object

List all actions associated with the current project

  • you can specify if you want to retrieve the already-done actions



41
42
43
44
45
46
# File 'lib/nozbe/project.rb', line 41

def get_actions(user_key, showdone = false)
  Nozbe::Action.list_for_project(user_key, id, showdone).collect { |action|
    action.project = self
    action
  }
end

#get_notes(user_key) ⇒ Object

List all notes associated with the current project



49
50
51
52
53
54
# File 'lib/nozbe/project.rb', line 49

def get_notes(user_key)
  Nozbe::Note.list_for_project(user_key, id).collect { |note|
    note.project = self
    note
  }
end

#load_info(user_key) ⇒ Object

load more infos (body) for the current project



35
36
37
# File 'lib/nozbe/project.rb', line 35

def load_info(user_key)
  ProjectInfoApiCall.new(user_key, self).call
end

#save!(user_key) ⇒ Object

Save the current Project instance

  • used to create a new project, not to save an already existing but modified project.

  • return the instance, with its new ID set



59
60
61
# File 'lib/nozbe/project.rb', line 59

def save!(user_key)
  ProjectNewApiCall.new(user_key, self).call
end