BaseClient.cs 1.4 KB

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