2
0

WeatherService.cs 1.2 KB

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