fake sign in

This commit is contained in:
Sven Fuchs 2012-09-16 00:45:38 +02:00
parent a8fc2f0e7a
commit 3387c185fa
4 changed files with 47 additions and 6 deletions

View File

@ -15,7 +15,12 @@ class Travis::Api::App
def service(key)
const = Travis.services[key] || raise("no service registered for #{key}")
const.new(respond_to?(:current_user) ? current_user : nil)
const.new(current_user)
end
def current_user
# TODO
User.where(:login => 'svenfuchs').first
end
end
end

View File

@ -6,7 +6,7 @@ class Travis::Api::App
class Branches < Endpoint
# TODO: Add documentation.
get('/') do
body service(:branches).find_all(params), :type => :branches
body service(:branches).find_all(params), type: :branches
end
end
end

View File

@ -5,8 +5,9 @@ class Travis::Api::App
# TODO: Add documentation.
class Hooks < Endpoint
# TODO: Add implementation and documentation.
get('/', scope: :private) do
body service(:builds).find_all(params)
# TODO scope: :private
get('/') do
body service(:hooks).find_all(params), type: :hooks
end
# TODO: Add implementation and documentation.

View File

@ -18,10 +18,45 @@ class Travis::Api::App
# "synced_at": "2012-08-14T22:11:21Z"
# }
# }
get('/', scope: :private) { body(user) }
get '/', scope: :private do
body user
end
put '/', scope: :private do
raise NotImplementedError
update_locale if valid_locale?
'ok'
end
# TODO: Add implementation and documentation.
post('/sync', scope: :private) { raise NotImplementedError }
post '/sync', scope: :private do
raise NotImplementedError
sync_user(current_user)
'ok'
end
private
def sync_user(user)
unless user.is_syncing?
publisher = Travis::Amqp::Publisher.new('sync.user')
publisher.publish({ user_id: user.id }, type: 'sync')
user.update_column(:is_syncing, true)
end
end
def locale
params[:user][:locale]
end
def valid_locale?
I18n.available_locales.include?(locale.to_sym) # ???
end
def update_locale
current_user.update_attributes!(:locale => locale.to_s)
session[:locale] = locale # ???
end
end
end
end