Exemple #1
0
        private IConsumerResponse CallApi(string method, string body, Uri baseUrl, string endpointName, string itemId, DateTime?lastModifiedDate, NameValueCollection additionalQueryParams, string acceptMimeType)
        {
            method = string.IsNullOrEmpty(method) ? "GET" : method.ToUpper();

            NameValueCollection allQueryParams = additionalQueryParams ?? new NameValueCollection();

            Uri uri = ConstructUri(baseUrl, endpointName, itemId, allQueryParams);

            IConsumerRequest request = _oauthSession.Request()
                                       .ForMethod(method)
                                       .ForUri(uri)
                                       .WithAcceptHeader(acceptMimeType ?? "text/xml")
                                       .WithIfModifiedSince(lastModifiedDate)
                                       .SignWithToken();

            if ((method == "PUT" || method == "POST"))
            {
                request = request.WithBody(body);
            }

            IConsumerResponse consumerResponse = request.ToConsumerResponse();

            // Check for <ApiException> response message
            if (consumerResponse.Content.StartsWith("<ApiException"))
            {
                ApiExceptionDetails details = ModelSerializer.DeserializeTo <ApiExceptionDetails>(consumerResponse.Content);
                throw new ApiException(details);
            }

            return(consumerResponse);
        }