Beispiel #1
0
        public IRestResponse Execute(string baseUrl, string resource, Method method)
        {
            var _client = _restClientFactory.Create(baseUrl);
            var request = _restRequestFactory.Create(resource, method);

            return(_client.Execute(request));
        }
        public async Task <IEnumerable <LaunchpadViewModel> > GetAllAsync()
        {
            var client  = _restClientFactory.Create(_baseUrl);
            var request = _restRequestFactory.Create($"launchpads?filter={SPACEX_API_LAUNCHPAD_FIELD_FILTER}", Method.GET);

            var response = await GetRequestAsync(client, request);

            var json = ValidateResponse(response);

            return(_deserializer.DeserializeLaunchpadCollectionResponse(json));
        }
        /// <summary>
        /// Get time zone info
        /// </summary>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <returns></returns>
        public async Task <IRestResponse <TimeZoneModel> > GetTimeZone(double latitude, double longitude)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("location", latitude + "," + longitude);
            dict.Add("timestamp", DateTime.Now.ToString("yyyyMMdd"));
            dict.Add("key", API);
            var request    = _restRequestFactory.Create("timezone/json", Method.GET, dict);
            var restClient = _restClientFactory.Create(restClientStr);

            return(await restClient.ExecuteGetTaskAsync <TimeZoneModel>(request));
        }
        private void SendGetPosts()
        {
            var restClient  = _restClientFactory.Create(_baseEndpoint);
            var restRequest = _restRequestFactory.Create(string.Format("{0}posts?userId={1}", _baseEndpoint, _id), Method.GET);

            restRequest.AddHeader("Content-Type", "application/json; charset=utf-8");

            var response = restClient.Execute(restRequest);

            _responseCode = response.StatusCode;
            _allPosts     = JsonConvert.DeserializeObject <List <PostModel> >(response.Content);
        }
Beispiel #5
0
        public int Add(int a, int b)
        {
            var restClient  = _restClientFactory.Create(_baseUrl);
            var restRequest = _restRequestFactory.Create($"api/math/add?a={a}&b={b}", Method.GET);
            var sum         = restClient.Get(restRequest).Content;

            using (IDbConnection db = new SqlConnection("Server=DESKTOP-EC5FMB7\\SQLEXPRESS;Database=DapperTest;Trusted_Connection=True;MultipleActiveResultSets=true;"))
            {
                var query        = $"INSERT INTO ImportantObject VALUES(1,{sum})";
                int rowsAffected = db.Execute(query);
            }
            //log the request

            return(Convert.ToInt32(sum));
        }
        public IRestResponse GetResponse(string endpoint, string Uri, Method method)
        {
            var restClient  = restClientFactory.Create(endpoint);
            var restRequest = restRequestFactory.Create(Uri, method);
            var response    = restClient.Execute(restRequest);

            return(response);
        }
        public IRestRequest RegisterUserRequest(Method method)
        {
            var restRequest = restRequestFactory.Create("oauth/account/register", method);

            restRequest.AddHeader("Content-Type", "application/json");
            restRequest.AddHeader("Authorization", "Basic " + ConfigurationHelper.GetAppSetting("authorization"));

            return(restRequest);
        }
        /// <summary>
        /// Get weather data by zipcode
        /// </summary>
        /// <param name="zipCode"></param>
        /// <returns>WeatherModel</returns>
        public async Task <IRestResponse <WeatherModel> > GetWeatherByZIPCode(string zipCode)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("zip", zipCode);
            dict.Add("APPID", API);
            dict.Add("units", "imperial");
            var request    = _restRequestFactory.Create("weather", Method.GET, dict);
            var restClient = _restClientFactory.Create(restClientStr);

            return(await restClient.ExecuteGetTaskAsync <WeatherModel>(request));
        }
Beispiel #9
0
        public IRestClientProxy Setup(Action <IRestRequest> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            _request = _restRequestFactory.Create();

            action(_request);

            return(this);
        }