Exemple #1
0
        /// <summary>
        /// Gets all articles from api. If a store id is spesified then get all articles from that store.
        /// </summary>
        /// <param name="storeId">Numeric store id.</param>
        /// <returns>A list of articles.</returns>
        public async Task <List <Article> > GetArticlesAsync(int?storeId)
        {
            string path = ApiUrl + "services/articles/";

            if (storeId != null)
            {
                path            += "stores/" + storeId;
                StoresSelectedID = (int)storeId;
            }

            var articlesResponse = new GetArticlesResponse();

            using (var client = new HttpClient())
            {
                string HttpAuth = ConfigurationManager.AppSettings["HttpAuth"];
                client.DefaultRequestHeaders.Add("Authorization", "Basic " + HttpAuth);

                var httpResponse = await client.GetAsync(path);

                if (httpResponse.IsSuccessStatusCode)
                {
                    string responseDetails = httpResponse.Content.ReadAsStringAsync().Result;

                    articlesResponse = JsonConvert.DeserializeObject <GetArticlesResponse>(responseDetails);
                }
            }

            Articles = articlesResponse.articles;
            return(Articles);
        }
Exemple #2
0
        /// <summary>
        /// Call the "services/articles/" API Method.
        /// </summary>
        /// <returns>A response object send by the api.</returns>
        public static GetArticlesResponse GetArticles()
        {
            var articlesResponse = new GetArticlesResponse();

            using (var client = new HttpClient())
            {
                string HttpAuth = ConfigurationManager.AppSettings["HttpAuth"];
                client.DefaultRequestHeaders.Add("Authorization", "Basic " + HttpAuth);
                var httpResponse = client.GetAsync(ApiUrl + "services/articles/");

                if (httpResponse.Result.IsSuccessStatusCode)
                {
                    string responseDetails = httpResponse.Result.Content.ReadAsStringAsync().Result;

                    articlesResponse = JsonConvert.DeserializeObject <GetArticlesResponse>(responseDetails);
                }
            }

            return(articlesResponse);
        }