public HttpRepositoryNavigator(IHttpClient httpClient, Uri baseUri)
 {
     _httpClient       = httpClient;
     _baseUri          = baseUri;
     _requestUri       = new Uri(baseUri, new Uri("index.wraplist", UriKind.Relative));
     _httpClientGetter = (uri) => _availableCredentials != null
                                       ? _httpClient.CreateRequest(uri).Credentials(new NetworkCredential(_availableCredentials.UserName, _availableCredentials.Password))
                                       : _httpClient.CreateRequest(uri);
 }
 public HttpRepositoryNavigator(IHttpClient httpClient, Uri baseUri)
 {
     _httpClient = httpClient;
     _baseUri = baseUri;
     _requestUri = new Uri(baseUri, new Uri("index.wraplist", UriKind.Relative));
     _httpClientGetter = (uri) => _availableCredentials != null
                                       ? _httpClient.CreateRequest(uri).Credentials(new NetworkCredential(_availableCredentials.UserName, _availableCredentials.Password))
                                       : _httpClient.CreateRequest(uri);
 }
Exemple #3
0
        /// <summary>
        /// Builds the request uri based on the parameters set by the user
        /// </summary>
        /// <returns></returns>
        private IHttpRequest CreateRequest(IHttpClient client)
        {
            var retval = client.CreateRequest(this.designDocument + "/_view/" + this.indexName);

            AddOptionalRequestParam(retval, "key", this.key);
            AddOptionalRequestParam(retval, "keys", this.keys);
            AddOptionalRequestParam(retval, "startkey", this.startKey);
            AddOptionalRequestParam(retval, "endkey", this.endKey);
            AddOptionalRequestParam(retval, "startkey_docid", this.startId);
            AddOptionalRequestParam(retval, "endkey_docid", this.endId);
            AddOptionalRequestParam(retval, "skip", this.skip);
            AddOptionalRequestParam(retval, "limit", this.limit);

            AddOptionalRequestParam(retval, "inclusive_end", this.inclusive);
            AddOptionalRequestParam(retval, "descending", this.descending);
            AddOptionalRequestParam(retval, "reduce", this.reduce);
            AddOptionalRequestParam(retval, "group", this.group);
            AddOptionalRequestParam(retval, "group_level", this.groupAt);

            if (this.stale != null)
            {
                switch (this.stale.Value)
                {
                case StaleMode.AllowStale:
                    retval.AddParameter("stale", "ok");
                    break;

                case StaleMode.UpdateAfter:
                    retval.AddParameter("stale", "update_after");
                    break;

                case StaleMode.False:
                    retval.AddParameter("stale", "false");
                    break;

                default: throw new ArgumentOutOfRangeException("stale: " + this.stale);
                }
            }

            if (this.onError != null)
            {
                switch (onError.Value)
                {
                case OnErrorMode.Continue:
                    retval.AddParameter("on_error", "continue");
                    break;

                case OnErrorMode.Stop:
                    retval.AddParameter("on_error", "stop");
                    break;

                default: throw new ArgumentOutOfRangeException("on_error: " + this.onError);
                }
            }

            return(retval);
        }
Exemple #4
0
        public GatewayModule(IHttpClient httpClient, ILogger logger)
        {
            Get("/productlist", async _ =>
            {
                var request  = httpClient.CreateRequest("http://localhost:54080/products?productIds=1,2,3,4", HttpMethod.Get);
                var response = await httpClient.Client.SendAsync(request).ConfigureAwait(false);
                var content  = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
                logger.Information(content);

                return(content);
            });
        }
        public Stream LoadPackage(PackageItem packageItem)
        {
            var response = _httpClient.CreateRequest(packageItem.PackageHref).Get().Send();

            if (response.Entity == null)
            {
                return(null);
            }
            var ms = new MemoryStream();

            NuGetConverter.Convert(response.Entity.Stream, ms);
            ms.Position = 0;
            return(ms);
        }
