2014-03-29 00:59:26 +00:00
|
|
|
class Api::V1::UsersController < Api::V1::BaseController
|
|
|
|
def index
|
2014-08-28 20:43:11 +00:00
|
|
|
render json: Api::V1::UsersCollection.as_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2015-10-28 14:31:05 +00:00
|
|
|
if params[:format].nil? || params[:format] == "id"
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
elsif params[:format] == "steamid"
|
|
|
|
steamid_i = params[:id].to_i
|
|
|
|
@user = User.first(conditions: { steamid: format("0:%d:%d", steamid_i % 2, steamid_i >> 1) })
|
|
|
|
elsif params[:format] == "steamidstr"
|
|
|
|
@user = User.first(conditions: { steamid: params[:id] })
|
|
|
|
end
|
|
|
|
|
|
|
|
if @user.nil?
|
2017-09-30 02:07:40 +00:00
|
|
|
not_found
|
2017-09-29 20:43:14 +00:00
|
|
|
return
|
2015-10-28 14:31:05 +00:00
|
|
|
end
|
|
|
|
|
2015-09-24 03:03:24 +00:00
|
|
|
if @user.steamid.present?
|
|
|
|
@steam = steam_profile @user
|
|
|
|
end
|
2014-08-28 20:43:11 +00:00
|
|
|
|
|
|
|
render json: {
|
2015-07-21 13:27:33 +00:00
|
|
|
id: @user.id,
|
|
|
|
username: @user.username,
|
|
|
|
country: @user.country,
|
|
|
|
time_zone: @user.time_zone,
|
|
|
|
avatar: @user.profile.avatar.url,
|
|
|
|
admin: @user.admin?,
|
2015-10-28 14:31:05 +00:00
|
|
|
referee: @user.ref?,
|
|
|
|
caster: @user.caster?,
|
2015-10-20 17:11:46 +00:00
|
|
|
moderator: @user.gather_moderator?,
|
2015-09-24 02:16:35 +00:00
|
|
|
steam: @user.steamid.nil? ? nil : {
|
2015-08-30 14:58:06 +00:00
|
|
|
id: @user.steamid,
|
2015-08-17 18:16:32 +00:00
|
|
|
url: @steam.nil? ? nil : @steam.base_url,
|
2015-08-17 18:06:47 +00:00
|
|
|
nickname: @steam.nil? ? nil : @steam.nickname
|
2015-08-01 15:44:39 +00:00
|
|
|
},
|
|
|
|
bans: {
|
|
|
|
gather: @user.banned?(Ban::TYPE_GATHER).present?,
|
|
|
|
mute: @user.banned?(Ban::TYPE_MUTE).present?,
|
|
|
|
site: @user.banned?(Ban::TYPE_SITE).present?
|
2015-08-01 16:05:17 +00:00
|
|
|
},
|
|
|
|
team: @user.team.present? ? { id: @user.team.id, name: @user.team.name } : nil
|
2014-08-28 20:43:11 +00:00
|
|
|
}
|
2015-07-22 16:22:38 +00:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2017-09-30 02:07:40 +00:00
|
|
|
not_found
|
2014-03-29 00:59:26 +00:00
|
|
|
end
|
2015-08-17 18:06:47 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-09-30 02:07:40 +00:00
|
|
|
def not_found
|
2017-09-30 12:35:27 +00:00
|
|
|
render json: {error: "User not found"}, status: :not_found
|
2017-09-30 02:07:40 +00:00
|
|
|
end
|
|
|
|
|
2015-08-17 18:16:32 +00:00
|
|
|
def steam_profile(user)
|
2015-08-17 18:06:47 +00:00
|
|
|
SteamCondenser::Community::SteamId.from_steam_id("STEAM_#{user.steamid}")
|
2015-08-17 18:16:32 +00:00
|
|
|
rescue SteamCondenser::Error
|
|
|
|
nil
|
2015-08-17 18:06:47 +00:00
|
|
|
end
|
2014-03-31 21:33:16 +00:00
|
|
|
end
|