Ejemplo n.º 1
0
        public BBoxClient(BBoxClientConfiguration bboxClientConfiguration, ILogger <BBoxClient> logger)
        {
            _bboxClientConfiguration = bboxClientConfiguration;
            _logger      = logger;
            _flurlClient = new FlurlClient(_bboxClientConfiguration.Uri);

            Uri  = _bboxClientConfiguration.Uri;
            User = _bboxClientConfiguration.User;
        }
Ejemplo n.º 2
0
 public IPBApiClient(IPBModuleConfig config, string?token, string?apiKey, ILogger <IPBApiClient> logger,
                     IHttpClientFactory httpClientFactory)
 {
     _config      = config;
     _token       = token;
     _apiKey      = apiKey;
     _logger      = logger;
     _flurlClient = new FlurlClient(httpClientFactory.CreateClient());
 }
Ejemplo n.º 3
0
        private DeveloperGame(FlurlClient client, string xsrfToken, string name, string navigationId, string gameId)
        {
            _client = client;

            this.XSRFToken    = xsrfToken;
            this.Name         = name;
            this.NavigationId = navigationId;
            this.GameId       = gameId;
        }
Ejemplo n.º 4
0
 /// <summary>
 ///     Disconnect the client from AA. Will force logon on the next request if required.
 /// </summary>
 public void Disconnect(bool resetAuth = false)
 {
     _client?.Dispose();
     _client = null;
     if (resetAuth)
     {
         _settings.TokenResponse = null;
     }
 }
Ejemplo n.º 5
0
        public async Task can_set_request_cookies()
        {
            var cli  = new FlurlClient();
            var resp = await cli.Request("https://httpbin.org/cookies").WithCookies(new { x = 1, y = 2 }).GetJsonAsync();

            // httpbin returns json representation of cookies that were set on the server.
            Assert.AreEqual("1", resp.cookies.x);
            Assert.AreEqual("2", resp.cookies.y);
        }
        public async Task <IList <Forecast> > GetForecasts()
        {
            var forecastHttpClient = new FlurlClient(ForecastHttpClient);

            return(await forecastHttpClient
                   .Request()
                   .GetJsonAsync <IList <Forecast> >()
                   .ConfigureAwait(false));
        }
 public AdminIssuesPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator)
 {
     _eventAggregator   = eventAggregator;
     FlurlClient        = new FlurlClient(ServerPath.Path);
     _navigationService = navigationService;
     GetIssues().ConfigureAwait(true);
     //Events
     _eventAggregator.GetEvent <DeleteIssueEvent>().Subscribe(DeleteIssue);
 }
