diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 5c8d1be3..01f27140 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -47,7 +47,10 @@ class TodosController < ApplicationController headers['Content-Type']=Mime::TEXT.to_s render :content_type => Mime::TEXT end - format.xml { render :xml => @todos.to_xml( *todo_xml_params ) } + format.xml do + @xml_todos = params[:limit_to_active_todos] ? @not_done_todos : @todos + render :xml => @xml_todos.to_xml( *todo_xml_params ) + end format.any(:rss, :atom) { @feed_title, @feed_description = 'Tracks Actions', "Actions for #{current_user.display_name}" } format.ics end diff --git a/app/views/integrations/rest_api.html.erb b/app/views/integrations/rest_api.html.erb index f52eb413..277d0eaf 100644 --- a/app/views/integrations/rest_api.html.erb +++ b/app/views/integrations/rest_api.html.erb @@ -79,6 +79,15 @@ field to ID, created_at, modified_at, completed_at by adding the pa +If you only want to get the active todos, you add the parameter limit_to_active_todos and set it to some value like this: + +
+
+  $ curl -u username:p4ssw0rd -H "Content-Type: text/xml" \
+  <%= root_url %>todos.xml?limit_to_active_todos=1
+
+
+

Writing to the API

The API provides mechanisms for adding, updating and deleting resources using the HTTP methods PUT, POST and DELETE in combination with the content.

diff --git a/test/integration/todo_xml_api_test.rb b/test/integration/todo_xml_api_test.rb index 8234c056..ed2458ee 100644 --- a/test/integration/todo_xml_api_test.rb +++ b/test/integration/todo_xml_api_test.rb @@ -17,7 +17,7 @@ class TodoXmlApiTest < ActionDispatch::IntegrationTest get '/tickler.xml', {}, {} assert_response 401 - get "/tickler.xml", {}, {'HTT_AUTHORIZATION' => "Basic " + Base64.encode64("wrong:wrong"),'ACCEPT' => 'application/xml'} + get "/tickler.xml", {}, {'HTTP_AUTHORIZATION' => "Basic " + Base64.encode64("wrong:wrong"),'ACCEPT' => 'application/xml'} assert_response 401 end @@ -32,6 +32,19 @@ class TodoXmlApiTest < ActionDispatch::IntegrationTest assert_no_tag :tag => "user_id" end + def test_get_index_with_only_active_todos + authenticated_get_xml "/todos.xml", @user.login, @password, {} + assert_response 200 + + all_todo_count = assigns['xml_todos'] + + authenticated_get_xml "/todos.xml?limit_to_active_todos=1", @user.login, @password, {} + assert_response 200 + + active_todo_count = assigns['xml_todos'] + assert all_todo_count != active_todo_count, "active should be less than all todos" + end + def test_create_todo_with_show_from old_count = @user.todos.count authenticated_post_xml_to_todo_create "