WeatherService.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using MediaBrowser.Controller;
  2. using MediaBrowser.Model.Weather;
  3. using ServiceStack.ServiceHost;
  4. using System.Linq;
  5. using System.Threading;
  6. namespace MediaBrowser.Api
  7. {
  8. /// <summary>
  9. /// Class Weather
  10. /// </summary>
  11. [Route("/Weather", "GET")]
  12. [Api(Description = "Gets weather information for a given location")]
  13. public class GetWeather : IReturn<WeatherInfo>
  14. {
  15. /// <summary>
  16. /// Gets or sets the location.
  17. /// </summary>
  18. /// <value>The location.</value>
  19. [ApiMember(Name = "Location", Description = "Us zip / City, State, Country / City, Country", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
  20. public string Location { get; set; }
  21. }
  22. /// <summary>
  23. /// Class WeatherService
  24. /// </summary>
  25. public class WeatherService : BaseApiService
  26. {
  27. /// <summary>
  28. /// Gets the specified request.
  29. /// </summary>
  30. /// <param name="request">The request.</param>
  31. /// <returns>System.Object.</returns>
  32. public object Get(GetWeather request)
  33. {
  34. var result = Kernel.Instance.WeatherProviders.First().GetWeatherInfoAsync(request.Location, CancellationToken.None).Result;
  35. return ToOptimizedResult(result);
  36. }
  37. }
  38. }