-
Notifications
You must be signed in to change notification settings - Fork 2
Things::Todo
Todos are accessed via the Things::Todo class.
If you want to fetch a list of todos, there is a set of collections you can use.
The largest one is the collection of all Todos. You fetch it by calling:
Things::Todo.all
It will return an array of Things::Todo instances.
If you only want the active (so non-finished) Todos, you can fetch a collection by calling:
Things::App.active
It will return an array of Things::Todo instances that are not finished.
As the gem will grow, more methods will follow.
If you want to create a new Todo, you simple create a new instance of the Things::Todo class, supplying the parameters:
Things::Todo.new(:name => 'Take out the garbage')
When you’re ready to send it to Things, simply call the save method on the instance:
todo = Things::Todo.new(:name => 'Take out the garbage')
todo.save # the Todo will appear in the Inbox
If you want to send the Todo to Things during the instantiation process, simply call create:
Things::Todo.create(:name => 'Take out the garbage') # the Todo will appear in the Inbox
Things::Todo has a few useful methods if you want to fetch a single Todo.
The smartest is the Things::Todo.find method, which will accept either a name or an id.
Things::Todo.find('Take out the garbage') # => #<Things::Todo:0x115dd84>
Things::Todo.find('11111111-1111-1111-1111-111111111111') # => #<Things::Todo:0x115dd84>
If you want a more targeted approach, you can use Things::Todo.find_by_name or Things::Todo.find_by_id
To update a Todo, you need to fetch it, change the desired properties and save it. The following example illustrates this:
todo = Things::Todo.find('Take out the garbage') # => #<Things::Todo:0x115dd84>
todo.name = 'Take out the garbage and old boxes'
todo.save
When you open up a Things window, you’ll notice that the name has changed.
To delete a todo, simply call the delete method. The Todo will be moved to Trash.
todo = Things::Todo.find('Take out the garbage') # => #<Things::Todo:0x115dd84>
todo.delete
To mark the Todo as completed, call the #complete method (you need to save it to see the effect in Things)
todo = Things::Todo.find('Take out the garbage') # => #<Things::Todo:0x115dd84>
todo.complete
todo.status # => :completed
todo.save
If you want to complete the Todo and save it at the same time, you can call the #complete! method
todo = Things::Todo.find('Take out the garbage') # => #<Things::Todo:0x115dd84>
todo.complete!