From 3387c185fa9e226cfc3d0aca4713eff166089348 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sun, 16 Sep 2012 00:45:38 +0200 Subject: [PATCH] fake sign in --- lib/travis/api/app/endpoint.rb | 7 ++++- lib/travis/api/app/endpoint/branches.rb | 2 +- lib/travis/api/app/endpoint/hooks.rb | 5 ++-- lib/travis/api/app/endpoint/profile.rb | 39 +++++++++++++++++++++++-- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/lib/travis/api/app/endpoint.rb b/lib/travis/api/app/endpoint.rb index 6fc5ced8..31eb233e 100644 --- a/lib/travis/api/app/endpoint.rb +++ b/lib/travis/api/app/endpoint.rb @@ -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 diff --git a/lib/travis/api/app/endpoint/branches.rb b/lib/travis/api/app/endpoint/branches.rb index 29917ca7..52d83a50 100644 --- a/lib/travis/api/app/endpoint/branches.rb +++ b/lib/travis/api/app/endpoint/branches.rb @@ -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 diff --git a/lib/travis/api/app/endpoint/hooks.rb b/lib/travis/api/app/endpoint/hooks.rb index cf2ebfae..fd590db5 100644 --- a/lib/travis/api/app/endpoint/hooks.rb +++ b/lib/travis/api/app/endpoint/hooks.rb @@ -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. diff --git a/lib/travis/api/app/endpoint/profile.rb b/lib/travis/api/app/endpoint/profile.rb index 8a9096c6..5e6f3fa7 100644 --- a/lib/travis/api/app/endpoint/profile.rb +++ b/lib/travis/api/app/endpoint/profile.rb @@ -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