IHttpClient.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. namespace MediaBrowser.Common.Net
  7. {
  8. /// <summary>
  9. /// Interface IHttpClient
  10. /// </summary>
  11. public interface IHttpClient : IDisposable
  12. {
  13. /// <summary>
  14. /// Performs a GET request and returns the resulting stream
  15. /// </summary>
  16. /// <param name="url">The URL.</param>
  17. /// <param name="resourcePool">The resource pool.</param>
  18. /// <param name="cancellationToken">The cancellation token.</param>
  19. /// <returns>Task{Stream}.</returns>
  20. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  21. Task<Stream> Get(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken);
  22. /// <summary>
  23. /// Gets the specified URL.
  24. /// </summary>
  25. /// <param name="url">The URL.</param>
  26. /// <param name="cancellationToken">The cancellation token.</param>
  27. /// <returns>Task{Stream}.</returns>
  28. Task<Stream> Get(string url, CancellationToken cancellationToken);
  29. /// <summary>
  30. /// Performs a POST request
  31. /// </summary>
  32. /// <param name="url">The URL.</param>
  33. /// <param name="postData">Params to add to the POST data.</param>
  34. /// <param name="resourcePool">The resource pool.</param>
  35. /// <param name="cancellationToken">The cancellation token.</param>
  36. /// <returns>stream on success, null on failure</returns>
  37. /// <exception cref="System.ArgumentNullException">postData</exception>
  38. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  39. Task<Stream> Post(string url, Dictionary<string, string> postData, SemaphoreSlim resourcePool, CancellationToken cancellationToken);
  40. /// <summary>
  41. /// Posts the specified URL.
  42. /// </summary>
  43. /// <param name="url">The URL.</param>
  44. /// <param name="postData">The post data.</param>
  45. /// <param name="cancellationToken">The cancellation token.</param>
  46. /// <returns>Task{Stream}.</returns>
  47. Task<Stream> Post(string url, Dictionary<string, string> postData, CancellationToken cancellationToken);
  48. /// <summary>
  49. /// Downloads the contents of a given url into a temporary location
  50. /// </summary>
  51. /// <param name="options">The options.</param>
  52. /// <returns>Task{System.String}.</returns>
  53. /// <exception cref="System.ArgumentNullException">progress</exception>
  54. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  55. Task<string> GetTempFile(HttpRequestOptions options);
  56. /// <summary>
  57. /// Downloads the contents of a given url into a MemoryStream
  58. /// </summary>
  59. /// <param name="url">The URL.</param>
  60. /// <param name="resourcePool">The resource pool.</param>
  61. /// <param name="cancellationToken">The cancellation token.</param>
  62. /// <returns>Task{MemoryStream}.</returns>
  63. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  64. Task<MemoryStream> GetMemoryStream(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken);
  65. /// <summary>
  66. /// Gets the memory stream.
  67. /// </summary>
  68. /// <param name="url">The URL.</param>
  69. /// <param name="cancellationToken">The cancellation token.</param>
  70. /// <returns>Task{MemoryStream}.</returns>
  71. Task<MemoryStream> GetMemoryStream(string url, CancellationToken cancellationToken);
  72. }
  73. }