Beispiel #1
0
        public static async Task <HttpResponseMessage> PutXmlAsync <T>(
            this ICateHttp cate, string uri, T data)
        {
            var body = new XmlBody(cate.Configuration.XmlSerializer.Serialize(data));

            return(await cate.SendAsync(uri, HttpMethod.Put, MimeType.Xml, body));
        }
Beispiel #2
0
        public static async Task <HttpResponseMessage> PostJsonAsync <T>(
            this ICateHttp cate, string uri, T data)
        {
            var body = new JsonBody(cate
                                    .Configuration.JsonSerializer.Serialize(data));

            return(await cate.SendAsync(uri, HttpMethod.Post, MimeType.Json, body));
        }
Beispiel #3
0
        public static async Task <HttpResponseMessage> PostFormUrlEncodedAsync(
            this ICateHttp cate, string uri,
            IEnumerable <KeyValuePair <string, string> > data)
        {
            var body = new FormUrlEncodedContent(data);

            return(await cate.SendAsync(uri, HttpMethod.Post, MimeType.FormUrlEncoded,
                                        body));
        }
Beispiel #4
0
        public static ICateHttp AddHeader(this ICateHttp cate, string key, string value)
        {
            if (IsNullOrWhiteSpace(key))
            {
                return(cate);
            }

            cate.Client.DefaultRequestHeaders.Add(key, value);
            return(cate);
        }
Beispiel #5
0
        public static HttpResponseMessage RespondWithXml(
            this ICateHttp cate, string content)
        {
            var response = new HttpResponseMessage {
                Content = new XmlBody(content)
            };

            MockHandler(cate).FakeResponse = response;
            return(response);
        }
Beispiel #6
0
        public static ICateHttp RemoveHeaders(this ICateHttp cate, string[] keys)
        {
            if (keys == null)
            {
                return(cate);
            }

            foreach (var key in keys)
            {
                cate.Client.DefaultRequestHeaders.Remove(key);
            }

            return(cate);
        }
Beispiel #7
0
        public static ICateHttp AddHeaders(this ICateHttp cate,
                                           IDictionary <string, string> headers)
        {
            if (headers == null)
            {
                return(cate);
            }

            foreach (var header in headers)
            {
                if (IsNullOrWhiteSpace(header.Key))
                {
                    continue;
                }
                cate.Client.DefaultRequestHeaders.Add(header.Key, header.Value);
            }

            return(cate);
        }
Beispiel #8
0
 public static ICateHttp WithProxy(this ICateHttp cate, IWebProxy proxy)
 {
     cate.Configuration.Proxy = proxy;
     return(cate);
 }
Beispiel #9
0
 public static ICateHttp WithBasicAuth(this ICateHttp cate, string username,
                                       string password)
 {
     cate.Client.SetBasicAuthHeader(username, password);
     return(cate);
 }
Beispiel #10
0
 public static ICateHttp ClearHeaders(this ICateHttp cate)
 {
     cate.Client.DefaultRequestHeaders.Clear();
     return(cate);
 }
Beispiel #11
0
 public static MockMessageHandler MockHandler(ICateHttp cate)
 => cate.MessageHandler as MockMessageHandler;
Beispiel #12
0
 public static HttpResponseMessage PostFormUrlEncode(
     this ICateHttp cate, string uri,
     IEnumerable <KeyValuePair <string, string> > data)
 => cate.PostFormUrlEncodedAsync(uri, data).Result;
Beispiel #13
0
 public static HttpResponseMessage PutJson <T>(
     this ICateHttp cate, string uri, T data)
 => cate.PutJsonAsync(uri, data).Result;
Beispiel #14
0
 public static HttpResponseMessage PostXml <T>(
     this ICateHttp cate, string uri, T data)
 => cate.PostXmlAsync(uri, data).Result;
Beispiel #15
0
 public static ICateHttp WithTimeout(this ICateHttp cate, int seconds)
 {
     cate.Configuration.Timeout = TimeSpan.FromSeconds(seconds);
     return(cate);
 }
Beispiel #16
0
 public static ICateHttp WithBaseAddress(this ICateHttp cate, string uri)
 {
     cate.Configuration.BaseAddress = new Uri(uri);
     return(cate);
 }
Beispiel #17
0
 public static ICateHttp WithXmlWriterSettings(
     this ICateHttp cate, XmlWriterSettings settings)
 {
     cate.Configuration.XmlSerializer.Settings = settings;
     return(cate);
 }
Beispiel #18
0
 public static ICateHttp WithXmlSerializer <T>(this ICateHttp cate)
     where T : ISerializer, new()
 {
     cate.Configuration.XmlSerializer = new T();
     return(cate);
 }
Beispiel #19
0
 public static ICateHttp WithOAuth(this ICateHttp cate, string token)
 {
     cate.Client.SetOAuthHeader(token);
     return(cate);
 }
Beispiel #20
0
 public static HttpResponseMessage GetXml(
     this ICateHttp cate, string uri)
 => cate.GetXmlAsync(uri).Result;
Beispiel #21
0
 public static ICateHttp UsePreAuthentication(this ICateHttp cate,
                                              bool preAuthenticate)
 {
     cate.Configuration.PreAuthenticate = preAuthenticate;
     return(cate);
 }
Beispiel #22
0
 public static async Task <HttpResponseMessage> GetJsonAsync(
     this ICateHttp cate, string uri)
 => await cate.SendAsync(uri, HttpMethod.Get, MimeType.Json);
Beispiel #23
0
 public static ICateHttp WithCredentials(this ICateHttp cate, ICredentials cc)
 {
     cate.Configuration.Credentials = cc;
     return(cate);
 }
Beispiel #24
0
 public static HttpResponseMessage Delete(
     this ICateHttp cate, string uri)
 => cate.DeleteAsync(uri).Result;
Beispiel #25
0
 public static ICateHttp RemoveHeader(this ICateHttp cate, string key)
 {
     cate.Client.DefaultRequestHeaders.Remove(key);
     return(cate);
 }