mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-27 11:16:10 +01:00
fix #1078 and document it on the REST_API page
This commit is contained in:
parent
ed2154b94b
commit
174becee81
3 changed files with 67 additions and 23 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -56,6 +56,10 @@
|
|||
<ul>
|
||||
<li>/todos.xml</li>
|
||||
<li>/todos/<code>ID</code>.xml</li>
|
||||
<li>/tickler.xml</li>
|
||||
<li>/done.xml</li>
|
||||
<li>/hidden.xml</li>
|
||||
<li>/calendar.xml</li>
|
||||
<li>/contexts.xml</li>
|
||||
<li>/contexts/<code>ID</code>.xml</li>
|
||||
<li>/contexts/<code>ID</code>/todos.xml</li>
|
||||
|
|
@ -64,6 +68,17 @@
|
|||
<li>/projects/<code>ID</code>/todos.xml</li>
|
||||
</ul>
|
||||
|
||||
<p>For the todo resources (todos, tickler, done, hidden and calendar) you can limit the returned
|
||||
field to <code>ID, created_at, modified_at, completed_at</code> by adding the parameter
|
||||
<code>limit_fields</code> and setting it to <code>index</code>. For example:</p>
|
||||
|
||||
<pre>
|
||||
<code>
|
||||
$ curl -u username:p4ssw0rd -H "Content-Type: text/xml" \
|
||||
<%= home_url %>tickler.xml?limit_fields=index
|
||||
</code>
|
||||
</pre>
|
||||
|
||||
<h2>Writing to the API</h2>
|
||||
|
||||
<p>The API provides mechanisms for adding, updating and deleting resources using the HTTP methods <code>PUT</code>, <code>POST</code> and <code>DELETE</code> in combination with the content.</p>
|
||||
|
|
@ -173,17 +188,17 @@ $ curl -u username:p4ssw0rd -H "Content-Type: text/xml" \
|
|||
|
||||
<pre>
|
||||
<code>
|
||||
$ 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>
|
||||
</code>
|
||||
</pre>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue