/// <summary> /// HTTP Get request for stream service. /// </summary> /// <param name="requestUri">Uri to make OAuth request.</param> /// <param name="tokens">Tokens to pass in request.</param> /// <param name="callback">Function invoked when stream available.</param> /// <param name="signatureManager">Signature manager to sign the OAuth requests</param> /// <returns>awaitable task</returns> public async Task ExecuteGetStreamAsync(Uri requestUri, TwitterOAuthTokens tokens, TwitterStreamCallbacks.RawJsonCallback callback, ISignatureManager signatureManager) { using (var request = new HttpRequestMessage(HttpMethod.Get, requestUri)) { var requestBuilder = new TwitterOAuthRequestBuilder(requestUri, tokens, signatureManager); request.Headers.Authorization = AuthenticationHeaderValue.Parse(requestBuilder.AuthorizationHeader); using (var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false)) { response.ThrowIfNotValid(); var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); using (var reader = new StreamReader(responseStream)) { while (!_abort && !reader.EndOfStream) { var result = reader.ReadLine(); if (!string.IsNullOrEmpty(result)) { callback?.Invoke(result); } } } } } }
/// <summary> /// HTTP Get request for stream service. /// </summary> /// <param name="requestUri">Uri to make OAuth request.</param> /// <param name="tokens">Tokens to pass in request.</param> /// <param name="callback">Function invoked when stream available.</param> /// <returns>awaitable task</returns> public async Task ExecuteGetStreamAsync(Uri requestUri, TwitterOAuthTokens tokens, TwitterStreamCallbacks.RawJsonCallback callback) { using (var request = new HttpHelperRequest(requestUri, HttpMethod.Get)) { var requestBuilder = new TwitterOAuthRequestBuilder(requestUri, tokens); request.Headers.Authorization = HttpCredentialsHeaderValue.Parse(requestBuilder.AuthorizationHeader); using (var response = await HttpHelper.Instance.GetInputStreamAsync(request).ConfigureAwait(false)) { var responseStream = await response.GetStreamResultAsync().ConfigureAwait(false); using (var reader = new StreamReader(responseStream.AsStreamForRead())) { while (!_abort && !reader.EndOfStream) { var result = reader.ReadLine(); if (!string.IsNullOrEmpty(result)) { callback?.Invoke(result); } } } } } }