Пример #1
0
        private async Task <string> GetJsonAsync(MCParameters mcParameters)
        {
            var Client = new HttpClient
            {
                BaseAddress = new Uri(defaultMCEndpointUrl)
            };

            var formContent = new FormUrlEncodedContent(mcParameters.ToList());

            using var responseMessage = await Client.PostAsync(defaultMCRequestUri, formContent);

            using var content = responseMessage.Content;
            return(await content.ReadAsStringAsync());
        }
Пример #2
0
        public MCClient(MCParameters parameters, string mcEndpointUrl = "https://api.meaningcloud.com", string mcRequstUri = "/summarization-1.0")
        {
            if (parameters == null)
            {
                throw new InvalidOperationException("MCParameters cannot be null.");
            }

            if (string.IsNullOrWhiteSpace(mcEndpointUrl))
            {
                throw new InvalidOperationException("The MeaningCloud endpoint URL cannot be null or empty. Example: \"https://api.meaningcloud.com\"");
            }

            if (string.IsNullOrWhiteSpace(mcRequstUri))
            {
                throw new InvalidOperationException("The mcRequstUri cannot be null or empty. Example: \"/summarization-1.0\"");
            }

            if (string.IsNullOrWhiteSpace(parameters.Key))
            {
                throw new InvalidOperationException("The API Key cannot be null or empty.");
            }

            if (string.IsNullOrWhiteSpace(parameters.Sentences))
            {
                throw new InvalidOperationException("The number of sentences to return cannot be null or empty.");
            }

            if (!string.IsNullOrWhiteSpace(parameters.Url) && !string.IsNullOrWhiteSpace(parameters.Txt))
            {
                throw new InvalidOperationException("Either \"Url\" or \"Txt\" must be part of your request but not both.");
            }

            if (string.IsNullOrWhiteSpace(parameters.Url) && string.IsNullOrWhiteSpace(parameters.Txt))
            {
                throw new InvalidOperationException("Either \"Url\" or \"Txt\" must be part of your request.");
            }

            defaultParameters    = parameters;
            defaultMCEndpointUrl = mcEndpointUrl;
            defaultMCRequestUri  = mcRequstUri;
        }