aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/ApiService.cs
blob: e6e4594c16fe56c3e0eb42b38ed783004a9861cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
using System;
using System.Net;

namespace MediaBrowser.Api
{
    /// <summary>
    /// Contains some helpers for the api
    /// </summary>
    public static class ApiService
    {
        /// <summary>
        /// Gets a User by Id
        /// </summary>
        /// <param name="id">The id of the user</param>
        /// <returns>User.</returns>
        /// <exception cref="System.ArgumentNullException">id</exception>
        public static User GetUserById(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            var guid = new Guid(id);

            return Kernel.Instance.GetUserById(guid);
        }

        /// <summary>
        /// Determines whether [is API URL match] [the specified URL].
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="request">The request.</param>
        /// <returns><c>true</c> if [is API URL match] [the specified URL]; otherwise, <c>false</c>.</returns>
        public static bool IsApiUrlMatch(string url, HttpListenerRequest request)
        {
            url = "/api/" + url;

            return request.Url.LocalPath.EndsWith(url, StringComparison.OrdinalIgnoreCase);
        }
    }
}