/// <summary> /// Initializes a new instance of the <see cref="RequestObserver"/> class. /// </summary> /// <param name="client">The client.</param> /// <param name="options">The options.</param> public RequestObserver(Client client, RequestOptions options) { _cache = client.Cache; _cachedResults = new Subject <Result>(); _downloadedResults = new Subject <Result>(); _downloadRequired = new Subject <UrlRequest>(); var downloader = new DownloadObserver(client.Cache, client.RequestTimeout, _downloadedResults); _downloadRequired .Buffer(client.BufferTimeout, 20) .Where(reqs => reqs.Count > 0) .Select(reqs => new EmbedlyRequest( new Uri(@"http://api.embed.ly/1/oembed?format=json&key=" + client.Key + @"&urls=" + string.Join(",", reqs.Select(req => Uri.EscapeDataString(req.Url.OriginalString))) + options.GetQueryString()), reqs ) ) .Subscribe(downloader); Output = _cachedResults.Merge(_downloadedResults); }