Class: Logan::TodoList
- Inherits:
-
Object
- Object
- Logan::TodoList
- Includes:
- HashConstructed
- Defined in:
- lib/logan/todolist.rb
Instance Attribute Summary collapse
-
#completed ⇒ Object
Returns the value of attribute completed.
-
#completed_todos ⇒ Object
Returns the value of attribute completed_todos.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
-
#remaining_todos ⇒ Object
Returns the value of attribute remaining_todos.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#create_todo(todo) ⇒ Logan::Todo
create a todo in this todo list via the Basecamp API.
-
#delete_todo(todo) ⇒ HTTParty::response
delete a todo in this todo list via delete call to Basecamp API.
-
#initialize(h) ⇒ TodoList
constructor
intializes a todo list by calling the HashConstructed initialize method and setting both @remaining_todos and @completed_todos to empty arrays.
- #post_json ⇒ Object
-
#todo_with_substring(substring) ⇒ Logan::Todo
searches the remaining and completed todos for the first todo with the substring in its content.
-
#todos=(todo_hash) ⇒ Object
assigns the #remaining_todos and #completed_todos from the associated keys in the passed hash.
-
#update_todo(todo) ⇒ Logan::Todo
update a todo in this todo list via the Basecamp API.
Constructor Details
#initialize(h) ⇒ TodoList
intializes a todo list by calling the HashConstructed initialize method and setting both @remaining_todos and @completed_todos to empty arrays
19 20 21 22 23 |
# File 'lib/logan/todolist.rb', line 19 def initialize(h) @remaining_todos = [] @completed_todos = [] super end |
Instance Attribute Details
#completed ⇒ Object
Returns the value of attribute completed.
12 13 14 |
# File 'lib/logan/todolist.rb', line 12 def completed @completed end |
#completed_todos ⇒ Object
Returns the value of attribute completed_todos.
14 15 16 |
# File 'lib/logan/todolist.rb', line 14 def completed_todos @completed_todos end |
#description ⇒ Object
Returns the value of attribute description.
11 12 13 |
# File 'lib/logan/todolist.rb', line 11 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/logan/todolist.rb', line 8 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/logan/todolist.rb', line 10 def name @name end |
#project_id ⇒ Object
Returns the value of attribute project_id.
9 10 11 |
# File 'lib/logan/todolist.rb', line 9 def project_id @project_id end |
#remaining_todos ⇒ Object
Returns the value of attribute remaining_todos.
13 14 15 |
# File 'lib/logan/todolist.rb', line 13 def remaining_todos @remaining_todos end |
#url ⇒ Object
Returns the value of attribute url.
15 16 17 |
# File 'lib/logan/todolist.rb', line 15 def url @url end |
Instance Method Details
#create_todo(todo) ⇒ Logan::Todo
create a todo in this todo list via the Basecamp API
52 53 54 55 56 57 58 59 60 |
# File 'lib/logan/todolist.rb', line 52 def create_todo(todo) post_params = { :body => todo.post_json, :headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'}) } response = Logan::Client.post "/projects/#{@project_id}/todolists/#{@id}/todos.json", post_params Logan::Todo.new response end |
#delete_todo(todo) ⇒ HTTParty::response
delete a todo in this todo list via delete call to Basecamp API
80 81 82 |
# File 'lib/logan/todolist.rb', line 80 def delete_todo(todo) response = Logan::Client.delete "/projects/#{@project_id}/todos/#{todo.id}.json" end |
#post_json ⇒ Object
25 26 27 |
# File 'lib/logan/todolist.rb', line 25 def post_json { :name => @name, :description => @description }.to_json end |
#todo_with_substring(substring) ⇒ Logan::Todo
searches the remaining and completed todos for the first todo with the substring in its content
43 44 45 46 |
# File 'lib/logan/todolist.rb', line 43 def todo_with_substring(substring) issue_todo = @remaining_todos.detect{ |t| !t.content.index(substring).nil? } issue_todo ||= @completed_todos.detect { |t| !t.content.index(substring).nil? } end |
#todos=(todo_hash) ⇒ Object
assigns the #remaining_todos and #completed_todos from the associated keys in the passed hash
33 34 35 36 37 |
# File 'lib/logan/todolist.rb', line 33 def todos=(todo_hash) @remaining_todos = todo_hash['remaining'].map { |h| Logan::Todo.new h } @completed_todos = todo_hash['completed'].map { |h| Logan::Todo.new h } return nil end |
#update_todo(todo) ⇒ Logan::Todo
update a todo in this todo list via the Basecamp API
66 67 68 69 70 71 72 73 74 |
# File 'lib/logan/todolist.rb', line 66 def update_todo(todo) put_params = { :body => todo.put_json, :headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'}) } response = Logan::Client.put "/projects/#{@project_id}/todos/#{todo.id}.json", put_params Logan::Todo.new response end |