2014-09-14 10:42:23 -07:00
|
|
|
|
using MediaBrowser.Controller.Connect;
|
2014-09-14 08:10:51 -07:00
|
|
|
|
using MediaBrowser.Controller.Net;
|
2014-10-13 13:14:53 -07:00
|
|
|
|
using MediaBrowser.Model.Connect;
|
2014-09-14 08:10:51 -07:00
|
|
|
|
using ServiceStack;
|
2014-10-13 13:14:53 -07:00
|
|
|
|
using System.Collections.Generic;
|
2014-09-14 10:42:23 -07:00
|
|
|
|
using System.Threading.Tasks;
|
2014-09-14 08:10:51 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
|
|
|
|
[Route("/Users/{Id}/Connect/Link", "POST", Summary = "Creates a Connect link for a user")]
|
2014-09-14 16:39:06 -07:00
|
|
|
|
public class CreateConnectLink : IReturn<UserLinkResult>
|
2014-09-14 08:10:51 -07:00
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Id", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "ConnectUsername", Description = "Connect username", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
|
|
|
|
public string ConnectUsername { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("/Users/{Id}/Connect/Link", "DELETE", Summary = "Removes a Connect link for a user")]
|
2014-09-14 10:12:47 -07:00
|
|
|
|
public class DeleteConnectLink : IReturnVoid
|
2014-09-14 08:10:51 -07:00
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Id", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")]
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
2014-09-14 10:42:23 -07:00
|
|
|
|
|
2014-10-13 13:14:53 -07:00
|
|
|
|
[Route("/Connect/Invite", "POST", Summary = "Creates a Connect link for a user")]
|
|
|
|
|
public class CreateConnectInvite : IReturn<UserLinkResult>
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "ConnectUsername", Description = "Connect username", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
|
|
|
|
public string ConnectUsername { get; set; }
|
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "SendingUserId", Description = "Sending User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")]
|
|
|
|
|
public string SendingUserId { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Route("/Connect/Pending", "GET", Summary = "Creates a Connect link for a user")]
|
|
|
|
|
public class GetPendingGuests : IReturn<List<ConnectAuthorization>>
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Route("/Connect/Pending", "DELETE", Summary = "Deletes a Connect link for a user")]
|
|
|
|
|
public class DeleteAuthorization : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Id", Description = "Authorization Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")]
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-14 10:42:23 -07:00
|
|
|
|
[Authenticated(Roles = "Admin")]
|
2014-09-14 08:10:51 -07:00
|
|
|
|
public class ConnectService : BaseApiService
|
|
|
|
|
{
|
|
|
|
|
private readonly IConnectManager _connectManager;
|
|
|
|
|
|
|
|
|
|
public ConnectService(IConnectManager connectManager)
|
|
|
|
|
{
|
|
|
|
|
_connectManager = connectManager;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-14 16:39:06 -07:00
|
|
|
|
public object Post(CreateConnectLink request)
|
2014-09-14 08:10:51 -07:00
|
|
|
|
{
|
2014-09-14 16:39:06 -07:00
|
|
|
|
return _connectManager.LinkUser(request.Id, request.ConnectUsername);
|
2014-09-14 08:10:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-13 13:14:53 -07:00
|
|
|
|
public object Post(CreateConnectInvite request)
|
|
|
|
|
{
|
|
|
|
|
return _connectManager.InviteUser(request.SendingUserId, request.ConnectUsername);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-14 08:10:51 -07:00
|
|
|
|
public void Delete(DeleteConnectLink request)
|
|
|
|
|
{
|
|
|
|
|
var task = _connectManager.RemoveLink(request.Id);
|
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
2014-10-13 13:14:53 -07:00
|
|
|
|
|
|
|
|
|
public async Task<object> Get(GetPendingGuests request)
|
|
|
|
|
{
|
|
|
|
|
var result = await _connectManager.GetPendingGuests().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Delete(DeleteAuthorization request)
|
|
|
|
|
{
|
|
|
|
|
var task = _connectManager.CancelAuthorization(request.Id);
|
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
2014-09-14 08:10:51 -07:00
|
|
|
|
}
|
|
|
|
|
}
|