Class: Todoable::List

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

Overview

Class that represents TODO Lists

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(todoable, params) ⇒ List

Create new instances of TODO Lists.

Parameters:

  • todoable (Todoable::Todoable)

    Instance of the `Todoable` class that knows how to perform authenticated requests.

  • params (Hash)

    The parameters of the list. The hash must contain the fields `name` and `id`.



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

#idObject

Returns the value of attribute id



31
32
33
# File 'lib/todoable.rb', line 31

def id
  @id
end

#nameObject

Returns the value of attribute name



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

def name
  @name
end

Instance Method Details

#deleteObject

Deletes the list



56
57
58
# File 'lib/todoable.rb', line 56

def delete
  @todoable.request!("delete", LIST_PATH, { :list_id => @id })
end

#itemsArray<Todoable::Item>

Lists the all TODO items related to the list

Returns:



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

Parameters:

  • name (String)

    The name of 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

Parameters:

  • name (String)

    The new name for the 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