BaseClient.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Net.Http;
  3. namespace MediaBrowser.ApiInteraction
  4. {
  5. /// <summary>
  6. /// Provides a base class used by the api and image services
  7. /// </summary>
  8. public abstract class BaseClient : IDisposable
  9. {
  10. /// <summary>
  11. /// Gets or sets the server host name (myserver or 192.168.x.x)
  12. /// </summary>
  13. public string ServerHostName { get; set; }
  14. /// <summary>
  15. /// Gets or sets the port number used by the API
  16. /// </summary>
  17. public int ApiPort { get; set; }
  18. protected string ApiUrl
  19. {
  20. get
  21. {
  22. return string.Format("http://{0}:{1}/mediabrowser/api", ServerHostName, ApiPort);
  23. }
  24. }
  25. protected HttpClient HttpClient { get; private set; }
  26. public BaseClient()
  27. : this(new HttpClientHandler())
  28. {
  29. }
  30. public BaseClient(HttpClientHandler clientHandler)
  31. {
  32. clientHandler.AutomaticDecompression = System.Net.DecompressionMethods.GZip;
  33. HttpClient = new HttpClient(clientHandler);
  34. }
  35. public void Dispose()
  36. {
  37. HttpClient.Dispose();
  38. }
  39. }
  40. }