WeatherService.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using MediaBrowser.Common.Net;
  2. using MediaBrowser.Controller;
  3. using MediaBrowser.Model.Weather;
  4. using ServiceStack.ServiceHost;
  5. using System.ComponentModel.Composition;
  6. using System.Linq;
  7. using System.Threading;
  8. namespace MediaBrowser.Api
  9. {
  10. /// <summary>
  11. /// Class Weather
  12. /// </summary>
  13. [Route("/Weather", "GET")]
  14. public class GetWeather : IReturn<WeatherInfo>
  15. {
  16. /// <summary>
  17. /// Gets or sets the location.
  18. /// </summary>
  19. /// <value>The location.</value>
  20. public string Location { get; set; }
  21. }
  22. /// <summary>
  23. /// Class WeatherService
  24. /// </summary>
  25. [Export(typeof(IRestfulService))]
  26. public class WeatherService : BaseRestService
  27. {
  28. /// <summary>
  29. /// Gets the specified request.
  30. /// </summary>
  31. /// <param name="request">The request.</param>
  32. /// <returns>System.Object.</returns>
  33. public object Get(GetWeather request)
  34. {
  35. var kernel = (Kernel) Kernel;
  36. var location = string.IsNullOrWhiteSpace(request.Location) ? kernel.Configuration.WeatherLocation : request.Location;
  37. var result = kernel.WeatherProviders.First().GetWeatherInfoAsync(location, CancellationToken.None).Result;
  38. return ToOptimizedResult(result);
  39. }
  40. }
  41. }