using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Connectivity;
using ServiceStack.Common.Web;
using System;
using System.Net;
using System.Threading.Tasks;
namespace MediaBrowser.Api
{
///
/// Contains some helpers for the api
///
public static class ApiService
{
///
/// Gets a User by Id
///
/// The id of the user
/// User.
/// id
public static User GetUserById(string id)
{
if (string.IsNullOrEmpty(id))
{
throw new ArgumentNullException("id");
}
var guid = new Guid(id);
return Kernel.Instance.GetUserById(guid);
}
///
/// Determines whether [is API URL match] [the specified URL].
///
/// The URL.
/// The request.
/// true if [is API URL match] [the specified URL]; otherwise, false.
public static bool IsApiUrlMatch(string url, HttpListenerRequest request)
{
url = "/api/" + url;
return request.Url.LocalPath.EndsWith(url, StringComparison.OrdinalIgnoreCase);
}
/////
///// Gets the current user.
/////
///// The request.
///// Task{User}.
//public static async Task GetCurrentUser(AuthenticatedRequest request)
//{
// var user = GetUserById(request.UserId);
// if (user == null)
// {
// throw HttpError.Unauthorized("Invalid user or password entered.");
// }
// var clientType = ClientType.Other;
// if (!string.IsNullOrEmpty(request.Client))
// {
// ClientType type;
// if (Enum.TryParse(request.Client, true, out type))
// {
// clientType = type;
// }
// }
// await Kernel.Instance.UserManager.LogUserActivity(user, clientType, request.Device).ConfigureAwait(false);
// return user;
//}
}
}