Beispiel #1
0
    public async Task <string> GetUsername(string token, string userId)
    {
        var uri = $"https://slack.com/api/users.list?token={token}";

        try
        {
            var result = await http.Get(uri);

            return(JSON.Deserialize <SlackUserList>(result.Body).Members.First(member => member.Id == userId).Name);
        }
        catch (System.Exception)
        {
            return(string.Empty);
        }
    }
Beispiel #2
0
        private void CrawlInternal(Uri domainUri, Node node)
        {
            // Gets the response and saves the visisted Uri.
            var response = _http.Get(node.Uri);

            SaveVisited(node.Uri);
            SaveVisited(response.RequestUri);
            if (!response.IsSuccess)
            {
                return;
            }

            // Gets the nodes out of the reponse HTML.
            var html = response.Content;

            node.Nodes = _nodeFactory.Create(domainUri, html);

            // Iterates through the children nodes recursively
            // only if the node is internal and it has not been visited yet.
            foreach (var child in node.Nodes)
            {
                if (child.IsInternal && !IsVisited(child))
                {
                    CrawlInternal(domainUri, child);
                }
            }
        }
Beispiel #3
0
        public async Task <IEnumerable <WeatherForecast> > GetForecastFor(string location)
        {
            var metaWeatherLocation = (await http
                                       .Get <MetaWeatherLocation[]>(url: $"https://www.metaweather.com/api/location/search/?query={location}"))
                                      .First();

            return((await http.Get <MetaWeatherForecast>(url: $"https://www.metaweather.com/api/location/{metaWeatherLocation.woeid}/"))
                   .consolidated_weather
                   .Select(forecast => new WeatherForecast
            {
                Date = DateTime.Parse(forecast.applicable_date),
                Summary = forecast.weather_state_name,
                TemperatureC = (int)forecast.the_temp
            })
                   .ToList());
        }
Beispiel #4
0
        public List <PlanModel> GetPlans(APIRequest apiRequest)
        {
            apiRequest.RouteName = "import/plans";
            _ihttp.ApiRequest    = apiRequest;
            var response = _ihttp.Get <PlanResponseDataModel>();

            return(response.Plans);
        }
Beispiel #5
0
        public List <CustomerModel> GetCustomers(APIRequest apiRequest)
        {
            apiRequest.RouteName = "import/customers";
            _iHttp.ApiRequest    = apiRequest;
            var response = _iHttp.Get <CustomerResponseDataModel>();

            return(response.Customers);
        }
 public string GetConversionRate()
 {
     try {
         return(_http.Get("http://www.openexchangerates.com/?currencies=" + this.CurrentUnit + "&value=" + this.TargetUnit));
     }
     catch (System.Net.WebException ex) {
         return(ex.Message);
     }
 }
    public double ConvertTo(double Value, string CurrentCurrency, string TargetCurrency)
    {
        var key  = CurrentCurrency + "-" + TargetCurrency;
        var rate = _cache.Get(key);

        if (rate != null)
        {
            _logger.Write("Se encontro la tasa en el cache" + rate);
            return(Value * double.Parse(rate));
        }
        else
        {
            _logger.Write("No se encontro la tasa en el cache entonces la voy a buscar en internet");
            var rateFromInternet = _http.Get("http://www.openexchangerates.com/?currencies=" + key + "&value=" + Value);
            _cache.Set(key, rateFromInternet);
            return(Value * double.Parse(rateFromInternet));
        }
    }
        private ExternalContent Get(string url)
        {
            HttpResponse httpResponse = null;
            WebException exception    = null;

            RetryPolicy.Retry(
                () =>
            {
                try
                {
                    httpResponse = http.Get(url);
                }
                catch (WebException e)
                {
                    exception = e;
                }
            },
                () =>
            {
                if (httpResponse != null)
                {
                    return(true);
                }

                HttpWebResponse response = exception.Response as HttpWebResponse;

                return((response != null) && (response.StatusCode >= HttpStatusCode.OK && response.StatusCode < HttpStatusCode.Ambiguous));
            },
                3,
                TimeSpan.FromSeconds(1));

            if (exception != null)
            {
                throw exception;
            }

            Match match = htmlTitleExpression.Match(httpResponse.Content);

            string title = !string.IsNullOrWhiteSpace(match.Value) ? match.Value.Trim() : TextMessages.CouldNotRetrieveTheTitle;

            return(new ExternalContent(title, httpResponse.Content));
        }
Beispiel #9
0
        public async Task <Response <Cart> > GetCart(string cartId)
        {
            var address = $"{domain}/api/v1/carts/{cartId}";

            return(await http.Get <Cart>(address));
        }
Beispiel #10
0
 /// <summary>
 /// Calls a Slack API method.
 /// </summary>
 /// <typeparam name="T">Type of response expected.</typeparam>
 /// <param name="apiMethod">Name of Slack method.</param>
 /// <param name="args">Arguments to send to Slack. The "token" parameter will be filled in automatically.</param>
 /// <param name="cancellationToken"></param>
 public async Task <T> Get <T>(string apiMethod, Args args, CancellationToken?cancellationToken) where T : class =>
 Deserialize <T>(await _http.Get <WebApiResponse>(Url(apiMethod, args), cancellationToken ?? CancellationToken.None).ConfigureAwait(false));
Beispiel #11
0
        public static HttpResponse Get(this IHttp instance, string url)
        {
            Check.Argument.IsNotNull(instance, "instance");

            return(instance.Get(url, Http.DefaultUserAgent, Http.DefaultTimeout, Http.DefaultRequestCompressed, Http.DefaultMaximumRedirects, null, null, null, null, null));
        }
 public HttpResponse Get()
 {
     return(_rawHttp.Get());
 }
Beispiel #13
0
        public Task <R <List <LicencePlateResponse> > > Get(string token) =>
        http.Get <List <LicencePlateResponse> >(
            uri: $"{endpoint}/api/v1/LicencePlate/",
            settings: HttpSettingsExtension.Create(token)

            );