Exemple #1
0
 public IRestResponse ExecuteAsPost(IRestRequest request, string httpMethod)
 {
     InjectZipkinTraces(request);
     using (GetClientSendTrace(request))
     {
         return(_innerClient.ExecuteAsPost(request, httpMethod));
     }
 }
Exemple #2
0
        public IRestResponse ExecuteAsPost(IRestRequest request, string httpMethod)
        {
            var response = _restClient.ExecuteAsPost(request, httpMethod);

            _logger.LogTrace($"Request: {request.Method} {request.Resource} {request.Body?.Value}. " +
                             $"Response: {response.StatusCode} {response.Content}.".Truncate(500));
            return(response);
        }
 public IRestResponse ExecuteAsPost(IRestRequest request, string httpMethod)
 {
     if (null == request)
     {
         return(null);
     }
     if (null == _pollyRetPolicy)
     {
         return(null);
     }
     return(_pollyRetPolicy.Execute(() => _innerService.ExecuteAsPost(request, httpMethod)));
 }
Exemple #4
0
 public IRestResponse ExecuteAsPost(IRestRequest request, string httpMethod)
 {
     if (null == _pollyRetPolicy)
     {
         throw new AggregateException(nameof(_pollyRetPolicy) + " is  null");
     }
     return(_pollyRetPolicy.Execute(() =>
     {
         if (null == request)
         {
             throw new AggregateException(nameof(request) + " is  null");
         }
         return _innerService.ExecuteAsPost(request, httpMethod);
     }));
 }
Exemple #5
0
        public RestsharpServiceTest()
        {
            fixture = new Fixture();
            token   = fixture.Create <string>();
            pessoas = fixture.CreateMany <Pessoa>().ToList();
            pessoa  = fixture.Create <Pessoa>();

            responsePessoas = new RestResponse <List <Pessoa> >
            {
                Data = pessoas
            };

            responsePessoa = new RestResponse <Pessoa>
            {
                Data = pessoa
            };

            restClient = Substitute.For <IRestClient>();
            restClient.ExecuteAsGet <List <Pessoa> >(Arg.Any <RestRequest>(), Arg.Any <string>()).Returns(responsePessoas);
            restClient.ExecuteAsGet <Pessoa>(Arg.Any <RestRequest>(), Arg.Any <string>()).Returns(responsePessoa);
            restClient.ExecuteGetAsync <List <Pessoa> >(Arg.Any <RestRequest>()).Returns(responsePessoas);
            restClient.ExecuteAsPost <Pessoa>(Arg.Any <RestRequest>(), Arg.Any <string>()).Returns(responsePessoa);

            service = new RestsharpService(restClient, token);
        }
Exemple #6
0
        public Pessoa Post(Pessoa pessoa)
        {
            var request = new RestRequest("pessoa").AddJsonBody(pessoa);

            var response = restClient.ExecuteAsPost <Pessoa>(request, "POST");

            return(response.Data);
        }
Exemple #7
0
        public T Execute <T>(RestRequest request) where T : new()
        {
            IRestResponse <T> response;

            // Explicitly check whether to execute as GET- or POST-like request
            // RestSharp treats DELETE by default as a GET-like request, however we
            // need it as a POST-like request
            var method = Enum.GetName(typeof(Method), request.Method);

            switch (request.Method)
            {
            case Method.POST:
            case Method.PUT:
            case Method.PATCH:
            case Method.DELETE:
                response = _client.ExecuteAsPost <T>(request, method);
                break;

            default:
                response = _client.ExecuteAsGet <T>(request, method);
                break;
            }

            if (response.ResponseStatus != ResponseStatus.Completed)
            {
                string message = String.Format("Error retrieving response: {0}. {1}",
                                               response.ResponseStatus.ToString(), response.ErrorMessage);
                throw new RequestFailedException(message, "RequestFailed", response.ErrorException);
            }
            // if we identify with a cookie, update the sessionId
            if (_authMethod == DataspaceRequest.AuthMethod.Cookie)
            {
                foreach (var cookie in response.Cookies)
                {
                    if (cookie.Name == DataspaceRequest.SessionIdCookieName)
                    {
                        _sessionId = cookie.Value;
                        break;
                    }
                }
            }
            return(response.Data);
        }
Exemple #8
0
 public IRestResponse ExecuteAsPost(IRestRequest request, string httpMethod)
 {
     return(_innerClient.ExecuteAsPost(request, httpMethod));
 }