-
Notifications
You must be signed in to change notification settings - Fork 2
Things::Project
Projects are accessed via the Things::Project class.
Currently there are no options for fetching a collection of Projects
You can, however, fetch a collection of Todos assigned to that particular project by calling:
Project.find('Top Secret Project').todos
If you want to create a new Project, you simple create a new instance of the Things::Project class, supplying the parameters:
Things::Project.new(:name => 'Top Secret Project')
When you’re ready to send it to Things, simply call the save method on the instance:
project = Things::Project.new(:name => 'Top Secret Project')
project.save # the Project will appear in Project area
If you want to send the Project to Things during the instantiation process, simply call create:
Things::Project.create(:name => 'Top Secret Project') # the Project will appear in the project list
Things::Project has a few useful methods if you want to fetch a single Project.
The smartest is the Things::Project.find method, which will accept either a name or an id.
Things::Project.find('Top Secret Project') # => #<Things::Project:0x115dd84>
Things::Project.find('11111111-1111-1111-1111-111111111111') # => #<Things::Project:0x115dd84>
If you want a more targeted approach, you can use Things::Project.find_by_name or Things::Project.find_by_id
To update a Project, you need to fetch it, change the desired properties and save it. The following example illustrates this:
project = Things::Project.find('Top Secret Project') # => #<Things::Project:0x115dd84>
project.name = 'Not so Secret Project'
project.save
When you open up a Things window, you’ll notice that the name has changed.
To delete a Project, simply call the delete method. The Project will be moved to Trash.
project = Things::Project.find('Top Secret Project') # => #<Things::Project:0x115dd84>
project.delete
To assign a Todo to a Project, you have to assign the chosen Project as an attribute of that todo by calling #project= on that Todo:
todo = Things::Todo.create(:name => 'Call Mark')
project = Things::Project.find('Secret Project')
todo.project = project
todo.save