aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/WeatherService.cs
blob: c79c2da2849de20cf948204bdd92084b146d2b0d (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.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Model.Weather;
using ServiceStack.ServiceHost;
using System.Linq;
using System.Threading;

namespace MediaBrowser.Api
{
    /// <summary>
    /// Class Weather
    /// </summary>
    [Route("/Weather", "GET")]
    public class GetWeather : IReturn<WeatherInfo>
    {
        /// <summary>
        /// Gets or sets the location.
        /// </summary>
        /// <value>The location.</value>
        public string Location { get; set; }
    }

    /// <summary>
    /// Class WeatherService
    /// </summary>
    public class WeatherService : BaseRestService
    {
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetWeather request)
        {
            var kernel = (Kernel) Kernel;

            var location = string.IsNullOrWhiteSpace(request.Location) ? kernel.Configuration.WeatherLocation : request.Location;

            var result = kernel.WeatherProviders.First().GetWeatherInfoAsync(location, CancellationToken.None).Result;

            return ToOptimizedResult(result);
        }
    }
}