Class: Todoable::List
- Inherits:
-
Object
- Object
- Todoable::List
- Defined in:
- lib/todoable.rb
Overview
Class that represents TODO Lists
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#delete ⇒ Object
Deletes the list.
-
#initialize(todoable, params) ⇒ List
constructor
Create new instances of TODO Lists.
-
#items ⇒ Array<Todoable::Item>
Lists the all TODO items related to the list.
-
#new_item(name) ⇒ Object
Creates a new TODO item within the list.
-
#update(name) ⇒ Object
Updates the name of a list.
Constructor Details
#initialize(todoable, params) ⇒ List
Create new instances of TODO Lists.
40 41 42 43 44 |
# File 'lib/todoable.rb', line 40 def initialize todoable, params @todoable = todoable @name = params['name'] @id = params['id'] end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id
31 32 33 |
# File 'lib/todoable.rb', line 31 def id @id end |
#name ⇒ Object
Returns the value of attribute name
30 31 32 |
# File 'lib/todoable.rb', line 30 def name @name end |
Instance Method Details
#delete ⇒ Object
Deletes the list
56 57 58 |
# File 'lib/todoable.rb', line 56 def delete @todoable.request!("delete", LIST_PATH, { :list_id => @id }) end |
#items ⇒ Array<Todoable::Item>
Lists the all TODO items related to the list
64 65 66 67 68 69 |
# File 'lib/todoable.rb', line 64 def items output = @todoable.request!("get", LIST_PATH, { :list_id => @id }) output['items'].collect { |json_item| Item.new(@todoable, self, json_item) } end |
#new_item(name) ⇒ Object
Creates a new TODO item within the list
74 75 76 77 |
# File 'lib/todoable.rb', line 74 def new_item name body = {"item": {"name": name}}.to_json @todoable.request!("post", ITEMS_PATH, {:list_id => @id}, body) end |
#update(name) ⇒ Object
Updates the name of a list
49 50 51 52 53 |
# File 'lib/todoable.rb', line 49 def update name body = {"list": {"name": name}}.to_json @todoable.request!("patch", LIST_PATH, { :list_id => @id }, body) @name = name end |