/// <summary/> public static Task <IChatApiResponse <TInterface?> > GetAsync <TInterface>(this IConnect connect, string operationName, Func <string, TInterface> deserialization, IResponseSettings?responseSettings = null, string?parameters = null) { string link = connect.CreateLink(operationName, responseSettings, parameters); Task <IChatApiResponse <TInterface?> > whatsAppResponseAsync = ChatApiResponse <TInterface?> .CreateInstanceAsync(() => { using var client = new WebClient().CreateHeaders(); Task <string> response = client.DownloadStringTaskAsync(link); return(response); }, deserialization); return(whatsAppResponseAsync); }
/// <summary/> public static Task <IChatApiResponse <TInterface?> > PostAsync <TInterface>(this IConnect connect, string operationName, Func <string, TInterface> deserialization, string?json = null, IResponseSettings?responseSettings = null) { string link = connect.CreateLink(operationName, responseSettings); Task <IChatApiResponse <TInterface?> > whatsAppResponseAsync = ChatApiResponse <TInterface?> .CreateInstanceAsync(() => { using var client = new WebClient().CreateHeaders(); Task <string> continueWith = client.UploadStringTaskAsync(link, "POST", json ?? string.Empty); return(continueWith); }, deserialization); return(whatsAppResponseAsync); }
/// <summary/> public static IChatApiResponse <TClass?> Get <TClass>(this IConnect connect, string operationName, Func <string, TClass> deserialization, IResponseSettings?responseSettings = null, string?parameters = null) where TClass : class, IErrorResponse, new() { string link = connect.CreateLink(operationName, responseSettings, parameters); IChatApiResponse <TClass?> chatApiResponse = ChatApiResponse <TClass?> .CreateInstance(() => { using var client = new WebClient().CreateHeaders(); string response = client.DownloadString(link); return(deserialization(response)); }); return(chatApiResponse); }
/// <summary/> public static IChatApiResponse <TClass?> Post <TClass>(this IConnect connect, string operationName, Func <string, TClass> deserialization, string?json = null, IResponseSettings?responseSettings = null) where TClass : class, IErrorResponse, new() { string link = connect.CreateLink(operationName, responseSettings); IChatApiResponse <TClass?> chatApiResponse = ChatApiResponse <TClass?> .CreateInstance(() => { using var client = new WebClient().CreateHeaders(); string response = client .UploadString(link, "POST", json ?? string.Empty); return(deserialization(response)); }); return(chatApiResponse); }