WeatherService.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. [ServiceStack.ServiceHost.Api(Description = "Gets weather information for a given location")]
  14. public class GetWeather : IReturn<WeatherInfo>
  15. {
  16. /// <summary>
  17. /// Gets or sets the location.
  18. /// </summary>
  19. /// <value>The location.</value>
  20. [ApiMember(Name = "Location", Description = "Us zip / City, State, Country / City, Country", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
  21. public string Location { get; set; }
  22. }
  23. /// <summary>
  24. /// Class WeatherService
  25. /// </summary>
  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 result = Kernel.Instance.WeatherProviders.First().GetWeatherInfoAsync(request.Location, CancellationToken.None).Result;
  36. return ToOptimizedResult(result);
  37. }
  38. }
  39. }