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_count ⇒ Object
Returns the value of attribute completed_count.
-
#completed_todos ⇒ Array<Logan::Todo>
returns the array of completed todos - potentially synchronously downloaded from API.
-
#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_count ⇒ Object
Returns the value of attribute remaining_count.
-
#remaining_todos ⇒ Array<Logan::Todo>
returns the array of remaining todos - potentially synchronously downloaded from API.
-
#url ⇒ Object
Returns the value of attribute url.
Attributes included from HashConstructed
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
-
#refresh ⇒ Object
refreshes the data for this todo list from the API.
-
#todo_with_substring(substring) ⇒ Logan::Todo
searches the remaining and completed todos for the first todo with the substring in its content.
-
#todos ⇒ Array<Logan::Todo>
returns an array of all todos, completed and remaining - potentially synchronously downloaded from API.
-
#todos=(todo_hash) ⇒ Array<Logan::Todo>
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
21 22 23 24 25 |
# File 'lib/logan/todolist.rb', line 21 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_count ⇒ Object
Returns the value of attribute completed_count.
14 15 16 |
# File 'lib/logan/todolist.rb', line 14 def completed_count @completed_count end |
#completed_todos ⇒ Array<Logan::Todo>
returns the array of completed todos - potentially synchronously downloaded from API
51 52 53 54 55 56 57 |
# File 'lib/logan/todolist.rb', line 51 def completed_todos if @completed_todos.empty? && @completed_count > 0 refresh end return @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_count ⇒ Object
Returns the value of attribute remaining_count.
13 14 15 |
# File 'lib/logan/todolist.rb', line 13 def remaining_count @remaining_count end |
#remaining_todos ⇒ Array<Logan::Todo>
returns the array of remaining todos - potentially synchronously downloaded from API
40 41 42 43 44 45 46 |
# File 'lib/logan/todolist.rb', line 40 def remaining_todos if @remaining_todos.empty? && @remaining_count > 0 refresh end return @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
90 91 92 93 94 95 96 97 98 |
# File 'lib/logan/todolist.rb', line 90 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
118 119 120 |
# File 'lib/logan/todolist.rb', line 118 def delete_todo(todo) response = Logan::Client.delete "/projects/#{@project_id}/todos/#{todo.id}.json" end |
#post_json ⇒ Object
27 28 29 |
# File 'lib/logan/todolist.rb', line 27 def post_json { :name => @name, :description => @description }.to_json end |
#refresh ⇒ Object
refreshes the data for this todo list from the API
32 33 34 35 |
# File 'lib/logan/todolist.rb', line 32 def refresh response = Logan::Client.get "/projects/#{@project_id}/todolists/#{@id}.json" initialize(response.parsed_response) end |
#todo_with_substring(substring) ⇒ Logan::Todo
searches the remaining and completed todos for the first todo with the substring in its content
81 82 83 84 |
# File 'lib/logan/todolist.rb', line 81 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 ⇒ Array<Logan::Todo>
returns an array of all todos, completed and remaining - potentially synchronously downloaded from API
62 63 64 |
# File 'lib/logan/todolist.rb', line 62 def todos remaining_todos + completed_todos end |
#todos=(todo_hash) ⇒ Array<Logan::Todo>
assigns the #remaining_todos and #completed_todos from the associated keys in the passed hash
71 72 73 74 75 |
# File 'lib/logan/todolist.rb', line 71 def todos=(todo_hash) @remaining_todos = todo_hash['remaining'].map { |h| Logan::Todo.new h.merge({ :project_id => @project_id }) } @completed_todos = todo_hash['completed'].map { |h| Logan::Todo.new h.merge({ :project_id => @project_id }) } return @remaining_todos + @completed_todos end |
#update_todo(todo) ⇒ Logan::Todo
update a todo in this todo list via the Basecamp API
104 105 106 107 108 109 110 111 112 |
# File 'lib/logan/todolist.rb', line 104 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 |