Exemple #6
0
        public IEnumerable <CryptoCurrency> GetAllCryptoCurrencies()
        {
            var result  = new List <CryptoCurrency>();
            var fullUrl = _baseUrl + "all/coinlist";        // https://min-api.cryptocompare.com/data/all/coinlist

            var request  = _httpClient.CreateRequest(fullUrl);
            var response = _httpClient.ExecuteRequest <Dictionary <string, object> >(request);

            if (CheckAPIResponse(response))
            {
                if (response.Data.ContainsKey("Data") && response.Data["Data"] is Dictionary <string, object> )
                {
                    var baseDetailsUrl = response.Data.ContainsKey("BaseLinkUrl") ? response.Data["BaseLinkUrl"] : string.Empty;
                    var baseImgUrl     = response.Data.ContainsKey("BaseImageUrl") ? response.Data["BaseImageUrl"] : string.Empty;


                    var coins = response.Data["Data"] as Dictionary <string, object>;
                    foreach (var coin in coins)
                    {
                        if (coin.Value is Dictionary <string, object> )
                        {
                            var coinCast = coin.Value as Dictionary <string, object>;
                            result.Add(new CryptoCurrency
                            {
                                Id   = coinCast["Symbol"] as string,
                                Name = coinCast["CoinName"] as string,

                                DetailsUrl = coinCast.ContainsKey("Url") ? string.Format("{0}{1}", baseDetailsUrl, coinCast["Url"]) : string.Empty,
                                ImageUrl   = coinCast.ContainsKey("ImageUrl") ? string.Format("{0}{1}", baseImgUrl, coinCast["ImageUrl"]) : string.Empty
                            });
                        }
                    }
                }
            }

            return(result);
        }
Exemple #7
0
        Func <IPackage> LoadPackage(PackageEntry packageEntry)
        {
            return(() =>
            {
                var response = _client.CreateRequest(packageEntry.PackageHref).Get().Send();
                if (response.Entity == null)
                {
                    return null;
                }
                var tempFile = _fileSystem.CreateTempFile();
                var tempDirectory = _fileSystem.CreateTempDirectory();
                using (var tempStream = tempFile.OpenWrite())
                    NuGetConverter.Convert(response.Entity.Stream, tempStream);

                return new CachedZipPackage(this, tempFile, tempDirectory).Load();
            });
        }
Exemple #8
0
        IPackageRepository TryLocate(string uri)
        {
            var target = uri.ToUri();

            if (target == null)
            {
                return(null);
            }

            var serviceResponse = _client.CreateRequest(target).Get().Send();

            if (serviceResponse.Status.Code != 200)
            {
                return(null);
            }
            var serviceDocument = XDocument.Load(XmlReader.Create(serviceResponse.Entity.Stream, new XmlReaderSettings {
            }), LoadOptions.SetBaseUri)
            ;
            var packagesUri = (from collectionElement in serviceDocument.Descendants(XName.Get("collection", NS_ATOMPUB))
                               let collectionHref = collectionElement.Attributes("href").FirstOrDefault()
                                                    let titleElement = collectionElement.Element(XName.Get("title", NS_ATOM))
                                                                       where collectionHref != null &&
                                                                       titleElement != null &&
                                                                       titleElement.Value == "Packages"
                                                                       let baseElement = (
                                   from parent in collectionElement.AncestorsAndSelf()
                                   let xmlBase = parent.Attribute(XName.Get("base", NS_XML))
                                                 where xmlBase != null
                                                 let parsedBaseUri = xmlBase.Value.ToUri()
                                                                     select parsedBaseUri
                                   ).Reverse().Aggregate(target, UriExtensions.Combine)
                                                                                         select baseElement.Combine(collectionHref.Value.ToUri())).FirstOrDefault();

            if (packagesUri == null)
            {
                return(null);
            }
            return(new NuFeedRepository(_fileSystem, _client, target, packagesUri));
        }
Exemple #9
0
        /// <summary>
        /// Builds the request uri based on the parameters set by the user
        /// </summary>
        /// <returns></returns>
        public IHttpRequest CreateRequest(IHttpClient client, Dictionary <string, string> viewParams = null)
        {
            var retval = client.CreateRequest(this.DesignDocument + "/" + this.ViewPath + "/" + this.IndexName);

            return(retval);
        }
 public override WebRequest CreateRequest()
 {
     return(_cachedRedirectClient.CreateRequest());
 }
Exemple #11
0
 public static IClientRequest Head(this IHttpClient client, string uri)
 {
     return(client.CreateRequest(new Uri(uri, UriKind.RelativeOrAbsolute)).Head());
 }
Exemple #12
0
 public static IClientRequest Get(this IHttpClient client, Uri uri)
 {
     return(client.CreateRequest(uri).Get());
 }