Ejemplo n.º 1
0
        protected virtual HttpWebRequest CreateRequest(string url)
        {
            var request = WebRequestFactory.Create(url);

            RateLimiter.Exec(() =>
            {
                request.UserAgent = string.Format("{0}/{1} +{2}", Publication.Product, Publication.Version, Publication.HomePage);
                if (this.Key != null && this.Secret != null)
                {
                    request.Headers[HttpRequestHeader.Authorization] = string.Format("Discogs key={0}, secret={1}", this.Key, this.Secret);
                }
            });
            return(request);
        }
Ejemplo n.º 2
0
        protected virtual async Task <SearchLyricResult> Lookup(string artist, string song)
        {
            var url = this.GetUrl(artist, song);

            Logger.Write(this, LogLevel.Debug, "Querying the API: {0}", url);
            var request = WebRequestFactory.Create(url);

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    Logger.Write(this, LogLevel.Warn, "Status code does not indicate success.");
                    return(null);
                }
                using (var stream = response.GetResponseStream())
                {
                    var results = Serializer.LoadSearchLyricResults(stream).Where(
                        result => result.Valid
                        );
                    return(await this.Lookup(artist, song, results).ConfigureAwait(false));
                }
            }
        }