Exemplo n.º 1
0
        private Uri GetUri(long?id = null, string action = null, UrlParams parameters = null)
        {
            var uriBuilder = new UriBuilder(ApiUrl)
            {
                Path = Path.Combine(
                    ApiVersion ?? string.Empty,
                    EntityName ?? string.Empty,
                    action ?? string.Empty,
                    id?.ToString() ?? string.Empty),
                Query = parameters?.ToString() ?? string.Empty,
            };

            return(uriBuilder.Uri);
        }
Exemplo n.º 2
0
        private TResponse BaseMakeRequest <TDto, TResponse>(HttpMethod method, string action = null, long?id = null, UrlParams parameters = null, TDto dto = default)
        {
            var requestUri    = GetUri(id, action, parameters);
            var responseBytes = SendRequest(requestUri, method, dto);

            try
            {
                return(DeserializeResponse <TResponse>(responseBytes));
            }
            catch (WebException ex) when(ex.Status == WebExceptionStatus.ProtocolError)
            {
                // If Bad Request returns JSON with the error message
                throw new InvalidOperationException(DeserializeResponse <dynamic>(responseBytes), ex);
            }
        }
Exemplo n.º 3
0
 public TResponse MakeRequest <TResponse>(HttpMethod method, string action, UrlParams parameters) =>
 BaseMakeRequest <object, TResponse>(method, action, id: null, parameters: parameters);