2012-07-31 16:29:07 +00:00
|
|
|
|
using System;
|
2012-08-03 15:54:05 +00:00
|
|
|
|
using System.Net;
|
2012-07-31 16:29:07 +00:00
|
|
|
|
using System.Net.Http;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.ApiInteraction
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides a base class used by the api and image services
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class BaseClient : IDisposable
|
|
|
|
|
{
|
2012-08-01 19:09:24 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the server host name (myserver or 192.168.x.x)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ServerHostName { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the port number used by the API
|
|
|
|
|
/// </summary>
|
2012-08-03 15:54:05 +00:00
|
|
|
|
public int ServerApiPort { get; set; }
|
2012-08-01 19:09:24 +00:00
|
|
|
|
|
2012-08-03 15:54:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the current api url based on hostname and port.
|
|
|
|
|
/// </summary>
|
2012-08-01 19:09:24 +00:00
|
|
|
|
protected string ApiUrl
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2012-08-03 15:54:05 +00:00
|
|
|
|
return string.Format("http://{0}:{1}/mediabrowser/api", ServerHostName, ServerApiPort);
|
2012-08-01 19:09:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-31 16:29:07 +00:00
|
|
|
|
|
|
|
|
|
protected HttpClient HttpClient { get; private set; }
|
|
|
|
|
|
|
|
|
|
public BaseClient()
|
2012-08-01 01:53:40 +00:00
|
|
|
|
: this(new HttpClientHandler())
|
2012-07-31 16:29:07 +00:00
|
|
|
|
{
|
2012-08-01 01:53:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BaseClient(HttpClientHandler clientHandler)
|
|
|
|
|
{
|
2012-08-05 18:58:24 +00:00
|
|
|
|
clientHandler.AutomaticDecompression = DecompressionMethods.Deflate;
|
2012-08-01 01:53:40 +00:00
|
|
|
|
|
|
|
|
|
HttpClient = new HttpClient(clientHandler);
|
2012-07-31 16:29:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
HttpClient.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|