diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 12dbba66..058dfd5c 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -26,7 +26,7 @@ class TodosController < ApplicationController respond_to do |format| format.html &render_todos_html format.m &render_todos_mobile - format.xml { render :xml => @todos.to_xml( :except => :user_id ) } + format.xml { render :xml => @todos.to_xml( *to_xml_params ) } format.rss &render_rss_feed format.atom &render_atom_feed format.text &render_text_feed @@ -230,7 +230,7 @@ class TodosController < ApplicationController @return_path=cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path render :action => 'show' end - format.xml { render :xml => @todo.to_xml( :root => 'todo', :except => :user_id, :include => [:tags] ) } + format.xml { render :xml => @todo.to_xml( *to_xml_params ) } end end @@ -305,7 +305,7 @@ class TodosController < ApplicationController end render end - format.xml { render :xml => @todo.to_xml( :except => :user_id ) } + format.xml { render :xml => @todo.to_xml( *to_xml_params ) } format.html do if @saved # TODO: I think this will work, but can't figure out how to test it @@ -325,7 +325,7 @@ class TodosController < ApplicationController @saved = true # cannot determine error respond_to do |format| format.js - format.xml { render :xml => @todo.to_xml( :except => :user_id ) } + format.xml { render :xml => @todo.to_xml( *to_xml_params ) } format.html { redirect_to request.referrer} end end @@ -345,7 +345,7 @@ class TodosController < ApplicationController respond_to do |format| format.js { render :action => :update } - format.xml { render :xml => @todo.to_xml( :except => :user_id ) } + format.xml { render :xml => @todo.to_xml( *to_xml_params ) } end end @@ -385,7 +385,7 @@ class TodosController < ApplicationController @status_message = t('todos.added_new_project') + ' / ' + @status_message if @new_project_created @status_message = t('todos.added_new_context') + ' / ' + @status_message if @new_context_created } - format.xml { render :xml => @todo.to_xml( :except => :user_id ) } + format.xml { render :xml => @todo.to_xml( *to_xml_params ) } format.m do if @saved if cookies[:mobile_url] @@ -473,6 +473,11 @@ class TodosController < ApplicationController @done_this_week = get_done_this_week(completed_todos) @done_this_month = get_done_this_month(completed_todos) @count = @done_today.size + @done_this_week.size + @done_this_month.size + + respond_to do |format| + format.html + format.xml { render :xml => completed_todos.to_xml( *to_xml_params ) } + end end def all_done @@ -497,7 +502,7 @@ class TodosController < ApplicationController respond_to do |format| format.html format.m { render :action => 'mobile_list_deferred' } - format.xml { render :xml => @not_done_todos.to_xml( :except => :user_id ) } + format.xml { render :xml => @not_done_todos.to_xml( *to_xml_params ) } end end @@ -687,6 +692,19 @@ class TodosController < ApplicationController @due_all = current_user.todos.not_completed.are_due.find(:all, :order => "due") render :action => 'calendar', :layout => false, :content_type => Mime::ICS } + format.xml { + @due_all = current_user.todos.not_completed.are_due.find(:all, :order => "due") + render :xml => @due_all.to_xml( *to_xml_params ) + } + end + end + + def list_hidden + @hidden = current_user.todos.hidden + respond_to do |format| + format.xml { + render :xml => @hidden.to_xml( *to_xml_params ) + } end end @@ -754,6 +772,14 @@ class TodosController < ApplicationController private + def to_xml_params + if params[:limit_fields] == 'index' + return [:only => [:id, :created_at, :updated_at, :completed_at] ] + else + return [:except => :user_id, :include => [:tags] ] + end + end + def get_todo_from_params # TODO: this was a :append_before but was removed to tune performance per # method. Reconsider re-enabling it diff --git a/app/views/integrations/rest_api.html.erb b/app/views/integrations/rest_api.html.erb index e4769410..317332ab 100644 --- a/app/views/integrations/rest_api.html.erb +++ b/app/views/integrations/rest_api.html.erb @@ -56,6 +56,10 @@
ID.xmlID.xmlID/todos.xmlID/todos.xmlFor the todo resources (todos, tickler, done, hidden and calendar) you can limit the returned
+field to ID, created_at, modified_at, completed_at by adding the parameter
+limit_fields and setting it to index. For example:
+
+ $ curl -u username:p4ssw0rd -H "Content-Type: text/xml" \
+ <%= home_url %>tickler.xml?limit_fields=index
+
+
+
The API provides mechanisms for adding, updating and deleting resources using the HTTP methods PUT, POST and DELETE in combination with the content.
-$ script/console
+$ script/console
Loading development environment (Rails 1.2.4)
>> class Context < ActiveResource::Base; end
=> nil
>> Context.site = "<%= home_url %>"
-=> "<%= home_url %>"
->> Context.site.user = "username"
-=> "username"
+=> "<%= home_url %>"
+>> Context.site.user = "username"
+=> "username"
->> Context.site.password = CGI.escape "p4ssw0rd"
-=> "p4ssw0rd"
+>> Context.site.password = CGI.escape "p4ssw0rd"
+=> "p4ssw0rd"
>> Context.find :first
=> #<Context:0x262396c @prefix_options={}, @attributes={...}>
>> >> Context.find :all
@@ -201,7 +216,7 @@ $ SITE="http://username:p4ssw0rd@<%= request.host_with_port %>" irb \
irb(main):001:0> inbox = Tracks::Context.find :first
irb(main):002:0> inbox.name
-=> "@inbox"
+=> "@inbox"
irb(main):003:0>
diff --git a/config/routes.rb b/config/routes.rb
index 830e4f63..1261ed40 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -3,7 +3,7 @@ ActionController::Routing::Routes.draw do |map|
:member => {:change_password => :get, :update_password => :post,
:change_auth_type => :get, :update_auth_type => :post, :complete => :get,
:refresh_token => :post }
-
+
map.with_options :controller => :users do |users|
users.signup 'signup', :action => "new"
end
@@ -12,11 +12,11 @@ ActionController::Routing::Routes.draw do |map|
contexts.resources :todos, :name_prefix => "context_"
end
- map.resources :projects, :collection => {:order => :post, :alphabetize => :post, :actionize => :post, :done => :get},
+ map.resources :projects, :collection => {:order => :post, :alphabetize => :post, :actionize => :post, :done => :get},
:member => {:done_todos => :get, :all_done_todos => :get} do |projects|
projects.resources :todos, :name_prefix => "project_"
end
-
+
map.resources :notes
map.resources :todos,
@@ -28,7 +28,7 @@ ActionController::Routing::Routes.draw do |map|
todos.home '', :action => "index"
todos.tickler 'tickler.:format', :action => "list_deferred"
todos.mobile_tickler 'tickler.m', :action => "list_deferred", :format => 'm'
-
+
# This route works for tags with dots like /todos/tag/version1.5
# please note that this pattern consumes everything after /todos/tag
# so /todos/tag/version1.5.xml will result in :name => 'version1.5.xml'
@@ -41,10 +41,13 @@ ActionController::Routing::Routes.draw do |map|
todos.tags 'tags.autocomplete', :action => "tags", :format => 'autocomplete'
todos.auto_complete_for_predecessor 'auto_complete_for_predecessor', :action => 'auto_complete_for_predecessor'
-
+
todos.calendar 'calendar.ics', :action => "calendar", :format => 'ics'
+ todos.calendar 'calendar.xml', :action => "calendar", :format => 'xml'
todos.calendar 'calendar', :action => "calendar"
-
+
+ todos.hidden 'hidden.xml', :action => "list_hidden", :format => 'xml'
+
todos.mobile 'mobile', :action => "index", :format => 'm'
todos.mobile_abbrev 'm', :action => "index", :format => 'm'
todos.mobile_abbrev_new 'm/new', :action => "new", :format => 'm'
@@ -74,7 +77,7 @@ ActionController::Routing::Routes.draw do |map|
fl.mobile_feeds 'feeds.m', :action => 'index', :format => 'm'
fl.feeds 'feeds', :action => 'index'
end
-
+
map.with_options :controller => :integrations do |i|
i.integrations 'integrations', :action => 'index'
i.rest_api_docs 'integrations/rest_api', :action => "rest_api"
@@ -83,12 +86,12 @@ ActionController::Routing::Routes.draw do |map|
end
map.preferences 'preferences', :controller => 'preferences', :action => 'index'
-
+
map.with_options :controller => :stats do |stats|
stats.stats 'stats', :action => 'index'
stats.done_overview 'done', :action => 'done'
end
-
+
map.search 'search', :controller => 'search', :action => 'index'
map.data 'data', :controller => 'data', :action => 'index'