/// <summary> /// Create new instance of DiskHttpApi. Keep one instance for all requests. /// </summary> /// <param name="baseUrl">Base url to Yandex Disk API.</param> /// <param name="oauthKey"> /// OAuth Key for authorization on API /// <see href="https://tech.yandex.ru/disk/api/concepts/quickstart-docpage/"/> /// </param> /// <param name="logSaver">Instance of custom logger.</param> /// <param name="httpClient"></param> public DiskHttpApi([NotNull] string baseUrl, [NotNull] string oauthKey, [CanBeNull] ILogSaver logSaver, [NotNull] IHttpClient httpClient) { BaseUrl = baseUrl; _httpClient = httpClient; var apiContext = new ApiContext { HttpClient = httpClient, BaseUrl = new Uri(baseUrl), LogSaver = logSaver }; Files = new FilesClient(apiContext); MetaInfo = new MetaInfoClient(apiContext); Commands = new CommandsClient(apiContext); }
public DiskHttpApi([NotNull] string oauthKey, [CanBeNull] ILogSaver logSaver = null) { var clientHandler = new HttpClientHandler(); var httpClient = new HttpClient(clientHandler, disposeHandler: true); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth", oauthKey); httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(AboutInfo.Client.ProductTitle, AboutInfo.Client.Version)); httpClient.Timeout = TimeSpan.FromHours(24); //For support large file uploading and downloading _httpClient = new RealHttpClientWrapper(httpClient); var apiContext = new ApiContext { HttpClient = _httpClient, BaseUrl = new Uri(BaseUrl), LogSaver = logSaver }; Files = new FilesClient(apiContext); MetaInfo = new MetaInfoClient(apiContext); Commands = new CommandsClient(apiContext); }