remove /profile, add /user and /accounts
This commit is contained in:
parent
228f71f407
commit
f2e8ccafc1
11
lib/travis/api/app/endpoint/accounts.rb
Normal file
11
lib/travis/api/app/endpoint/accounts.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
require 'travis/api/app'
|
||||||
|
|
||||||
|
class Travis::Api::App
|
||||||
|
class Endpoint
|
||||||
|
class Accounts < Endpoint
|
||||||
|
get '/', scope: :private do
|
||||||
|
body service(:account).find_all, type: :account
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -180,8 +180,8 @@ class Travis::Api::App
|
||||||
def user_for_github_token(token)
|
def user_for_github_token(token)
|
||||||
data = GH.with(token: token.to_s) { GH['user'] }
|
data = GH.with(token: token.to_s) { GH['user'] }
|
||||||
scopes = parse_scopes data.headers['x-oauth-scopes']
|
scopes = parse_scopes data.headers['x-oauth-scopes']
|
||||||
user = User.find_by_github_id(data['id'])
|
user = ::User.find_by_github_id(data['id'])
|
||||||
user ||= User.create! user_info(data, github_oauth_token: token)
|
user ||= ::User.create! user_info(data, github_oauth_token: token)
|
||||||
|
|
||||||
halt 403, 'not a Travis user' if user.nil?
|
halt 403, 'not a Travis user' if user.nil?
|
||||||
halt 403, 'insufficient access' unless acceptable? scopes
|
halt 403, 'insufficient access' unless acceptable? scopes
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
require 'travis/api/app'
|
|
||||||
|
|
||||||
class Travis::Api::App
|
|
||||||
class Endpoint
|
|
||||||
class Profile < Endpoint
|
|
||||||
LOCALES = %w(en es fr ja eb nl pl pt-Br ru) # TODO how to figure these out
|
|
||||||
|
|
||||||
# Gives information about the currently logged in user.
|
|
||||||
#
|
|
||||||
# Example:
|
|
||||||
#
|
|
||||||
# {
|
|
||||||
# "user": {
|
|
||||||
# "email": "svenfuchs@artweb-design.de",
|
|
||||||
# "gravatar_id": "402602a60e500e85f2f5dc1ff3648ecb",
|
|
||||||
# "is_syncing": false,
|
|
||||||
# "locale": "de",
|
|
||||||
# "login": "svenfuchs",
|
|
||||||
# "name": "Sven Fuchs",
|
|
||||||
# "synced_at": "2012-08-14T22:11:21Z"
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
get '/', scope: :private do
|
|
||||||
body service(:user).find_one, type: :user
|
|
||||||
end
|
|
||||||
|
|
||||||
put '/:id?', scope: :private do
|
|
||||||
update_locale if valid_locale?
|
|
||||||
'ok'
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO: Add implementation and documentation.
|
|
||||||
post '/sync', scope: :private do
|
|
||||||
sync_user(current_user)
|
|
||||||
204
|
|
||||||
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[:profile][:locale].to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
def valid_locale?
|
|
||||||
LOCALES.include?(locale)
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_locale
|
|
||||||
current_user.update_attribute(:locale, locale.to_s)
|
|
||||||
# session[:locale] = locale # ???
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
43
lib/travis/api/app/endpoint/user.rb
Normal file
43
lib/travis/api/app/endpoint/user.rb
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
require 'travis/api/app'
|
||||||
|
|
||||||
|
class Travis::Api::App
|
||||||
|
class Endpoint
|
||||||
|
class User < Endpoint
|
||||||
|
# Gives information about the currently logged in user.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
#
|
||||||
|
# {
|
||||||
|
# "user": {
|
||||||
|
# "name": "Sven Fuchs",
|
||||||
|
# "login": "svenfuchs",
|
||||||
|
# "email": "svenfuchs@artweb-design.de",
|
||||||
|
# "gravatar_id": "402602a60e500e85f2f5dc1ff3648ecb",
|
||||||
|
# "locale": "de",
|
||||||
|
# "is_syncing": false,
|
||||||
|
# "synced_at": "2012-08-14T22:11:21Z"
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
get '/:id?', scope: :private do
|
||||||
|
body current_user
|
||||||
|
end
|
||||||
|
|
||||||
|
put '/:id?', scope: :private do
|
||||||
|
services(:user).update_locale(locale)
|
||||||
|
204
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: Add implementation and documentation.
|
||||||
|
post '/sync', scope: :private do
|
||||||
|
services(:user).sync
|
||||||
|
204
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def locale
|
||||||
|
params[:profile][:locale]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user