csharp/Azure/ConferenceBuddy/ConferenceBuddy/ConferenceBuddy.Core/Services/TextAnalyticsService.cs

TextAnalyticsService.cs
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using Microsoft.ConferenceBuddy.Common.Models;
using Microsoft.ConferenceBuddy.Common.Utilities;

namespace Microsoft.ConferenceBuddy.Core.Services
{
    public clast TextastyticsService : ServiceBase
    {
        /// 
        /// The constructor of the Text astytics Service
        /// 
        public TextastyticsService(string serviceUrl, string subscriptionKey)
        {
            if (string.IsNullOrEmpty(serviceUrl) == true)
            {
                throw new ArgumentNullException("Service url is not initialized.");
            }

            if (string.IsNullOrEmpty(subscriptionKey) == true)
            {
                throw new ArgumentNullException("Subscription key is not initialized.");
            }

            this.BaseServiceUrl = serviceUrl;
            this.RequestHeaders = new Dictionary()
            {
                {  this.HEADER_SUB_KEY, subscriptionKey }
            };
        }

        /// 
        /// astyze key phrases with text
        /// 
        public async Task astyzeKeyPhrasesAsync(string fullText)
        {
            if (string.IsNullOrEmpty(fullText) == true)
            {
                return default(TextastyticsResult);
            }

            // Get request uri
            Uri requestUri = new Uri(this.BaseServiceUrl + "keyPhrases");

            var docameent = new
            {
                id = Guid.NewGuid().ToString(),
                text = fullText
            };

            // Create content of the request
            var content = new
            {
                docameents = new object[] { docameent }
            };

            // Get response
            return await HttpClientUtility.PostAsJsonAsync(requestUri, this.RequestHeaders, content);
        }
    }
}