Example #1
0
        /// <summary>
        /// the response for the search all KB request
        /// </summary>
        /// <param name="subdomain">the site's subdomain</param>
        /// <param name="consumerKey">your consumer key</param>
        /// <param name="consumerSecret">your consumer secret</param>
        /// <param name="query">your search query</param>
        /// <param name="page">the page number</param>
        /// <param name="perPage">the number of articles per page</param>
        /// <param name="filter">how the request response should be filtered</param>
        /// <param name="sort">the order in which the response should be sorted</param>
        /// <returns>IRestResponse containing the requested data</returns>
        private async Task <IRestResponse> SearchAllArticlesResponse(string subdomain, string consumerKey, string consumerSecret, string query, int page = 1, int perPage = 10, ArticlesFilter filter = ArticlesFilter.all, ArticlesSort sort = ArticlesSort.newest)
        {
            _client.BaseUrl       = new Uri(string.Format("https://{0}.uservoice.com/api/v1/", subdomain));
            _client.Authenticator = OAuth1Authenticator.ForProtectedResource(consumerKey, consumerSecret, null, null);

            RestRequest request = new RestRequest("search.json", HttpMethod.Get);

            request.AddHeader("If-Modified-Since", DateTime.Now.ToUniversalTime().ToString("R"));


            request.AddParameter("page", page);
            request.AddParameter("query", query);
            request.AddParameter("per_page", perPage);
            request.AddParameter("filter", filter);
            request.AddParameter("sort", sort);

            return(await _client.Execute(request));
        }
Example #2
0
        /// <summary>
        /// async wrapper for the KnowledgeBase Model
        /// </summary>
        /// <param name="subdomain">the site's subdomain</param>
        /// <param name="consumerKey">your consumer key</param>
        /// <param name="consumerSecret">your consumer secret</param>
        /// <param name="page">the page number</param>
        /// <param name="perPage">the number of articles per page</param>
        /// <param name="filter">how the request response should be filtered</param>
        /// <param name="sort">the order in which the response should be sorted</param>
        /// <returns>data to be filled in the KnowledgeBase model</returns>
        public async Task <KnowledgeBaseResult> GetAllArticles(string subdomain, string consumerKey, string consumerSecret, int page = 1, int perPage = 10, ArticlesFilter filter = ArticlesFilter.all, ArticlesSort sort = ArticlesSort.newest)
        {
            KnowledgeBaseResult allKB = new KnowledgeBaseResult();

            IRestResponse response = await GetAllArticlesResponse(subdomain, consumerKey, consumerSecret, page, perPage, filter, sort);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                string jsonContent = Encoding.UTF8.GetString(response.RawBytes, 0, response.RawBytes.Length);

                allKB = JsonConvert.DeserializeObject <KnowledgeBaseResult>(jsonContent);
            }

            return(allKB);
        }