2013-03-07 06:34:00 +01:00
|
|
|
|
using MediaBrowser.Controller;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
using MediaBrowser.Model.Weather;
|
2013-03-07 06:34:00 +01:00
|
|
|
|
using MediaBrowser.Server.Implementations.HttpServer;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
using ServiceStack.ServiceHost;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class Weather
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Weather", "GET")]
|
2013-03-05 06:08:27 +01:00
|
|
|
|
[ServiceStack.ServiceHost.Api(Description = "Gets weather information for a given location")]
|
2013-02-21 02:33:05 +01:00
|
|
|
|
public class GetWeather : IReturn<WeatherInfo>
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the location.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The location.</value>
|
2013-03-05 06:08:27 +01:00
|
|
|
|
[ApiMember(Name = "Location", Description = "Us zip / City, State, Country / City, Country", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
2013-02-21 02:33:05 +01:00
|
|
|
|
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)
|
|
|
|
|
{
|
2013-03-04 06:43:06 +01:00
|
|
|
|
var result = Kernel.Instance.WeatherProviders.First().GetWeatherInfoAsync(request.Location, CancellationToken.None).Result;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|