Class: Logan::Todo
- Inherits:
-
Object
- Object
- Logan::Todo
- Includes:
- HashConstructed
- Defined in:
- lib/logan/todo.rb
Instance Attribute Summary collapse
-
#app_url ⇒ Object
Returns the value of attribute app_url.
-
#assignee ⇒ Object
Returns the value of attribute assignee.
-
#comments_count ⇒ Object
Returns the value of attribute comments_count.
-
#completed ⇒ Object
Returns the value of attribute completed.
-
#content ⇒ Object
Returns the value of attribute content.
-
#due_at ⇒ Object
Returns the value of attribute due_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#position ⇒ Object
Returns the value of attribute position.
-
#private ⇒ Object
Returns the value of attribute private.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
-
#trashed ⇒ Object
Returns the value of attribute trashed.
-
#url ⇒ Object
Returns the value of attribute url.
Attributes included from HashConstructed
Instance Method Summary collapse
-
#comments ⇒ Array<Logan::Comment] Array of comments on this todo
returns the array of comments - potentially synchronously downloaded from API.
-
#comments=(comment_array) ⇒ Array<Logan::Comment>
assigns the #comments from the passed array.
-
#create_comment(comment) ⇒ Logan::Comment
create a create in this todo list via the Basecamp API.
-
#initialize(h) ⇒ Todo
constructor
A new instance of Todo.
- #post_json ⇒ Object
- #put_json ⇒ Object
-
#refresh ⇒ Object
refreshes the data for this todo from the API.
- #save ⇒ Object
Constructor Details
#initialize(h) ⇒ Todo
Returns a new instance of Todo.
22 23 24 25 26 27 28 29 30 |
# File 'lib/logan/todo.rb', line 22 def initialize h super unless app_url.nil? || app_url.blank? @project_id ||= app_url[/projects\/(\d*)\//, 1].to_i end self end |
Instance Attribute Details
#app_url ⇒ Object
Returns the value of attribute app_url.
17 18 19 |
# File 'lib/logan/todo.rb', line 17 def app_url @app_url end |
#assignee ⇒ Object
Returns the value of attribute assignee.
14 15 16 |
# File 'lib/logan/todo.rb', line 14 def assignee @assignee end |
#comments_count ⇒ Object
Returns the value of attribute comments_count.
13 14 15 |
# File 'lib/logan/todo.rb', line 13 def comments_count @comments_count end |
#completed ⇒ Object
Returns the value of attribute completed.
12 13 14 |
# File 'lib/logan/todo.rb', line 12 def completed @completed end |
#content ⇒ Object
Returns the value of attribute content.
11 12 13 |
# File 'lib/logan/todo.rb', line 11 def content @content end |
#due_at ⇒ Object
Returns the value of attribute due_at.
15 16 17 |
# File 'lib/logan/todo.rb', line 15 def due_at @due_at end |
#id ⇒ Object
Returns the value of attribute id.
9 10 11 |
# File 'lib/logan/todo.rb', line 9 def id @id end |
#position ⇒ Object
Returns the value of attribute position.
16 17 18 |
# File 'lib/logan/todo.rb', line 16 def position @position end |
#private ⇒ Object
Returns the value of attribute private.
20 21 22 |
# File 'lib/logan/todo.rb', line 20 def private @private end |
#project_id ⇒ Object
Returns the value of attribute project_id.
10 11 12 |
# File 'lib/logan/todo.rb', line 10 def project_id @project_id end |
#trashed ⇒ Object
Returns the value of attribute trashed.
19 20 21 |
# File 'lib/logan/todo.rb', line 19 def trashed @trashed end |
#url ⇒ Object
Returns the value of attribute url.
18 19 20 |
# File 'lib/logan/todo.rb', line 18 def url @url end |
Instance Method Details
#comments ⇒ Array<Logan::Comment] Array of comments on this todo
returns the array of comments - potentially synchronously downloaded from API
69 70 71 72 |
# File 'lib/logan/todo.rb', line 69 def comments refresh if (@comments.nil? || @comments.empty?) && @comments_count > 0 @comments ||= Array.new end |
#comments=(comment_array) ⇒ Array<Logan::Comment>
assigns the #comments from the passed array
78 79 80 |
# File 'lib/logan/todo.rb', line 78 def comments=(comment_array) @comments = comment_array.map { |obj| obj = Logan::Comment.new obj if obj.is_a?(Hash) } end |
#create_comment(comment) ⇒ Logan::Comment
create a create in this todo list via the Basecamp API
94 95 96 97 98 99 100 101 102 |
# File 'lib/logan/todo.rb', line 94 def create_comment(comment) post_params = { :body => comment.post_json, :headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'}) } response = Logan::Client.post "/projects/#{@project_id}/todos/#{@id}/comments.json", post_params Logan::Comment.new response end |
#post_json ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/logan/todo.rb', line 32 def post_json { :content => @content, :due_at => @due_at, :assignee => @assignee.nil? ? nil : @assignee.to_hash }.to_json end |
#put_json ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/logan/todo.rb', line 40 def put_json { :content => @content, :due_at => @due_at, :assignee => @assignee.nil? ? nil : @assignee.to_hash, :position => (@position.nil? || @position.to_s.empty?) ? 99 : @position, :completed => @completed }.to_json end |