Пример #1
0
        /// <summary>
        /// Corresponds to the HTTP PUT method.
        /// </summary>
        /// <param name="relativePath">The path to call, relative to the base URI.</param>
        /// <param name="requestHeaders">An optional list of request headers.</param>
        /// <param name="requestParameters">The optional set of request parameters.</param>
        /// <param name="requestBody">The optional request body to send.</param>
        /// <param name="context">The optional call context to use</param>
        /// <typeparam name="T">Type of the response.</typeparam>
        /// <exception cref="CommunicationException"> when an exception occurred communicating with the Ingenico ePayments platform</exception>
        /// <exception cref="ResponseException">when an error response was received from the Ingenico ePayments platform</exception>
        /// <exception cref="ApiException">when an error response was received from the Ingenico ePayments platform which contained a list of errors</exception>
        public async Task <T> Put <T>(string relativePath, IEnumerable <IRequestHeader> requestHeaders, AbstractParamRequest requestParameters,
                                      object requestBody, CallContext context)
        {
            if (requestBody is MultipartFormDataObject)
            {
                return(await Put <T>(relativePath, requestHeaders, requestParameters, (MultipartFormDataObject)requestBody, context));
            }
            if (requestBody is IMultipartFormDataRequest)
            {
                MultipartFormDataObject multipart = ((IMultipartFormDataRequest)requestBody).ToMultipartFormDataObject();
                return(await Put <T>(relativePath, requestHeaders, requestParameters, multipart, context));
            }

            IConnection connection = Session.Connection;
            IEnumerable <RequestParam> requestParameterList = requestParameters?.ToRequestParameters();
            Uri uri = ToAbsoluteURI(relativePath, requestParameterList);

            requestHeaders = requestHeaders ?? new List <IRequestHeader>();

            string requestJson = null;
            IList <IRequestHeader> requestHeaderList = requestHeaders.ToList();

            if (requestBody != null)
            {
                requestHeaderList.Add(new EntityHeader("Content-Type", "application/json"));
                requestJson = Marshaller.Marshal(requestBody);
            }

            requestHeaders = AddGenericHeaders(HttpMethod.Put, uri, requestHeaderList, context);
            return(await connection.Put <T>(uri, requestHeaders, requestJson, (status, body, headers) => {
                return ProcessResponse <T>(status, body, headers, relativePath, context);
            }));
        }
Пример #2
0
        async Task Put(string relativePath, IEnumerable <IRequestHeader> requestHeaders, AbstractParamRequest requestParameters,
                       MultipartFormDataObject multipart, Action <Stream, IEnumerable <IResponseHeader> > bodyHandler, CallContext context)
        {
            IConnection connection = Session.Connection;
            IEnumerable <RequestParam> requestParameterList = requestParameters?.ToRequestParameters();
            Uri uri = ToAbsoluteURI(relativePath, requestParameterList);

            requestHeaders = requestHeaders ?? new List <IRequestHeader>();

            IList <IRequestHeader> requestHeaderList = requestHeaders.ToList();

            requestHeaderList.Add(new EntityHeader("Content-Type", multipart.ContentType));

            requestHeaders = AddGenericHeaders(HttpMethod.Put, uri, requestHeaderList, context);
            await connection.Put(uri, requestHeaders, multipart, (status, body, headers) => {
                return(ProcessResponse <object>(status, body, headers, relativePath, context, bodyHandler));
            });
        }