Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);
        }