views:

833

answers:

1

I've set up a new Rails 2.3.2 app and added the Basecamp API ruby wrapper to my /lib directory from here:

http://developer.37signals.com/basecamp/basecamp.rb

In my application_controller.rb I have created the following method to enable calls to Basecamp:

def basecamp_connect
  Basecamp.establish_connection!('xxxxxx', 'xxxxxx', 'xxxxxx', false)
  @basecamp = Basecamp.new
end

Can somebody provide an example of how I access the API from a controller to retrieve a list of To Do lists across all active Basecamp projects?

+1  A: 

It's based on ActiveResource, so luckily your code will look a lot like AR model code.

This should find all todo items for your basecamp:

Basecamp::TodoList.find(:all)

You can also get all TodoLists from a given project, and specify if they're completed or not, using a method they've added to the TodoList class. To find all lists for a given project, for example, just use:

Basecamp::Todolist.all(project_id)
Terry
Thanks - this helps a lot. Is there a way using the API to retrieve a list of all To Dos open across all projects? Looking at the documentation it doesn't seem like that is possible?
I think you can just do TodoItem.find(:all). I think there's a :complete flag that you could pass into the params, but if that doesn't work, you might be able to do BaseCamp::TodoList.find(:all).map{|tl| tl.todo_items} ?
Terry
The second option BaseCamp::TodoList.find(:all).map{|tl| tl.todo_items} returns all ToDo items inside todo-lists > todo-list > todo-itemHow do I loop through the todo-items from the returned XML?