Exemple #1
0
        public async Task <StackResponse> GetStack()
        {
            Dictionary <String, Object> headers   = GetHeader(_LocalHeaders);
            Dictionary <String, object> headerAll = new Dictionary <string, object>();
            Dictionary <string, object> mainJson  = new Dictionary <string, object>();

            if (headers != null && headers.Count() > 0)
            {
                foreach (var header in headers)
                {
                    headerAll.Add(header.Key, (String)header.Value);
                }
            }

            foreach (var kvp in UrlQueries)
            {
                mainJson.Add(kvp.Key, kvp.Value);
            }

            try
            {
                HTTPRequestHandler RequestHandler = new HTTPRequestHandler();
                var outputResult = await RequestHandler.ProcessRequest(_StackUrl, headers, mainJson);

                JObject data = JsonConvert.DeserializeObject <JObject>(outputResult.Replace("\r\n", ""), this.SerializerSettings);
                SerializerSettings.DateFormatString = "yyyy-MM-dd";
                var stack     = data["stack"];
                var stackJson = JsonConvert.SerializeObject(stack);
                return(JsonConvert.DeserializeObject <StackResponse>(stackJson, this.SerializerSettings));
            }
            catch (Exception ex)
            {
                throw GetContentstackError(ex);
            }
        }
Exemple #2
0
        /// <summary>
        /// This method returns comprehensive information of all the global fields available in a particular stack in your account.
        /// </summary>
        /// <example>
        /// <code>
        ///     ContentstackClient stack = new ContentstackClinet(&quot;blt5d4sample2633b&quot;, &quot;blt6d0240b5sample254090d&quot;, &quot;stag&quot;);
        ///     var result = await stack.GetGlobalFields();
        /// </code>
        /// </example>
        /// <returns>The List of Global Fields schema.</returns>
        public async Task <ContentstackResponse> GetGlobalFields(int skip = 0)
        {
            Dictionary <String, Object> headers   = GetHeader(_LocalHeaders);
            Dictionary <String, object> headerAll = new Dictionary <string, object>();
            Dictionary <string, object> mainJson  = new Dictionary <string, object>();

            if (headers != null && headers.Count() > 0)
            {
                foreach (var header in headers)
                {
                    headerAll.Add(header.Key, (String)header.Value);
                }
            }

            foreach (var kvp in UrlQueries)
            {
                mainJson.Add(kvp.Key, kvp.Value);
            }
            mainJson.Add("include_count", "true");
            mainJson.Add("skip", $"{skip}");
            try
            {
                HTTPRequestHandler RequestHandler = new HTTPRequestHandler();
                var outputResult = await RequestHandler.ProcessRequest(_GlobalFieldsUrl, headers, mainJson);

                JObject data         = JsonConvert.DeserializeObject <JObject>(outputResult.Replace("\r\n", ""), this.SerializerSettings);
                IList   globalFields = (IList)data["global_fields"];
                ContentstackResponse contentstackResponse = new ContentstackResponse();
                var ContentTypeJson = JsonConvert.SerializeObject(globalFields);
                contentstackResponse.listContentTypes = JsonConvert.DeserializeObject <List <Contenttype> >(ContentTypeJson);
                if (data["count"] != null)
                {
                    contentstackResponse.Count = (int)data["count"];
                }
                return(contentstackResponse);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw GetContentstackError(ex);
            }
        }