Ejemplo n.º 8
0
        private static void CreateClient()
        {
            _client = new FlurlClient(ApiUrlConfig.BaseUrl);

            if (TimeoutSeconds.HasValue)
            {
                _client.WithTimeout(TimeoutSeconds.Value);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a new TraditionalClient.
        /// </summary>
        /// <remarks>
        /// Takes an optional CultureInfo which is useful for formatting numbers. If not specified,
        /// the user's current culture is used.
        /// </remarks>
        /// <param name="cultureInfo"></param>
        public TraditionalClient(string hostname, ApiVersion version = ApiVersion.V2, CultureInfo cultureInfo = null)
        {
            var culture = cultureInfo ?? CultureInfo.CurrentCulture;

            FlurlHttp.Configure(settings => settings.OnErrorAsync = HandleFlurlErrorAsync);
            FlurlHttp.Configure(settings => settings.OnError      = HandleFlurlError);

            client = new FlurlClient($"https://{hostname}"
                                     .AppendPathSegments("api", version));
        }
Ejemplo n.º 10
0
        public SerialThread(string databaseHost, string webServerHost)
        {
            serialPort.BaudRate     = 115200;
            serialPort.ReadTimeout  = 1500;
            serialPort.WriteTimeout = 1500;

            client      = new MongoClient($"mongodb://{databaseHost}:27017/?connect=direct;replicaSet=rs0;readPreference=primaryPreferred");
            flurlClient = new FlurlClient($"http://{webServerHost}:3001");
            database    = client.GetDatabase("beademing");
        }
Ejemplo n.º 11
0
        static async Task <String> Postmethod(FlurlClient client)
        {
            var values = new Dictionary <string, string>
            {
                //any values/anything will work,but will keep it empty for checking result with seversite
            };
            var posting = await client.Request("/post").PostUrlEncodedAsync(values).Result.Content.ReadAsStringAsync();

            return(posting);
        }
Ejemplo n.º 12
0
        public void BeforeScenario()
        {
            HttpClientHandler httpClientHandler = new HttpClientHandler();

            httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true;
            HttpClient httpClient = new HttpClient(httpClientHandler);

            httpClient.BaseAddress = new Uri("http://localhost:5000/vehicle-checks/makes/");
            _flurlClient           = new FlurlClient(httpClient);
        }
Ejemplo n.º 13
0
        private static async Task <List <Person> > ReadPostResponseAsync(FlurlClient countryCodeClient, List <Person> peopleRequest)
        {
            var response = await countryCodeClient.Request().PostJsonAsync(peopleRequest);

            var json = await response.Content.ReadAsStringAsync();

            var people = JsonConvert.DeserializeObject <List <Person> >(json);

            return(people);
        }
Ejemplo n.º 14
0
        public async Task can_get_response_cookies_with_a_delegating_handler()
        {
            var cli = new FlurlClient("https://httpbin.org")
                      .Configure(settings => settings.HttpClientFactory = new DelegatingHandlerHttpClientFactory())
                      .EnableCookies();

            await cli.Request("cookies/set?z=999").HeadAsync();

            Assert.AreEqual("999", cli.Cookies["z"].Value);
        }
Ejemplo n.º 15
0
        [Test]         // #334
        public void can_dispose_FlurlClient_created_with_HttpClient()
        {
            var hc = new HttpClient();
            var fc = new FlurlClient(hc);

            fc.Dispose();

            // ensure the HttpClient got disposed
            Assert.ThrowsAsync <ObjectDisposedException>(() => hc.GetAsync("http://mysite.com"));
        }
Ejemplo n.º 16
0
    /// <summary>
    /// Sends an asynchronous POST request of specified data (usually an anonymous object or dictionary) formatted as XML.
    /// </summary>
    /// <param name="client">The FlurlClient</param>
    /// <param name="serializedXml">Data to be serialized and posted.</param>
    /// <returns>A Task whose result is the received HttpResponseMessage.</returns>
    public static Task <HttpResponseMessage> PostXmlAsync(this FlurlClient client, string serializedXml)
    {
        var request = new HttpRequestMessage(HttpMethod.Post, client.Url.ToString())
        {
            Content = new CapturedStringContent(serializedXml, Encoding.UTF8, "text/xml"),
            Method  = HttpMethod.Post
        };

        return(client.HttpClient.SendAsync(request));
    }
Ejemplo n.º 17
0
        public static void Initialize(TestContext testContext)
        {
            //Load all the assemblies in to the app domain so this loading doesn't skew results
            var flurlClient       = new FlurlClient(PeopleUrl);
            var countryCodeClient = new Client(new NewtonsoftSerializationAdapter(), new Uri(PeopleUrl));
            var restSharpClient   = new RestSharp.RestClient(PeopleUrl);
            var dalSoftClient     = new DalSoft.RestClient.RestClient(PeopleUrl);
            var personJson        = JsonConvert.SerializeObject(new Person());

            personJson = System.Text.Json.JsonSerializer.Serialize(new Person());
        }
        public ClientProvidersPageViewModel(INavigationService navigationService)
        {
            ClientModule.UserId      = Settings.UserId;
            ClientModule.AccessToken = Settings.AccessToken;
            FlurlClient        = new FlurlClient(ServerPath.Path);
            _navigationService = navigationService;
            AddProviderCommand = new DelegateCommand(AddProvicer);
            SearchCommand      = new DelegateCommand(Search);

            GetProviders().ConfigureAwait(true);
        }
Ejemplo n.º 19
0
        [Test]         // #335
        public async Task doesnt_record_calls_made_with_HttpClient()
        {
            using (var httpTest = new HttpTest()) {
                httpTest.RespondWith("Hello");
                var flurClient = new FlurlClient();
                // use the underlying HttpClient directly
                await flurClient.HttpClient.GetStringAsync("https://www.google.com/");

                CollectionAssert.IsEmpty(httpTest.CallLog);
            }
        }
Ejemplo n.º 20
0
        public static async Task <T> GetODataValueAsync <T>(this FlurlClient client)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            var odataResult = await client.GetJsonAsync <ODataClientResult <T> >().ConfigureAwait(false);

            return(odataResult.Value);
        }
Ejemplo n.º 21
0
        public async Task autodispose_true_creates_new_httpclients()
        {
            var fc = new FlurlClient("http://www.mysite.com", true);
            var x  = await fc.GetAsync();

            var y = await fc.GetAsync();

            var z = await fc.GetAsync();

            Assert.AreEqual(3, _fac.NewClientCount);
        }
Ejemplo n.º 22
0
 public void can_override_settings_fluently()
 {
     using (var test = new HttpTest()) {
         var cli = new FlurlClient().Configure(s => s.AllowedHttpStatusRange = "*");
         test.RespondWith("epic fail", 500);
         Assert.ThrowsAsync <FlurlHttpException>(async() => await "http://www.api.com"
                                                 .ConfigureRequest(c => c.AllowedHttpStatusRange = "2xx")
                                                 .WithClient(cli) // client-level settings shouldn't win
                                                 .GetAsync());
     }
 }
Ejemplo n.º 23
0
        public async Task autodispose_false_resues_httpclient()
        {
            var fc = new FlurlClient("http://www.mysite.com", false);
            var x  = await fc.GetAsync();

            var y = await fc.GetAsync();

            var z = await fc.GetAsync();

            Assert.AreEqual(1, _fac.NewClientCount);
        }
 public RestClient(string clientId, string clientSecret, string server)
 {
     this.clientId     = clientId;
     this.clientSecret = clientSecret;
     this.server       = server;
     flurlClient       = new FlurlClient(server);
     flurlClient.Configure(c =>
     {
         c.AfterCall = AfterCall;
     });
 }
Ejemplo n.º 25
0
        public void settings_propagate_correctly()
        {
            FlurlHttp.GlobalSettings.Redirects.Enabled          = false;
            FlurlHttp.GlobalSettings.AllowedHttpStatusRange     = "4xx";
            FlurlHttp.GlobalSettings.Redirects.MaxAutoRedirects = 123;

            var client1 = new FlurlClient();

            client1.Settings.Redirects.Enabled = true;
            Assert.AreEqual("4xx", client1.Settings.AllowedHttpStatusRange);
            Assert.AreEqual(123, client1.Settings.Redirects.MaxAutoRedirects);
            client1.Settings.AllowedHttpStatusRange     = "5xx";
            client1.Settings.Redirects.MaxAutoRedirects = 456;

            var req = client1.Request("http://myapi.com");

            Assert.IsTrue(req.Settings.Redirects.Enabled, "request should inherit client settings when not set at request level");
            Assert.AreEqual("5xx", req.Settings.AllowedHttpStatusRange, "request should inherit client settings when not set at request level");
            Assert.AreEqual(456, req.Settings.Redirects.MaxAutoRedirects, "request should inherit client settings when not set at request level");

            var client2 = new FlurlClient();

            client2.Settings.Redirects.Enabled = false;

            req.WithClient(client2);
            Assert.IsFalse(req.Settings.Redirects.Enabled, "request should inherit client settings when not set at request level");
            Assert.AreEqual("4xx", req.Settings.AllowedHttpStatusRange, "request should inherit global settings when not set at request or client level");
            Assert.AreEqual(123, req.Settings.Redirects.MaxAutoRedirects, "request should inherit global settings when not set at request or client level");

            client2.Settings.Redirects.Enabled          = true;
            client2.Settings.AllowedHttpStatusRange     = "3xx";
            client2.Settings.Redirects.MaxAutoRedirects = 789;
            Assert.IsTrue(req.Settings.Redirects.Enabled, "request should inherit client settings when not set at request level");
            Assert.AreEqual("3xx", req.Settings.AllowedHttpStatusRange, "request should inherit client settings when not set at request level");
            Assert.AreEqual(789, req.Settings.Redirects.MaxAutoRedirects, "request should inherit client settings when not set at request level");

            req.Settings.Redirects.Enabled          = false;
            req.Settings.AllowedHttpStatusRange     = "6xx";
            req.Settings.Redirects.MaxAutoRedirects = 2;
            Assert.IsFalse(req.Settings.Redirects.Enabled, "request-level settings should override any defaults");
            Assert.AreEqual("6xx", req.Settings.AllowedHttpStatusRange, "request-level settings should override any defaults");
            Assert.AreEqual(2, req.Settings.Redirects.MaxAutoRedirects, "request-level settings should override any defaults");

            req.Settings.ResetDefaults();
            Assert.IsTrue(req.Settings.Redirects.Enabled, "request should inherit client settings when cleared at request level");
            Assert.AreEqual("3xx", req.Settings.AllowedHttpStatusRange, "request should inherit client settings when cleared request level");
            Assert.AreEqual(789, req.Settings.Redirects.MaxAutoRedirects, "request should inherit client settings when cleared request level");

            client2.Settings.ResetDefaults();
            Assert.IsFalse(req.Settings.Redirects.Enabled, "request should inherit global settings when cleared at request and client level");
            Assert.AreEqual("4xx", req.Settings.AllowedHttpStatusRange, "request should inherit global settings when cleared at request and client level");
            Assert.AreEqual(123, req.Settings.Redirects.MaxAutoRedirects, "request should inherit global settings when cleared at request and client level");
        }
Ejemplo n.º 26
0
        private static IFlurlRequest Target(string arg)
        {
            var certificate = new X509Certificate2();

            var client = new FlurlClient("https://api.dataservices-qa.doverfs.com:8863/device")
                         .Configure(c => c.HttpClientFactory =
                                        certificate != null
                        ? new X509ClientFactory(certificate, Log.Logger)
                        : null);

            return(client.Request("register", "Terminal", deviceId));
        }
Ejemplo n.º 27
0
        public FortniteClient(string apiKey)
        {
            _client = new FlurlClient
            {
                BaseUrl = "https://api.fortnitetracker.com/v1"
            };
            _client.WithHeader("TRN-Api-Key", apiKey);

            _queue = new Semaphore(1, 1);
            _rateLimitRemaining      = RateLimitAmount;
            _rateLimitResetRemaining = DateTimeOffset.UtcNow + RateLimitDuration;
        }
Ejemplo n.º 28
0
        public void can_create_FlurlClient_with_existing_HttpClient()
        {
            var hc = new HttpClient {
                BaseAddress = new Uri("http://api.com/"),
                Timeout     = TimeSpan.FromSeconds(123)
            };
            var cli = new FlurlClient(hc);

            Assert.AreEqual("http://api.com/", cli.HttpClient.BaseAddress.ToString());
            Assert.AreEqual(123, cli.HttpClient.Timeout.TotalSeconds);
            Assert.AreEqual("http://api.com/", cli.BaseUrl);
        }
Ejemplo n.º 29
0
 public NasaApiProxy(IHttpClientFactory httpClientFactory, IOptions <NasaApiSettings> options)
 {
     _settings = options.Value;
     _client   = new FlurlClient
     {
         Settings =
         {
             HttpClientFactory = httpClientFactory
         }
     }
     .WithTimeout(TimeSpan.FromSeconds(30));
 }
Ejemplo n.º 30
0
 public FlightClient(string flightServiceUrl, IHttpClientFactory clientFactory, IAsyncPolicy asyncPolicy)
 {
     _flightServiceUrl = flightServiceUrl;
     _asyncPolicy      = asyncPolicy;
     _client           = new FlurlClient
     {
         Settings =
         {
             HttpClientFactory = clientFactory
         }
     };
 }