Add a /api/0.6/user/NNNN call to the API
This commit is contained in:
parent
8e19a9bf7d
commit
3ce4de1295
6 changed files with 96 additions and 49 deletions
|
@ -1,20 +1,22 @@
|
|||
class UserController < ApplicationController
|
||||
layout :choose_layout
|
||||
|
||||
skip_before_filter :verify_authenticity_token, :only => [:api_details, :api_gpx_files]
|
||||
skip_before_filter :verify_authenticity_token, :only => [:api_read, :api_details, :api_gpx_files]
|
||||
before_filter :disable_terms_redirect, :only => [:terms, :save, :logout, :api_details]
|
||||
before_filter :authorize, :only => [:api_details, :api_gpx_files]
|
||||
before_filter :authorize_web, :except => [:api_details, :api_gpx_files]
|
||||
before_filter :set_locale, :except => [:api_details, :api_gpx_files]
|
||||
before_filter :authorize_web, :except => [:api_read, :api_details, :api_gpx_files]
|
||||
before_filter :set_locale, :except => [:api_read, :api_details, :api_gpx_files]
|
||||
before_filter :require_user, :only => [:account, :go_public, :make_friend, :remove_friend]
|
||||
before_filter :check_database_readable, :except => [:login, :api_details, :api_gpx_files]
|
||||
before_filter :check_database_readable, :except => [:login, :api_read, :api_details, :api_gpx_files]
|
||||
before_filter :check_database_writable, :only => [:new, :account, :confirm, :confirm_email, :lost_password, :reset_password, :go_public, :make_friend, :remove_friend]
|
||||
before_filter :check_api_readable, :only => [:api_details, :api_gpx_files]
|
||||
before_filter :check_api_readable, :only => [:api_read, :api_details, :api_gpx_files]
|
||||
before_filter :require_allow_read_prefs, :only => [:api_details]
|
||||
before_filter :require_allow_read_gpx, :only => [:api_gpx_files]
|
||||
before_filter :require_cookies, :only => [:login, :confirm]
|
||||
before_filter :require_administrator, :only => [:set_status, :delete, :list]
|
||||
before_filter :lookup_this_user, :only => [:set_status, :delete]
|
||||
around_filter :api_call_handle_error, :only => [:api_read, :api_details, :api_gpx_files]
|
||||
before_filter :lookup_user_by_id, :only => [:api_read]
|
||||
before_filter :lookup_user_by_name, :only => [:set_status, :delete]
|
||||
|
||||
cache_sweeper :user_sweeper, :only => [:account, :set_status, :delete]
|
||||
|
||||
|
@ -373,6 +375,15 @@ class UserController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def api_read
|
||||
render :nothing => true, :status => :gone unless @this_user.visible?
|
||||
end
|
||||
|
||||
def api_details
|
||||
@this_user = @user
|
||||
render :action => :api_read
|
||||
end
|
||||
|
||||
def api_gpx_files
|
||||
doc = OSM::API.new.get_xml_doc
|
||||
@user.traces.each do |trace|
|
||||
|
@ -714,7 +725,13 @@ private
|
|||
|
||||
##
|
||||
# ensure that there is a "this_user" instance variable
|
||||
def lookup_this_user
|
||||
def lookup_user_by_id
|
||||
@this_user = User.find(params[:id])
|
||||
end
|
||||
|
||||
##
|
||||
# ensure that there is a "this_user" instance variable
|
||||
def lookup_user_by_name
|
||||
@this_user = User.find_by_display_name(params[:display_name])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
redirect_to :controller => 'user', :action => 'view', :display_name => params[:display_name] unless @this_user
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
xml.instruct! :xml, :version => "1.0"
|
||||
xml.osm("version" => API_VERSION, "generator" => GENERATOR) do
|
||||
xml.tag! "user", :id => @user.id,
|
||||
:display_name => @user.display_name,
|
||||
:account_created => @user.creation_time.xmlschema do
|
||||
if @user.description
|
||||
xml.tag! "description", @user.description
|
||||
end
|
||||
xml.tag! "contributor-terms",
|
||||
:agreed => !!@user.terms_agreed,
|
||||
:pd => !!@user.consider_pd
|
||||
if @user.home_lat and @user.home_lon
|
||||
xml.tag! "home", :lat => @user.home_lat,
|
||||
:lon => @user.home_lon,
|
||||
:zoom => @user.home_zoom
|
||||
end
|
||||
if @user.image.file?
|
||||
xml.tag! "img", :href => "http://#{SERVER_URL}#{@user.image.url}"
|
||||
end
|
||||
if @user.languages
|
||||
xml.tag! "languages" do
|
||||
@user.languages.split(",") { |lang| xml.tag! "lang", lang }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
app/views/user/api_read.builder
Normal file
28
app/views/user/api_read.builder
Normal file
|
@ -0,0 +1,28 @@
|
|||
xml.instruct! :xml, :version => "1.0"
|
||||
xml.osm("version" => API_VERSION, "generator" => GENERATOR) do
|
||||
xml.tag! "user", :id => @this_user.id,
|
||||
:display_name => @this_user.display_name,
|
||||
:account_created => @this_user.creation_time.xmlschema do
|
||||
if @this_user.description
|
||||
xml.tag! "description", @this_user.description
|
||||
end
|
||||
xml.tag! "contributor-terms",
|
||||
:agreed => !!@this_user.terms_agreed,
|
||||
:pd => !!@this_user.consider_pd
|
||||
if @this_user.image.file?
|
||||
xml.tag! "img", :href => "http://#{SERVER_URL}#{@this_user.image.url}"
|
||||
end
|
||||
if @user && @user == @this_user
|
||||
if @this_user.home_lat and @this_user.home_lon
|
||||
xml.tag! "home", :lat => @this_user.home_lat,
|
||||
:lon => @this_user.home_lon,
|
||||
:zoom => @this_user.home_zoom
|
||||
end
|
||||
if @this_user.languages
|
||||
xml.tag! "languages" do
|
||||
@this_user.languages.split(",") { |lang| xml.tag! "lang", lang }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue