From 8a85a5ebded155b90a5e9fea4d6a86190ba67b08 Mon Sep 17 00:00:00 2001 From: Uttam K Ukkoji Date: Mon, 4 Mar 2019 16:25:07 +0530 Subject: [PATCH 01/13] Added functionality to override Host and version --- .../Contentstack.Core.Tests.csproj | 2 + Contentstack.Core.Tests/StackConfig.cs | 9 +- .../Configuration/ContentstackOptions.cs | 9 + Contentstack.Core/ContentstackClient.cs | 23 +- Contentstack.Core/Models/Entry.cs | 113 ++------- Contentstack.Core/Models/Query.cs | 62 ++--- README.md | 224 +++++++++--------- 7 files changed, 180 insertions(+), 262 deletions(-) mode change 100644 => 100755 README.md diff --git a/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj b/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj index d30d430..c087835 100644 --- a/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj +++ b/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj @@ -12,6 +12,7 @@ + @@ -33,6 +34,7 @@ + diff --git a/Contentstack.Core.Tests/StackConfig.cs b/Contentstack.Core.Tests/StackConfig.cs index 72fe74c..d537d1f 100644 --- a/Contentstack.Core.Tests/StackConfig.cs +++ b/Contentstack.Core.Tests/StackConfig.cs @@ -2,6 +2,7 @@ using Contentstack.Core; using Contentstack.Core.Models; using System.Configuration; +using Microsoft.Extensions.Options; namespace Contentstack.Core.Tests { @@ -30,16 +31,16 @@ public static ContentstackClient GetStack() string apiKey = ConfigurationManager.AppSettings["api_key"]; string accessToken = ConfigurationManager.AppSettings["access_token"]; string environment = ConfigurationManager.AppSettings["environment"]; - + string host = ConfigurationManager.AppSettings["host"]; Configuration.ContentstackOptions contentstackOptions = new Configuration.ContentstackOptions { ApiKey = apiKey, AccessToken = accessToken, - Environment = environment + Environment = environment, + Host = host }; - ContentstackClient contentstackClient = new ContentstackClient(apiKey, accessToken, environment); - + ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper(contentstackOptions)); return contentstackClient; } diff --git a/Contentstack.Core/Configuration/ContentstackOptions.cs b/Contentstack.Core/Configuration/ContentstackOptions.cs index 4793b34..c95fc57 100644 --- a/Contentstack.Core/Configuration/ContentstackOptions.cs +++ b/Contentstack.Core/Configuration/ContentstackOptions.cs @@ -21,5 +21,14 @@ public class ContentstackOptions /// public string Environment { get; set; } + /// + /// The Host used to set host url for the ContentStack API. + /// + public string Host { get; set; } + + /// + /// The Version number for the ContentStack API. + /// + public string Version { get; set; } } } diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index f65f964..20a255b 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -49,6 +49,14 @@ public ContentstackClient(IOptions options) this.SetHeader("access_token", _options.AccessToken); Config cnfig = new Config(); cnfig.Environment = _options.Environment; + if (_options.Host != null) + { + cnfig.Host = _options.Host; + } + if (_options.Version != null) + { + cnfig.Version = _options.Version; + } this.SetConfig(cnfig); } @@ -74,13 +82,16 @@ public ContentstackClient(ContentstackOptions options) : /// ContentType contentType = stack.ContentType("contentType_name"); /// /// - public ContentstackClient(string apiKey, string accessToken, string environment) : + public ContentstackClient(string apiKey, string accessToken, string environment, string host = null, string version = null) : this(new OptionsWrapper(new ContentstackOptions() - { - ApiKey = apiKey, - AccessToken = accessToken, - Environment = environment - })) + { + ApiKey = apiKey, + AccessToken = accessToken, + Environment = environment, + Host = host, + Version = version + } + )) { } diff --git a/Contentstack.Core/Models/Entry.cs b/Contentstack.Core/Models/Entry.cs index 47cdff0..fbbbed0 100755 --- a/Contentstack.Core/Models/Entry.cs +++ b/Contentstack.Core/Models/Entry.cs @@ -23,8 +23,20 @@ public class Entry private ContentType ContentTypeInstance { get; set; } private CachePolicy _CachePolicy; private Dictionary UrlQueries = new Dictionary(); - private string _Url; - private bool _IsCachePolicySet; + private bool _IsCachePolicySet; + private string _Url + { + get + { + + Config config = this.ContentTypeInstance.StackInstance.config; + + if (!String.IsNullOrEmpty(this.EntryUid)) + return String.Format("{0}/content_types/{1}/entries/{2}", config.BaseUrl, this.ContentTypeInstance.ContentTypeName, this.EntryUid); + else + return String.Format("{0}/content_types/{1}/entries", config.BaseUrl, this.ContentTypeInstance.ContentTypeName); + } + } #endregion #region Internal Variables @@ -71,48 +83,6 @@ public class Entry /// public string EntryUid { get; set; } - /// - /// Rest Url for an Entry on contentstack.io - /// - /// - /// - /// //"blt5d4sample2633b" is a dummy Stack API key - /// //"blt6d0240b5sample254090d" is dummy access token. - /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); - /// Entry entry = stack.ContentType("contentType_name").Entry("entry_uid"); - /// entry.Fetch().ContinueWith((entryResult) => { - /// //Your callback code. - /// //var result = entryResult.Result.Url; - /// }); - /// - /// - public string Url - { - get - { - if (string.IsNullOrEmpty(this._Url)) - { - Config config = this.ContentTypeInstance.StackInstance.config; - - if (!String.IsNullOrEmpty(this.EntryUid)) - return String.Format("{0}/content_types/{1}/entries/{2}", config.BaseUrl, this.ContentTypeInstance.ContentTypeName, this.EntryUid); - else - return String.Format("{0}/content_types/{1}/entries", config.BaseUrl, this.ContentTypeInstance.ContentTypeName); - } - else - { - if (!String.IsNullOrEmpty(this.EntryUid) && !this._Url.Contains(this.EntryUid)) - this._Url += "/" + this.EntryUid; - - return this._Url; - } - } - set - { - this._Url = value; - } - } - /// /// Set array of Tags /// @@ -388,27 +358,6 @@ public Entry SetCachePolicy(CachePolicy cachePolicy) return this; } - /// - /// Returns Rest Url for an Entry on contentstack.io - /// - /// url in string - /// - /// - /// //"blt5d4sample2633b" is a dummy Stack API key - /// //"blt6d0240b5sample254090d" is dummy access token. - /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); - /// Entry entry = stack.ContentType("contentType_name").Entry("entry_uid"); - /// entry.Fetch().ContinueWith((entryResult) => { - /// //Your callback code. - /// //var result = entryResult.Result.GetURL(); - /// }); - /// - /// - public string GetURL() - { - return Url; - } - /// /// Get title /// @@ -1366,23 +1315,6 @@ public async Task Fetch() mainJson.Add(kvp.Key, kvp.Value); } - - //foreach (var value in mainJson) - //{ - // if (value.Value is Dictionary) - // { - // Url = Url + "&" + value.Key + "=" + JsonConvert.SerializeObject(value.Value); - // } - // else - // { - // Url = Url + "&" + value.Key + "=" + value.Value; - // } - //} - - //mainJson.Add("query", UrlQueries); - - //mainJson.Add("_method", HttpMethods.Get.ToString().ToUpper()); - try { //String mainStringForMD5 = Url + JsonConvert.SerializeObject(mainJson) + JsonConvert.SerializeObject(headers); @@ -1410,7 +1342,7 @@ public async Task Fetch() case CachePolicy.NetworkOnly: HTTPRequestHandler RequestHandler = new HTTPRequestHandler(); - var outputResult = await RequestHandler.ProcessRequest(Url, headers, mainJson); + var outputResult = await RequestHandler.ProcessRequest(_Url, headers, mainJson); StackOutput stackOutput = new StackOutput(ContentstackConvert.ToString(outputResult, "{}")); ParseObject((Dictionary)stackOutput.Object); break; @@ -1484,11 +1416,6 @@ public async Task Fetch() break; } - //HTTPRequestHandler contentstackRequestHandler = new HTTPRequestHandler(); - //var result = await contentstackRequestHandler.ProcessRequest(Url, headers, mainJson); - //StackOutput contentstackOutput = new StackOutput(ContentstackConvert.ToString(result, "{}")); - ////Entry resultObject = new Entry(); - //ParseObject((Dictionary)contentstackOutput.Object); return this; } catch (Exception ex) @@ -1592,16 +1519,6 @@ internal Entry ParseObject(Dictionary jsonObj, string url = null this.Title = string.IsNullOrEmpty(jsonObj["title"].ToString()) ? " " : jsonObj["title"].ToString(); } - //if (jsonObj != null && jsonObj.ContainsKey("url")) - //{ - // this.Url = string.IsNullOrEmpty(jsonObj["url"].ToString()) ? " " : jsonObj["url"].ToString(); - //} - - if (url != null) - { - this.Url = url + "/" + this.EntryUid; - } - if (jsonObj != null && jsonObj.ContainsKey("_metadata")) { Dictionary _metadataJSON = (Dictionary)jsonObj["_metadata"]; diff --git a/Contentstack.Core/Models/Query.cs b/Contentstack.Core/Models/Query.cs index 5b69a59..340da2b 100644 --- a/Contentstack.Core/Models/Query.cs +++ b/Contentstack.Core/Models/Query.cs @@ -19,61 +19,39 @@ public class Query { #region Private Variables - internal Dictionary _FormHeaders = new Dictionary(); private Dictionary _Headers = new Dictionary(); private Dictionary UrlQueries = new Dictionary(); private Dictionary QueryValueJson = new Dictionary(); private string _ResultJson = string.Empty; - private string _Url; private Entry[] _Result; private List> _Schema; private CachePolicy _CachePolicy; private int _TotalCount; private ContentType ContentTypeInstance { get; set; } - private bool _IsCachePolicySet; - #endregion + private bool _IsCachePolicySet; + + private string _Url + { + get + { - #region Public Properties - /// - /// Rest Url for a entry on contentstack.io. - /// - /// - /// - /// //"blt5d4sample2633b" is a dummy Stack API key - /// //"blt6d0240b5sample254090d" is dummy access token. - /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); - /// Query csQuery = stack.ContentType("contentType_name").Query(); - /// csQuery.Find().ContinueWith((queryResult) => { - /// //Your callback code. - /// var result = queryResult.Result.Url; - /// }); - /// - /// - public string Url { - get { - if (string.IsNullOrEmpty(this._Url)) { - Config config = this.ContentTypeInstance.StackInstance.config; - String contentTypeName = this.ContentTypeInstance.ContentTypeName; - //String queryParam = String.Join("&", - //UrlQueries.Select(kvp =>{ - // return String.Format("{0}={1}", kvp.Key, kvp.Value); - - //})); - return String.Format("{0}/content_types/{1}/entries", - config.BaseUrl, - contentTypeName); - } else { + Config config = this.ContentTypeInstance.StackInstance.config; + String contentTypeName = this.ContentTypeInstance.ContentTypeName; + //String queryParam = String.Join("&", + //UrlQueries.Select(kvp =>{ + // return String.Format("{0}={1}", kvp.Key, kvp.Value); + + //})); + return String.Format("{0}/content_types/{1}/entries", + config.BaseUrl, + contentTypeName); - return this._Url; - } - } - set - { - this._Url = value; } } + #endregion + #region Public Properties /// /// Content type uid. /// @@ -1700,7 +1678,7 @@ private async Task Exec() case CachePolicy.NetworkOnly: HTTPRequestHandler requestHandler = new HTTPRequestHandler(); - var output = await requestHandler.ProcessRequest(Url, headers, mainJson); + var output = await requestHandler.ProcessRequest(_Url, headers, mainJson); StackOutput stackOutput = new StackOutput(ContentstackConvert.ToString(output, "{}")); await GetOutputAsync(stackOutput); break; @@ -1865,7 +1843,7 @@ private Task GetOutputAsync(StackOutput output) foreach (var item in result) { Entry entry = new Entry(); - lstEntryObject.Add(entry.ParseObject((Dictionary)item,this.Url)); + lstEntryObject.Add(entry.ParseObject((Dictionary)item,this._Url)); } this._Result = lstEntryObject.ToArray(); } diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 782eb1d..c506e3f --- a/README.md +++ b/README.md @@ -1,113 +1,113 @@ -[![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/) -# Contentstack dotnet - -.NET SDK for Contentstack's Content Delivery API - -## Getting Started - -This guide will help you get started with our .NET SDK to build apps powered by Contentstack. - -## SDK Installation and Setup - -To use the .NET SDK, download it from here - -Open the terminal and install the contentstack module via ‘Package Manager’ command - -``` console -PM> Install-Package contentstack.csharp -``` -And via ‘.Net CLI’ -``` console -dotnet add package contentstack.csharp -``` -To use the module in your application, you need to first Add Namespace to your class - -``` cs -using Contentstack.Core; // ContentstackClient -using Contentstack.Core.Models; // Stack, Query, Entry, Asset, ContentType -using Contentstack.Core.Configuration; // ContentstackOptions -``` - -## Initialize SDK - -You will need to specify the API key, Access token, and Environment Name of your stack to initialize the SDK: - -``` cs -// Initialize the Contentstack -ContentstackClient stack = new ContentstackClient("api_key", "access_token", "enviroment_name"); -``` -or: - -``` cs -// -var options = new ContentstackOptions() -{ - ApiKey = "", - AccessToken = "" - Environment = "" -} -ContentstackClient stack = new ContentstackClient(options); -``` - -Once you have initialized the SDK, you can start getting content in your app. - -## Basic Queries - -### Get a Single Entry - -To retrieve a single entry from a content type, use the code snippet given below: -``` cs -Entry entry = client.ContentType("blog").Entry("blta464e9fbd048668c"); -entry.Fetch().ContinueWith((t) => { - if (!t.IsFaulted) { - Console.WriteLine("entry:" + t.Result); - } -}); -``` - -### Get Multiple Entries - -To retrieve multiple entries of a particular content type, use the code snippet given below: - -``` cs - -Query query = client.ContentType("blog").Query(); -query.Where("title", "welcome"); -query.IncludeSchema(); -query.IncludeCount(); -query.ToJSON(); -query.Find().ContinueWith((t) => { - if (!t.IsFaulted) { - Entry[] result = t.Result.Result; - Console.WriteLine("result" + result); - } -}); -``` -These were example of some of the basic queries of the SDK. For advanced queries, refer to our API reference documentation by visiting the link given below. - -## API Reference -Go through our .NET SDK API Reference guide to know about the methods that can be used to query your content in Contentstack. - -[Read .NET API Reference Guide](https://www.contentstack.com/docs/platforms/dot-net/api-reference/api/index.html) - -## Example -To help you get started, we have created a sample application that is powered by Contentstack .NET SDK. Click on the link below to read the tutorial of the app. - -[.NET News Console App](https://www.contentstack.com/docs/example-apps/build-a-news-app-using-contentstack-dot-net-sdk) - - -### Helpful Links - -- [Contentstack Website](https://www.contentstack.com) -- [Official Documentation](https://contentstack.com/docs) -- [Content Delivery API Docs](https://contentstack.com/docs/apis/content-delivery-api/) - -### The MIT License (MIT) - -Copyright © 2012-2018 [Contentstack](https://www.contentstack.com/). All Rights Reserved - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - +[![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/) +# Contentstack dotnet + +.NET SDK for Contentstack's Content Delivery API + +## Getting Started + +This guide will help you get started with our .NET SDK to build apps powered by Contentstack. + +## SDK Installation and Setup + +To use the .NET SDK, download it from here + +Open the terminal and install the contentstack module via ‘Package Manager’ command + +``` console +PM> Install-Package contentstack.csharp +``` +And via ‘.Net CLI’ +``` console +dotnet add package contentstack.csharp +``` +To use the module in your application, you need to first Add Namespace to your class + +``` cs +using Contentstack.Core; // ContentstackClient +using Contentstack.Core.Models; // Stack, Query, Entry, Asset, ContentType +using Contentstack.Core.Configuration; // ContentstackOptions +``` + +## Initialize SDK + +You will need to specify the API key, Access token, and Environment Name of your stack to initialize the SDK: + +``` cs +// Initialize the Contentstack +ContentstackClient stack = new ContentstackClient("api_key", "access_token", "enviroment_name"); +``` +or: + +``` cs +// +var options = new ContentstackOptions() +{ + ApiKey = "", + AccessToken = "" + Environment = "" +} +ContentstackClient stack = new ContentstackClient(options); +``` + +Once you have initialized the SDK, you can start getting content in your app. + +## Basic Queries + +### Get a Single Entry + +To retrieve a single entry from a content type, use the code snippet given below: +``` cs +Entry entry = client.ContentType("blog").Entry("blta464e9fbd048668c"); +entry.Fetch().ContinueWith((t) => { + if (!t.IsFaulted) { + Console.WriteLine("entry:" + t.Result); + } +}); +``` + +### Get Multiple Entries + +To retrieve multiple entries of a particular content type, use the code snippet given below: + +``` cs + +Query query = client.ContentType("blog").Query(); +query.Where("title", "welcome"); +query.IncludeSchema(); +query.IncludeCount(); +query.ToJSON(); +query.Find().ContinueWith((t) => { + if (!t.IsFaulted) { + Entry[] result = t.Result.Result; + Console.WriteLine("result" + result); + } +}); +``` +These were example of some of the basic queries of the SDK. For advanced queries, refer to our API reference documentation by visiting the link given below. + +## API Reference +Go through our .NET SDK API Reference guide to know about the methods that can be used to query your content in Contentstack. + +[Read .NET API Reference Guide](https://www.contentstack.com/docs/platforms/dot-net/api-reference/api/index.html) + +## Example +To help you get started, we have created a sample application that is powered by Contentstack .NET SDK. Click on the link below to read the tutorial of the app. + +[.NET News Console App](https://www.contentstack.com/docs/example-apps/build-a-news-app-using-contentstack-dot-net-sdk) + + +### Helpful Links + +- [Contentstack Website](https://www.contentstack.com) +- [Official Documentation](https://contentstack.com/docs) +- [Content Delivery API Docs](https://contentstack.com/docs/apis/content-delivery-api/) + +### The MIT License (MIT) + +Copyright © 2012-2018 [Contentstack](https://www.contentstack.com/). All Rights Reserved + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file From a4ab1b0c0cecfb7735c7756667dadab22602ddcd Mon Sep 17 00:00:00 2001 From: Uttam K Ukkoji Date: Thu, 14 Mar 2019 11:56:53 +0530 Subject: [PATCH 02/13] stack schema fetch implemented --- .../TestResults/Prod_2019-03-08_14_48_46.trx | 347 ++++++++++++++++++ ...Uttams-MacBook-Pro_2019-03-08_14_48_46.trx | 347 ++++++++++++++++++ 2 files changed, 694 insertions(+) create mode 100644 Contentstack.Core.Tests/TestResults/Prod_2019-03-08_14_48_46.trx create mode 100644 Contentstack.Core.Tests/TestResults/_Uttams-MacBook-Pro_2019-03-08_14_48_46.trx diff --git a/Contentstack.Core.Tests/TestResults/Prod_2019-03-08_14_48_46.trx b/Contentstack.Core.Tests/TestResults/Prod_2019-03-08_14_48_46.trx new file mode 100644 index 0000000..e2293f2 --- /dev/null +++ b/Contentstack.Core.Tests/TestResults/Prod_2019-03-08_14_48_46.trx @@ -0,0 +1,347 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [xUnit.net 00:00:00.5946316] Discovering: Contentstack.Core.Tests[xUnit.net 00:00:00.6691032] Discovered: Contentstack.Core.Tests[xUnit.net 00:00:00.6759638] Starting: Contentstack.Core.Tests[xUnit.net 00:00:30.9190659] Finished: Contentstack.Core.Tests + + + \ No newline at end of file diff --git a/Contentstack.Core.Tests/TestResults/_Uttams-MacBook-Pro_2019-03-08_14_48_46.trx b/Contentstack.Core.Tests/TestResults/_Uttams-MacBook-Pro_2019-03-08_14_48_46.trx new file mode 100644 index 0000000..e2293f2 --- /dev/null +++ b/Contentstack.Core.Tests/TestResults/_Uttams-MacBook-Pro_2019-03-08_14_48_46.trx @@ -0,0 +1,347 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [xUnit.net 00:00:00.5946316] Discovering: Contentstack.Core.Tests[xUnit.net 00:00:00.6691032] Discovered: Contentstack.Core.Tests[xUnit.net 00:00:00.6759638] Starting: Contentstack.Core.Tests[xUnit.net 00:00:30.9190659] Finished: Contentstack.Core.Tests + + + \ No newline at end of file From 0346874cce5736aed92dfa0806cd44de5f8e46bc Mon Sep 17 00:00:00 2001 From: Uttam K Ukkoji Date: Thu, 14 Mar 2019 11:57:36 +0530 Subject: [PATCH 03/13] stack schema fetch implemented --- Contentstack.Core.Tests/EntryTest.cs | 34 +- .../TestResults/Prod_2019-03-08_14_48_46.trx | 347 ------------------ ...Uttams-MacBook-Pro_2019-03-08_14_48_46.trx | 347 ------------------ Contentstack.Core/ContentstackClient.cs | 165 ++++++++- Contentstack.Core/Models/ContentType.cs | 132 ++++++- 5 files changed, 325 insertions(+), 700 deletions(-) delete mode 100644 Contentstack.Core.Tests/TestResults/Prod_2019-03-08_14_48_46.trx delete mode 100644 Contentstack.Core.Tests/TestResults/_Uttams-MacBook-Pro_2019-03-08_14_48_46.trx diff --git a/Contentstack.Core.Tests/EntryTest.cs b/Contentstack.Core.Tests/EntryTest.cs index bec787c..0ec85f0 100644 --- a/Contentstack.Core.Tests/EntryTest.cs +++ b/Contentstack.Core.Tests/EntryTest.cs @@ -6,7 +6,8 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; - +using System.Collections; + namespace Contentstack.Core.Tests { @@ -33,6 +34,37 @@ public async Task FetchByUid() { } } + [Fact] + public async Task GetContentTypes() + { + var result = await client.getContentTypes(); + + if (result == null) + { + Assert.False(true, "client.getContentTypes is not match with expected result."); + } + else + { + Assert.True(true); + + } + } + + [Fact] + public async Task FetchContenTypeSchema() + { + ContentType contenttype = client.ContentType(source); + var result = await contenttype.Fetch(); + if (result == null) + { + Assert.False(true, "contenttype.FetchSchema() is not match with expected result."); + } + else + { + Assert.True(true); + } + } + [Fact] public async Task IncludeReference() { ContentType contenttype = client.ContentType(source); diff --git a/Contentstack.Core.Tests/TestResults/Prod_2019-03-08_14_48_46.trx b/Contentstack.Core.Tests/TestResults/Prod_2019-03-08_14_48_46.trx deleted file mode 100644 index e2293f2..0000000 --- a/Contentstack.Core.Tests/TestResults/Prod_2019-03-08_14_48_46.trx +++ /dev/null @@ -1,347 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [xUnit.net 00:00:00.5946316] Discovering: Contentstack.Core.Tests[xUnit.net 00:00:00.6691032] Discovered: Contentstack.Core.Tests[xUnit.net 00:00:00.6759638] Starting: Contentstack.Core.Tests[xUnit.net 00:00:30.9190659] Finished: Contentstack.Core.Tests - - - \ No newline at end of file diff --git a/Contentstack.Core.Tests/TestResults/_Uttams-MacBook-Pro_2019-03-08_14_48_46.trx b/Contentstack.Core.Tests/TestResults/_Uttams-MacBook-Pro_2019-03-08_14_48_46.trx deleted file mode 100644 index e2293f2..0000000 --- a/Contentstack.Core.Tests/TestResults/_Uttams-MacBook-Pro_2019-03-08_14_48_46.trx +++ /dev/null @@ -1,347 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [xUnit.net 00:00:00.5946316] Discovering: Contentstack.Core.Tests[xUnit.net 00:00:00.6691032] Discovered: Contentstack.Core.Tests[xUnit.net 00:00:00.6759638] Starting: Contentstack.Core.Tests[xUnit.net 00:00:30.9190659] Finished: Contentstack.Core.Tests - - - \ No newline at end of file diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index 20a255b..c1bbd9d 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -4,6 +4,13 @@ using Contentstack.Core.Configuration; using Microsoft.Extensions.Options; using Contentstack.Core.Models; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; +using System.Linq; +using System.Threading.Tasks; +using System.Net; +using System.IO; +using System.Collections; namespace Contentstack.Core { @@ -20,8 +27,17 @@ internal string StackApiKey set; } private ContentstackOptions _options; - - + private Dictionary UrlQueries = new Dictionary(); + private Dictionary _Headers = new Dictionary(); + private string _Url + { + get + { + Config config = this.config; + return String.Format("{0}/content_types/", config.BaseUrl); + } + } + private Dictionary _StackHeaders = new Dictionary(); /// /// Initializes a instance of the class. /// @@ -61,6 +77,62 @@ public ContentstackClient(IOptions options) } + + internal static ContentstackError GetContentstackError(Exception ex) + { + Int32 errorCode = 0; + string errorMessage = string.Empty; + HttpStatusCode statusCode = HttpStatusCode.InternalServerError; + ContentstackError contentstackError = new ContentstackError(ex); + Dictionary errors = null; + //ContentstackError.OtherErrors errors = null; + + try + { + System.Net.WebException webEx = (System.Net.WebException)ex; + + using (var exResp = webEx.Response) + using (var stream = exResp.GetResponseStream()) + using (var reader = new StreamReader(stream)) + { + errorMessage = reader.ReadToEnd(); + JObject data = JObject.Parse(errorMessage.Replace("\r\n", "")); + //errorCode = ContentstackConvert.ToInt32(data.Property("error_code").Value); + //errorMessage = ContentstackConvert.ToString(data.Property("error_message").Value); + + JToken token = data["error_code"]; + if (token != null) + errorCode = token.Value(); + + token = data["error_message"]; + if (token != null) + errorMessage = token.Value(); + + token = data["errors"]; + if (token != null) + errors = token.ToObject>(); + + var response = exResp as HttpWebResponse; + if (response != null) + statusCode = response.StatusCode; + } + } + catch + { + errorMessage = ex.Message; + } + + contentstackError = new ContentstackError() + { + ErrorCode = errorCode, + ErrorMessage = errorMessage, + StatusCode = statusCode, + Errors = errors + }; + + return contentstackError; + } + public ContentstackClient(ContentstackOptions options) : this(new OptionsWrapper(options)) { @@ -125,6 +197,55 @@ internal void SetConfig(Config cnfig) #endregion #region Public Functions + public async Task getContentTypes() + { + Dictionary headers = GetHeader(_LocalHeaders); + Dictionary headerAll = new Dictionary(); + Dictionary mainJson = new Dictionary(); + + //Dictionary urlQueries = new Dictionary(); + + if (headers != null && headers.Count() > 0) + { + foreach (var header in headers) + { + headerAll.Add(header.Key, (String)header.Value); + } + + if (headers.ContainsKey("environment")) + { + UrlQueries.Add("environment", headers["environment"]); + //Url = Url + "?environment=" + headers["environment"]; + } + else if (headers.ContainsKey("environment_uid")) + { + UrlQueries.Add("environment_uid", headers["environment_uid"]); + //Url = Url + "?environment_uid=" + headers["environment_uid"]; + } + else + { + + mainJson.Add("environment", this.config.Environment); + } + } + + foreach (var kvp in UrlQueries) + { + mainJson.Add(kvp.Key, kvp.Value); + } + try + { + HTTPRequestHandler RequestHandler = new HTTPRequestHandler(); + var outputResult = await RequestHandler.ProcessRequest(_Url, headers, mainJson); + JObject data = JsonConvert.DeserializeObject(outputResult.Replace("\r\n", ""), ContentstackConvert.JsonSerializerSettings); + IList contentTypes = (IList)data["content_types"]; + return contentTypes; + } + catch (Exception ex) + { + throw GetContentstackError(ex); + } + } /// /// Represents a ContentType. Creates ContenntType Instance. @@ -353,6 +474,46 @@ public void SetHeader(string key, string value) #endregion #region Private Functions + + private Dictionary GetHeader(Dictionary localHeader) + { + Dictionary mainHeader = _StackHeaders; + Dictionary classHeaders = new Dictionary(); + + if (localHeader != null && localHeader.Count > 0) + { + if (mainHeader != null && mainHeader.Count > 0) + { + foreach (var entry in localHeader) + { + String key = entry.Key; + classHeaders.Add(key, entry.Value); + } + + foreach (var entry in mainHeader) + { + String key = entry.Key; + if (!classHeaders.ContainsKey(key)) + { + classHeaders.Add(key, entry.Value); + } + } + + return classHeaders; + + } + else + { + return localHeader; + } + + } + else + { + return _StackHeaders; + } + } + private Dictionary GetHeader() { diff --git a/Contentstack.Core/Models/ContentType.cs b/Contentstack.Core/Models/ContentType.cs index db28de7..6fdf4c7 100644 --- a/Contentstack.Core/Models/ContentType.cs +++ b/Contentstack.Core/Models/ContentType.cs @@ -1,6 +1,14 @@ using System; using System.Collections.Generic; - +using Contentstack.Core.Configuration; +using Contentstack.Core.Internals; +using System.Threading.Tasks; +using System.Net; +using Newtonsoft.Json.Linq; +using System.Linq; +using System.IO; +using Newtonsoft.Json; + namespace Contentstack.Core.Models { /// @@ -10,7 +18,9 @@ public class ContentType { #region Public Properties internal ContentstackClient StackInstance { get; set; } - internal string Uid { get; set; } + internal string Uid { get; set; } + private Dictionary UrlQueries = new Dictionary(); + /// /// Content type uid /// @@ -24,7 +34,16 @@ public string ContentTypeName #region Private Properties private Dictionary _Headers = new Dictionary(); - private Dictionary _StackHeaders = new Dictionary(); + private Dictionary _StackHeaders = new Dictionary(); + + private string _Url + { + get + { + Config config = this.StackInstance.config; + return String.Format("{0}/content_types/{1}", config.BaseUrl,this.ContentTypeName); + } + } #endregion #region Internal Constructors @@ -45,6 +64,62 @@ internal ContentType(String contentTypeName) #endregion #region Internal Functions + + internal static ContentstackError GetContentstackError(Exception ex) + { + Int32 errorCode = 0; + string errorMessage = string.Empty; + HttpStatusCode statusCode = HttpStatusCode.InternalServerError; + ContentstackError contentstackError = new ContentstackError(ex); + Dictionary errors = null; + //ContentstackError.OtherErrors errors = null; + + try + { + System.Net.WebException webEx = (System.Net.WebException)ex; + + using (var exResp = webEx.Response) + using (var stream = exResp.GetResponseStream()) + using (var reader = new StreamReader(stream)) + { + errorMessage = reader.ReadToEnd(); + JObject data = JObject.Parse(errorMessage.Replace("\r\n", "")); + //errorCode = ContentstackConvert.ToInt32(data.Property("error_code").Value); + //errorMessage = ContentstackConvert.ToString(data.Property("error_message").Value); + + JToken token = data["error_code"]; + if (token != null) + errorCode = token.Value(); + + token = data["error_message"]; + if (token != null) + errorMessage = token.Value(); + + token = data["errors"]; + if (token != null) + errors = token.ToObject>(); + + var response = exResp as HttpWebResponse; + if (response != null) + statusCode = response.StatusCode; + } + } + catch + { + errorMessage = ex.Message; + } + + contentstackError = new ContentstackError() + { + ErrorCode = errorCode, + ErrorMessage = errorMessage, + StatusCode = statusCode, + Errors = errors + }; + + return contentstackError; + } + internal void SetStackInstance(ContentstackClient stack) { this.StackInstance = stack; @@ -53,6 +128,57 @@ internal void SetStackInstance(ContentstackClient stack) #endregion #region Public Functions + + public async TaskFetch() + { + Dictionary headers = GetHeader(_Headers); + Dictionary headerAll = new Dictionary(); + Dictionary mainJson = new Dictionary(); + + //Dictionary urlQueries = new Dictionary(); + + if (headers != null && headers.Count() > 0) + { + foreach (var header in headers) + { + headerAll.Add(header.Key, (String)header.Value); + } + + if (headers.ContainsKey("environment")) + { + UrlQueries.Add("environment", headers["environment"]); + //Url = Url + "?environment=" + headers["environment"]; + } + else if (headers.ContainsKey("environment_uid")) + { + UrlQueries.Add("environment_uid", headers["environment_uid"]); + //Url = Url + "?environment_uid=" + headers["environment_uid"]; + } + else + { + + mainJson.Add("environment", this.StackInstance.config.Environment); + } + } + + foreach (var kvp in UrlQueries) + { + mainJson.Add(kvp.Key, kvp.Value); + } + try + { + HTTPRequestHandler RequestHandler = new HTTPRequestHandler(); + var outputResult = await RequestHandler.ProcessRequest(_Url, headers, mainJson); + JObject data = JsonConvert.DeserializeObject(outputResult.Replace("\r\n", ""), ContentstackConvert.JsonSerializerSettings); + JObject contentTypes = (Newtonsoft.Json.Linq.JObject)data["content_type"]; + return contentTypes; + } + catch (Exception ex) + { + throw GetContentstackError(ex); + } + } + /// /// To set headers for Built.io Contentstack rest calls. /// From 998b02d16cc55ffd085b309581029788398349d4 Mon Sep 17 00:00:00 2001 From: Uttam K Ukkoji Date: Thu, 11 Apr 2019 11:38:46 +0530 Subject: [PATCH 04/13] Test cases refactor --- Contentstack.Core.Tests/SyncStackTest.cs | 10 ++++++++++ Contentstack.Core/Models/SyncStack.cs | 21 +++++++++++++++++++++ Contentstack.Core/Models/SyncType.cs | 10 ++++++++++ Contentstack.Core/Models/Untitled.html | 24 ++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 Contentstack.Core.Tests/SyncStackTest.cs create mode 100755 Contentstack.Core/Models/SyncStack.cs create mode 100644 Contentstack.Core/Models/SyncType.cs create mode 100644 Contentstack.Core/Models/Untitled.html diff --git a/Contentstack.Core.Tests/SyncStackTest.cs b/Contentstack.Core.Tests/SyncStackTest.cs new file mode 100644 index 0000000..e3e3b5d --- /dev/null +++ b/Contentstack.Core.Tests/SyncStackTest.cs @@ -0,0 +1,10 @@ +using System; +namespace Contentstack.Core.Tests +{ + public class SyncStackTest + { + public SyncStackTest() + { + } + } +} diff --git a/Contentstack.Core/Models/SyncStack.cs b/Contentstack.Core/Models/SyncStack.cs new file mode 100755 index 0000000..9ddcee6 --- /dev/null +++ b/Contentstack.Core/Models/SyncStack.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +namespace Contentstack.Core.Models +{ + public class SyncStack + { + public IEnumerable items { get; set; } + + public int skip { get; set; } + + public int limit { get; set; } + + public int total_count { get; set; } + + public string sync_token { get; set; } + + public string pagination_token { get; set; } + + } +} \ No newline at end of file diff --git a/Contentstack.Core/Models/SyncType.cs b/Contentstack.Core/Models/SyncType.cs new file mode 100644 index 0000000..39b730a --- /dev/null +++ b/Contentstack.Core/Models/SyncType.cs @@ -0,0 +1,10 @@ +using System; +namespace Contentstack.Core.Models +{ + public class SyncType + { + public SyncType() + { + } + } +} diff --git a/Contentstack.Core/Models/Untitled.html b/Contentstack.Core/Models/Untitled.html new file mode 100644 index 0000000..2a87f72 --- /dev/null +++ b/Contentstack.Core/Models/Untitled.html @@ -0,0 +1,24 @@ + + + + + + + + + + + + + Download + + + From c4f3603dd359adf1ba4984f1966f961e1552a523 Mon Sep 17 00:00:00 2001 From: Uttam K Ukkoji Date: Thu, 11 Apr 2019 11:39:26 +0530 Subject: [PATCH 05/13] Test cases refactor --- Contentstack.Core.Tests/EntryTest.cs | 1 - Contentstack.Core.Tests/StackConfig.cs | 24 ++ Contentstack.Core.Tests/SyncStackTest.cs | 128 +++++++- Contentstack.Core/ContentstackClient.cs | 273 ++++++++++++++++-- .../Internals/ContentStackError.cs | 2 +- .../Internals/ContentstackConstants.cs | 2 - .../Internals/ContentstackConvert.cs | 2 +- .../Internals/HTTPRequestHandler.cs | 2 +- Contentstack.Core/Internals/StackOutput.cs | 10 +- Contentstack.Core/Models/Asset.cs | 10 +- Contentstack.Core/Models/AssetLibrary.cs | 2 +- Contentstack.Core/Models/ContentType.cs | 2 +- Contentstack.Core/Models/Entry.cs | 18 +- Contentstack.Core/Models/Query.cs | 14 +- Contentstack.Core/Models/SyncStack.cs | 31 +- Contentstack.Core/Models/SyncType.cs | 44 ++- Contentstack.Core/Models/Untitled.html | 24 -- docfx_project/Template/styles/main.css | 75 +++++ docfx_project/api/index.md | 54 ++++ docfx_project/api/toc.yml | 31 ++ docfx_project/docfx.json | 68 +++++ docfx_project/filterRules.yml | 24 ++ docfx_project/images/favicon.ico | Bin 0 -> 32038 bytes docfx_project/images/logo.svg | 109 +++++++ docfx_project/index.md | 54 ++++ docfx_project/toc.yml | 3 + 26 files changed, 898 insertions(+), 109 deletions(-) delete mode 100644 Contentstack.Core/Models/Untitled.html create mode 100644 docfx_project/Template/styles/main.css create mode 100644 docfx_project/api/index.md create mode 100644 docfx_project/api/toc.yml create mode 100644 docfx_project/docfx.json create mode 100644 docfx_project/filterRules.yml create mode 100755 docfx_project/images/favicon.ico create mode 100755 docfx_project/images/logo.svg create mode 100644 docfx_project/index.md create mode 100644 docfx_project/toc.yml diff --git a/Contentstack.Core.Tests/EntryTest.cs b/Contentstack.Core.Tests/EntryTest.cs index bec787c..684632d 100644 --- a/Contentstack.Core.Tests/EntryTest.cs +++ b/Contentstack.Core.Tests/EntryTest.cs @@ -15,7 +15,6 @@ public class EntryTest ContentstackClient client = StackConfig.GetStack(); - String numbersContentType = "numbers_content_type"; String source = "source"; String singelEntryFetchUID = "blt1f94e478501bba46"; String referenceFieldUID = "reference"; diff --git a/Contentstack.Core.Tests/StackConfig.cs b/Contentstack.Core.Tests/StackConfig.cs index d537d1f..05d7b20 100644 --- a/Contentstack.Core.Tests/StackConfig.cs +++ b/Contentstack.Core.Tests/StackConfig.cs @@ -18,6 +18,30 @@ System.Configuration.Configuration assemblyConfiguration } } + public static ContentstackClient GetSyncStack() + { + StackConfig config = new StackConfig(); + if (config.assemblyConfiguration.HasFile && string.Compare(config.assemblyConfiguration.FilePath, config.currentConfiguration.FilePath, true) != 0) + { + config.assemblyConfiguration.SaveAs(config.currentConfiguration.FilePath); + ConfigurationManager.RefreshSection("appSettings"); + ConfigurationManager.RefreshSection("connectionStrings"); + } + string apiKey = ConfigurationManager.AppSettings["sync_api_key"]; + string accessToken = ConfigurationManager.AppSettings["sync_access_token"]; + string environment = ConfigurationManager.AppSettings["sync_environment"]; + string host = ConfigurationManager.AppSettings["host"]; + Configuration.ContentstackOptions contentstackOptions = new Configuration.ContentstackOptions + { + ApiKey = apiKey, + AccessToken = accessToken, + Environment = environment, + Host = host + }; + + ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper(contentstackOptions)); + return contentstackClient; + } public static ContentstackClient GetStack() { diff --git a/Contentstack.Core.Tests/SyncStackTest.cs b/Contentstack.Core.Tests/SyncStackTest.cs index e3e3b5d..f4ece25 100644 --- a/Contentstack.Core.Tests/SyncStackTest.cs +++ b/Contentstack.Core.Tests/SyncStackTest.cs @@ -1,10 +1,136 @@ using System; +using Xunit; +using Contentstack.Core.Configuration; +using System.Threading.Tasks; + namespace Contentstack.Core.Tests { public class SyncStackTest { - public SyncStackTest() + ContentstackClient client = StackConfig.GetSyncStack(); + + [Fact] + public async Task SyncInit() { + + var result = await client.SyncRecursive(); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + + [Fact] + public async Task SyncSyncType() + { + + var result = await client.SyncRecursive(SyncType: Models.SyncType.asset_published); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + [Fact] + public async Task SyncContentType() + { + + var result = await client.SyncRecursive(ContentTypeUid: "session"); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + [Fact] + public async Task SyncStartFrom() + { + + var result = await client.SyncRecursive(StartFrom:DateTime.Now); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + [Fact] + public async Task SyncTypeWithContentType() + { + + var result = await client.SyncRecursive(SyncType: Models.SyncType.entry_published, ContentTypeUid: "session"); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + [Fact] + public async Task SyncTypeWithStartFrom() + { + + var result = await client.SyncRecursive(SyncType: Models.SyncType.entry_published, StartFrom:DateTime.Now); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + + [Fact] + public async Task SyncPaginationToken() + { + + var result = await client.SyncPaginationToken("blt99c1e34e65f6cc0fd1d82b"); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + + [Fact] + public async Task SyncToken() + { + + var result = await client.SyncToken("blt08854bd48e43a740951809"); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } } } } diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index 20a255b..92609a1 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -4,11 +4,17 @@ using Contentstack.Core.Configuration; using Microsoft.Extensions.Options; using Contentstack.Core.Models; +using System.Threading.Tasks; +using Newtonsoft.Json; +using System.Linq; +using System.Net; +using Newtonsoft.Json.Linq; +using System.IO; namespace Contentstack.Core { /// - /// To fetch stack level information of your application from Built.io Contentstack server. + /// To fetch stack level information of your application from Contentstack server. /// public class ContentstackClient { @@ -22,6 +28,16 @@ internal string StackApiKey private ContentstackOptions _options; + internal string _SyncUrl + { + get + { + Config config = this.config; + return String.Format("{0}/stacks/sync", + config.BaseUrl); + } + } + /// /// Initializes a instance of the class. /// @@ -108,6 +124,60 @@ private ContentstackClient() { } #endregion #region Internal Constructor + internal static ContentstackError GetContentstackError(Exception ex) + { + Int32 errorCode = 0; + string errorMessage = string.Empty; + HttpStatusCode statusCode = HttpStatusCode.InternalServerError; + ContentstackError contentstackError = new ContentstackError(ex); + Dictionary errors = null; + //ContentstackError.OtherErrors errors = null; + + try + { + System.Net.WebException webEx = (System.Net.WebException)ex; + + using (var exResp = webEx.Response) + using (var stream = exResp.GetResponseStream()) + using (var reader = new StreamReader(stream)) + { + errorMessage = reader.ReadToEnd(); + JObject data = JObject.Parse(errorMessage.Replace("\r\n", "")); + //errorCode = ContentstackConvert.ToInt32(data.Property("error_code").Value); + //errorMessage = ContentstackConvert.ToString(data.Property("error_message").Value); + + JToken token = data["error_code"]; + if (token != null) + errorCode = token.Value(); + + token = data["error_message"]; + if (token != null) + errorMessage = token.Value(); + + token = data["errors"]; + if (token != null) + errors = token.ToObject>(); + + var response = exResp as HttpWebResponse; + if (response != null) + statusCode = response.StatusCode; + } + } + catch + { + errorMessage = ex.Message; + } + + contentstackError = new ContentstackError() + { + ErrorCode = errorCode, + ErrorMessage = errorMessage, + StatusCode = statusCode, + Errors = errors + }; + + return contentstackError; + } internal ContentstackClient(String stackApiKey) { this.StackApiKey = stackApiKey; @@ -296,7 +366,7 @@ public void RemoveHeader(string key) } /// - /// To set headers for Built.io Contentstack rest calls. + /// To set headers for Contentstack rest calls. /// /// header name. /// header value against given header name. @@ -318,41 +388,136 @@ public void SetHeader(string key, string value) } } + /// + /// Syncs the recursive. + /// + /// The recursive. + /// Sync type. + /// Content type uid. + /// Start from Date. + /// + /// + /// //"blt5d4sample2633b" is a dummy Stack API key + /// //"blt6d0240b5sample254090d" is dummy access token. + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// stack.SyncRecursive("SyncType"); + /// + /// + /// + public async Task SyncRecursive(SyncType SyncType = SyncType.All, string ContentTypeUid = null, DateTime? StartFrom = null) + { + SyncStack syncStack = await Sync(SyncType: SyncType, ContentTypeUid: ContentTypeUid, StartFrom: StartFrom); + syncStack = await SyncPageinationRecursive(syncStack); + return syncStack; + } - ///// - ///// set environment. - ///// - ///// environment uid/name - ///// true - If environment uid is present - ///// false - If environment uid is not present - ///// - ///// - ///// //"blt5d4sample2633b" is a dummy Stack API key - ///// //"blt6d0240b5sample254090d" is dummy access token. - ///// Stack stack = Contentstack.Stack("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); - ///// stack.SetEnvironment("stag", false); - ///// - ///// - //public void SetEnvironment(string environment, bool isEnvironmentUid) - //{ - // if (!string.IsNullOrEmpty(environment)) - // { - // if (isEnvironmentUid) - // { - // RemoveHeader("environment"); - // SetHeader("environment_uid", environment); - // } - // else - // { - // RemoveHeader("environment_uid"); - // SetHeader("environment", environment); - // } - // } - //} + /// + /// Syncs the recursive with language. + /// + /// The recursive with language. + /// Sync type. + /// Content type uid. + /// Start from Date. + /// Lang. + /// + /// + /// //"blt5d4sample2633b" is a dummy Stack API key + /// //"blt6d0240b5sample254090d" is dummy access token. + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// stack.SyncRecursiveLanguage("SyncType", "Language"); + /// + /// + /// + public async Task SyncRecursiveLanguage(Language Lang, SyncType SyncType = SyncType.All, string ContentTypeUid = null, DateTime? StartFrom = null) + { + SyncStack syncStack = await SyncLanguage(Lang: Lang, SyncType: SyncType, ContentTypeUid: ContentTypeUid, StartFrom: StartFrom); + syncStack = await SyncPageinationRecursive(syncStack); + return syncStack; + } + /// + /// Syncs the pagination token. + /// + /// The pagination token. + /// Pagination token. + /// + /// + /// //"blt5d4sample2633b" is a dummy Stack API key + /// //"blt6d0240b5sample254090d" is dummy access token. + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// stack.SyncPaginationTokenn("blt123343"); + /// + /// + + public async Task SyncPaginationToken(string paginationToken) + { + return await GetResultAsync(PaginationToken: paginationToken); + } + + /// + /// Syncs the token. + /// + /// The token. + /// Sync token. + /// + /// + /// //"blt5d4sample2633b" is a dummy Stack API key + /// //"blt6d0240b5sample254090d" is dummy access token. + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// stack.SyncToken("blt123343"); + /// + /// + public async Task SyncToken(string SyncToken) + { + return await GetResultAsync(SyncToken: SyncToken); + } #endregion #region Private Functions + + private async Task SyncPageinationRecursive(SyncStack syncStack) + { + while (syncStack.pagination_token != null) + { + SyncStack newSyncStack = await SyncPaginationToken(syncStack.pagination_token); + syncStack.items = syncStack.items.Concat(newSyncStack.items); + syncStack.pagination_token = newSyncStack.pagination_token; + syncStack.skip = newSyncStack.skip; + syncStack.total_count = newSyncStack.total_count; + syncStack.sync_token = newSyncStack.sync_token; + } + return syncStack; + } + + private async Task Sync(SyncType SyncType = SyncType.All, string ContentTypeUid = null, DateTime? StartFrom = null) + { + return await GetResultAsync(Init: "true", ContentTypeUid: ContentTypeUid, StartFrom: StartFrom); + } + + + private async Task SyncLanguage(Language Lang, SyncType SyncType = SyncType.All, string ContentTypeUid = null, DateTime? StartFrom = null) + { + return await GetResultAsync(Init: "true", ContentTypeUid: ContentTypeUid, StartFrom: StartFrom, Lang: GetLocaleCode(Lang)); + } + + //GetLanguage code + private string GetLocaleCode(Language language) + { + string localeCode = null; + try + { + int localeValue = (int)language; + LanguageCode[] languageCodeValues = Enum.GetValues(typeof(LanguageCode)).Cast().ToArray(); + localeCode = languageCodeValues[localeValue].ToString(); + localeCode = localeCode.Replace("_", "-"); + } + catch (Exception e) + { + throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + } + return localeCode; + } + private Dictionary GetHeader() { @@ -360,6 +525,50 @@ private Dictionary GetHeader() return mainHeader; } + + + private async Task GetResultAsync(string Init = "false", string ContentTypeUid = null, DateTime? StartFrom = null, string SyncToken = null, string PaginationToken = null, string Lang = null) + { + //mainJson = null; + Dictionary mainJson = new Dictionary(); + if (Init != "false") + { + mainJson.Add("init", "true"); + mainJson.Add("environment", config.Environment); + } + if (StartFrom != null) + { + DateTime startFrom = StartFrom ?? DateTime.MinValue; + mainJson.Add("start_from", startFrom.ToString("yyyy-MM-dd")); + } + if (SyncToken != null) + { + mainJson.Add("sync_token", SyncToken); + } + if (PaginationToken != null) + { + mainJson.Add("pagination_token", PaginationToken); + } + if (ContentTypeUid != null) + { + mainJson.Add("content_type_uid", ContentTypeUid); + } + if (Lang != null) + { + mainJson.Add("locale", Lang); + } + try + { + HTTPRequestHandler requestHandler = new HTTPRequestHandler(); + string js = await requestHandler.ProcessRequest(_SyncUrl, _LocalHeaders, mainJson); + SyncStack stackSyncOutput = JsonConvert.DeserializeObject(js); + return stackSyncOutput; + } + catch (Exception ex) + { + throw GetContentstackError(ex); + } + } #endregion } diff --git a/Contentstack.Core/Internals/ContentStackError.cs b/Contentstack.Core/Internals/ContentStackError.cs index 0b91971..e6ba381 100644 --- a/Contentstack.Core/Internals/ContentStackError.cs +++ b/Contentstack.Core/Internals/ContentStackError.cs @@ -16,7 +16,7 @@ public class ContentstackError : Exception #region Public Variables /// - /// This is http response status code of REST request to built.io. + /// This is http response status code of REST request to Contentstack. /// public HttpStatusCode StatusCode; diff --git a/Contentstack.Core/Internals/ContentstackConstants.cs b/Contentstack.Core/Internals/ContentstackConstants.cs index 25b3448..3ea6e95 100644 --- a/Contentstack.Core/Internals/ContentstackConstants.cs +++ b/Contentstack.Core/Internals/ContentstackConstants.cs @@ -6,8 +6,6 @@ namespace Contentstack.Core.Internals internal class ContentstackConstants { #region Private Variable - private string _Entries = "entries"; - private string _CacheFolderName; private string _ContentTypes = "content_types"; #endregion diff --git a/Contentstack.Core/Internals/ContentstackConvert.cs b/Contentstack.Core/Internals/ContentstackConvert.cs index 0d42809..13dc24f 100644 --- a/Contentstack.Core/Internals/ContentstackConvert.cs +++ b/Contentstack.Core/Internals/ContentstackConvert.cs @@ -326,7 +326,7 @@ public static bool GetResponseTimeFromCacheFile(string filePath, long responseTi } } - catch (Exception e) + catch { //showLog("appUtils", "------------getJsonFromFilec catch-|" + e.toString()); return false; diff --git a/Contentstack.Core/Internals/HTTPRequestHandler.cs b/Contentstack.Core/Internals/HTTPRequestHandler.cs index cfc3de6..41df875 100644 --- a/Contentstack.Core/Internals/HTTPRequestHandler.cs +++ b/Contentstack.Core/Internals/HTTPRequestHandler.cs @@ -44,7 +44,7 @@ public async Task ProcessRequest(string Url, Dictionary foreach (var header in Headers) { try { request.Headers[header.Key] = header.Value.ToString(); - } catch (Exception e) { + } catch { } } diff --git a/Contentstack.Core/Internals/StackOutput.cs b/Contentstack.Core/Internals/StackOutput.cs index 3c5ec26..7ae139b 100644 --- a/Contentstack.Core/Internals/StackOutput.cs +++ b/Contentstack.Core/Internals/StackOutput.cs @@ -15,13 +15,13 @@ internal class StackOutput private object _Output = default(object); private Dictionary _ObjectAttributes = new Dictionary(); private object _Schema = default(object); - private object _Stack = default(object); - private object _ContentType = default(object); - private object _ContentTypes = default(object); + //private object _Stack = default(object); + //private object _ContentType = default(object); + //private object _ContentTypes = default(object); private object _Object = default(object); private object _Objects = default(object); - private object _Asset = default(object); - private object _Assets = default(object); + //private object _Asset = default(object); + //private object _Assets = default(object); private object _Result = default(object); private object _ApplicationUser = default(object); private object _Tags = default(object); diff --git a/Contentstack.Core/Models/Asset.cs b/Contentstack.Core/Models/Asset.cs index ada2de0..dec69fe 100644 --- a/Contentstack.Core/Models/Asset.cs +++ b/Contentstack.Core/Models/Asset.cs @@ -15,8 +15,6 @@ internal class Asset private Dictionary _Headers = new Dictionary(); private string _jsonString = String.Empty; private string _Url = string.Empty; - private byte[] _Bytes = default(byte[]); - internal object _Result; #endregion public ContentstackClient Stack { @@ -159,7 +157,7 @@ internal Asset(ContentstackClient stack) #endregion /// - /// To set headers for Built.io Backend rest calls. + /// To set headers for Backend rest calls. /// /// header name. /// header value against given header name. @@ -228,7 +226,7 @@ public DateTime GetCreateAt() String value = _ObjectAttributes["created_at"].ToString(); return ContentstackConvert.ToDateTime(value); } - catch (Exception e) + catch { //CSAppUtils.showLog(TAG, "-----------------getCreateAtDate|" + e); } @@ -249,7 +247,7 @@ public DateTime GetUpdateAt() String value = _ObjectAttributes["updated_at"].ToString(); return ContentstackConvert.ToDateTime(value); } - catch (Exception e) + catch { //CSAppUtils.showLog(TAG, "-----------------getUpdateAtDate|" + e); } @@ -270,7 +268,7 @@ public DateTime GetDeleteAt() String value = _ObjectAttributes["deleted_at"].ToString(); return ContentstackConvert.ToDateTime(value); } - catch (Exception e) + catch { // CSAppUtils.showLog(TAG, "-----------------getDeleteAt|" + e); } diff --git a/Contentstack.Core/Models/AssetLibrary.cs b/Contentstack.Core/Models/AssetLibrary.cs index ebbe15d..ed41c82 100644 --- a/Contentstack.Core/Models/AssetLibrary.cs +++ b/Contentstack.Core/Models/AssetLibrary.cs @@ -9,7 +9,7 @@ public class AssetLibrary #region Private Variables - private CachePolicy _CachePolicy; + //private CachePolicy _CachePolicy; private Dictionary _PostParams; #endregion diff --git a/Contentstack.Core/Models/ContentType.cs b/Contentstack.Core/Models/ContentType.cs index db28de7..e35b495 100644 --- a/Contentstack.Core/Models/ContentType.cs +++ b/Contentstack.Core/Models/ContentType.cs @@ -54,7 +54,7 @@ internal void SetStackInstance(ContentstackClient stack) #region Public Functions /// - /// To set headers for Built.io Contentstack rest calls. + /// To set headers for Contentstack rest calls. /// /// header name. /// header value against given header name. diff --git a/Contentstack.Core/Models/Entry.cs b/Contentstack.Core/Models/Entry.cs index fbbbed0..07efdf5 100755 --- a/Contentstack.Core/Models/Entry.cs +++ b/Contentstack.Core/Models/Entry.cs @@ -621,7 +621,7 @@ public List GetMultipleHTMLText(string markdownKey) } return result; } - catch (Exception ex) + catch { } } @@ -711,7 +711,7 @@ public Object Get(String key) else return null; } - catch (Exception e) + catch { //CSAppUtils.showLog(TAG, "-----------------getUpdateAtDate|" + e); } @@ -742,7 +742,7 @@ public DateTime GetCreateAt() String value = _ObjectAttributes["created_at"].ToString(); return ContentstackConvert.ToDateTime(value); } - catch (Exception e) + catch { //CSAppUtils.showLog(TAG, "-----------------getCreateAtDate|" + e); } @@ -823,7 +823,7 @@ public DateTime GetUpdateAt() String value = _ObjectAttributes["updated_at"].ToString(); return ContentstackConvert.ToDateTime(value); } - catch (Exception e) + catch { //CSAppUtils.showLog(TAG, "-----------------getUpdateAtDate|" + e); } @@ -904,7 +904,7 @@ public DateTime GetDeleteAt() String value = _ObjectAttributes["deleted_at"].ToString(); return ContentstackConvert.ToDateTime(value); } - catch (Exception e) + catch { // CSAppUtils.showLog(TAG, "-----------------getDeleteAt|" + e); } @@ -1028,7 +1028,7 @@ public Entry Except(String[] fieldUid) } } - catch (Exception e) + catch { //CSAppUtils.showLog(TAG, "--include Reference-catch|" + e); } @@ -1062,7 +1062,7 @@ public Entry IncludeReference(String referenceField) UrlQueries.Add("include[]", referenceField); } return this; - } catch (Exception e) { + } catch { //CSAppUtils.showLog(TAG, "--include Reference-catch|" + e); } @@ -1096,7 +1096,7 @@ public Entry IncludeReference(String[] referenceFields) } return this; } - catch (Exception e) + catch { //CSAppUtils.showLog(TAG, "--include Reference-catch|" + e); } @@ -1254,7 +1254,7 @@ public Entry Only(String[] fieldUid) UrlQueries.Add("only[BASE][]", fieldUid); } } - catch (Exception e) + catch { //CSAppUtils.showLog(TAG, "--include Reference-catch|" + e); } diff --git a/Contentstack.Core/Models/Query.cs b/Contentstack.Core/Models/Query.cs index 340da2b..9d2df98 100644 --- a/Contentstack.Core/Models/Query.cs +++ b/Contentstack.Core/Models/Query.cs @@ -1247,7 +1247,7 @@ public Query Only(String[] fieldUid) { { UrlQueries.Add("only[BASE][]", fieldUid); } - } catch (Exception e) { + } catch { //CSAppUtils.showLog(TAG, "--include Reference-catch|" + e); } @@ -1279,7 +1279,7 @@ public Query Except(String[] fieldUids) { if (fieldUids != null && fieldUids.Length > 0) { UrlQueries.Add("except[BASE][]", fieldUids); } - } catch (Exception e) { + } catch { //CSAppUtils.showLog(TAG, "--include Reference-catch|" + e); } return this; @@ -1868,16 +1868,6 @@ private Task GetOutputAsync(StackOutput output) } } #endregion - - - } - - class QueryModel { - public string uid { get; set; } - } - class QueryModel2 - { - public QueryModel[] entries; } } diff --git a/Contentstack.Core/Models/SyncStack.cs b/Contentstack.Core/Models/SyncStack.cs index 9ddcee6..61b2cad 100755 --- a/Contentstack.Core/Models/SyncStack.cs +++ b/Contentstack.Core/Models/SyncStack.cs @@ -2,20 +2,35 @@ using System.Collections.Generic; namespace Contentstack.Core.Models -{ +{ + /// + /// Represents the result of a sync operation. + /// public class SyncStack { + /// + /// Readonly property contains all the Contents + /// public IEnumerable items { get; set; } - + /// + /// Readonly property to check skip count + /// public int skip { get; set; } - + /// + /// Readonly property to check limit + /// public int limit { get; set; } - + /// + /// Readonly property to check totalCount + /// public int total_count { get; set; } - + /// + /// Readonly property to delta sync. + /// public string sync_token { get; set; } - - public string pagination_token { get; set; } - + /// + /// Readonly property for paginating sync + /// + public string pagination_token { get; set;} } } \ No newline at end of file diff --git a/Contentstack.Core/Models/SyncType.cs b/Contentstack.Core/Models/SyncType.cs index 39b730a..e7970f3 100644 --- a/Contentstack.Core/Models/SyncType.cs +++ b/Contentstack.Core/Models/SyncType.cs @@ -1,10 +1,46 @@ using System; namespace Contentstack.Core.Models { - public class SyncType + /// + /// The different types of items you can request a sync for. + /// + public enum SyncType { - public SyncType() - { - } + /// + /// Every type of item. + /// + All, + + /// + /// Only Asset Published. + /// + asset_published, + + /// + /// Only Entry Published. + /// + entry_published, + + /// + /// Only Asset Unpublished. + /// + asset_unpublished, + + /// + /// Only Asset Deleted. + /// + asset_deleted, + + /// + /// Only Entry Deleted. + /// + entry_deleted, + + /// + /// Only Deleted Content Type. + /// + content_type_deleted + } + } diff --git a/Contentstack.Core/Models/Untitled.html b/Contentstack.Core/Models/Untitled.html deleted file mode 100644 index 2a87f72..0000000 --- a/Contentstack.Core/Models/Untitled.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - Download - - - diff --git a/docfx_project/Template/styles/main.css b/docfx_project/Template/styles/main.css new file mode 100644 index 0000000..688095a --- /dev/null +++ b/docfx_project/Template/styles/main.css @@ -0,0 +1,75 @@ + +/* Custom Navbar + ------------------------------------------------------- */ +.navbar-inverse { + background-color: #ffffff; + opacity: 0.95; + border-color: #ffffff; +} +.navbar-inverse .navbar-brand { + color: #ffffff; +} +.navbar-inverse .navbar-brand:hover, +.navbar-inverse .navbar-brand:focus { + color: #ecdbff; +} +.navbar-inverse .navbar-text { + color: #ffffff; +} +.navbar-inverse .navbar-nav > li > a { + color: #000000; +} +.navbar-inverse .navbar-nav > li > a:hover, +.navbar-inverse .navbar-nav > li > a:focus { + color: #000000; +} +.navbar-inverse .navbar-nav > .active > a, +.navbar-inverse .navbar-nav > .active > a:hover, +.navbar-inverse .navbar-nav > .active > a:focus { + color: #000000; + background-color: #ffffff; +} +.navbar-inverse .navbar-nav > .open > a, +.navbar-inverse .navbar-nav > .open > a:hover, +.navbar-inverse .navbar-nav > .open > a:focus { + color: #000000; + background-color: #ffffff; +} +.navbar-inverse .navbar-toggle { + border-color: #ffffff; +} +.navbar-inverse .navbar-toggle:hover, +.navbar-inverse .navbar-toggle:focus { + background-color: #ffffff; +} +.navbar-inverse .navbar-toggle .icon-bar { + background-color: #ffffff; +} +.navbar-inverse .navbar-collapse, +.navbar-inverse .navbar-form { + border: none; +} +.navbar-inverse .navbar-link { + color: #ffffff; +} +.navbar-inverse .navbar-link:hover { + color: #ecdbff; +} +svg:hover path { + fill: #444444; +} +@media (max-width: 767px) { + .navbar-inverse .navbar-nav .open .dropdown-menu > li > a { + color: #ffffff; + } + .navbar-inverse .navbar-nav .open .dropdown-menu > li > a:hover, + .navbar-inverse .navbar-nav .open .dropdown-menu > li > a:focus { + color: #ecdbff; + } + .navbar-inverse .navbar-nav .open .dropdown-menu > .active > a, + .navbar-inverse .navbar-nav .open .dropdown-menu > .active > a:hover, + .navbar-inverse .navbar-nav .open .dropdown-menu > .active > a:focus { + color: #ecdbff; + background-color: #ffffff; + } +} \ No newline at end of file diff --git a/docfx_project/api/index.md b/docfx_project/api/index.md new file mode 100644 index 0000000..5e4a298 --- /dev/null +++ b/docfx_project/api/index.md @@ -0,0 +1,54 @@ + +# Contentstack - .Net SDK + +.NET SDK for Contentstack's Content Delivery API + +Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/). + +For more details about the namespaces and classes navigate menu to left. + +## Prerequisites + +To get started with C#, you will need: + +.net platform, IDE (Visual Studio) and NuGet. + +## SDK installation and setup + +The .Net SDK provided by contentstack.io is available for Xamarin, Windows Phone and legacy .Net applications. You can integrate contentstack with your application by following these steps. + +Open the terminal and install the contentstack module via 'Package Manager' command + +And via ‘.Net CLI’ + +To use the module in your application, you need to first Add Namespace to your class + +## Initialize SDK + +You will need to specify the API key, Access token, and Environment Name of your stack to initialize the SDK: + +or: + +Once you have initialized the SDK, you can start getting content in your app. + +## Basic Queries + +### Get a Single Entry + +To retrieve a single entry from a content type, use the code snippet given below: + +### Get Multiple Entries + +To retrieve multiple entries of a particular content type, use the code snippet given below: + +## Example + +To help you get started, we have created a sample console application that is powered by Contentstack .NET SDK. Click on the link below to read the tutorial of the app. + +[.NET News Console App](https://contentstack.com/docs/example-apps/build-a-news-app-using-contentstack-dot-net-sdk) + +## Helpful Links + +- [Contentstack Website](https://www.contentstack.com/) +- [Official Documentation](https://contentstack.com/docs) +- [Content Delivery API Docs](https://contentstack.com/docs/apis/content-delivery-api/) diff --git a/docfx_project/api/toc.yml b/docfx_project/api/toc.yml new file mode 100644 index 0000000..b73a62e --- /dev/null +++ b/docfx_project/api/toc.yml @@ -0,0 +1,31 @@ +### YamlMime:TableOfContent +- uid: Contentstack.AspNetCore + name: Contentstack.AspNetCore + items: + - uid: Contentstack.AspNetCore.IServiceCollectionExtensions + name: IServiceCollectionExtensions +- uid: Contentstack.Core + name: Contentstack.Core + items: + - uid: Contentstack.Core.ContentstackClient + name: ContentstackClient +- uid: Contentstack.Core.Internals + name: Contentstack.Core.Internals + items: + - uid: Contentstack.Core.Internals.CachePolicy + name: CachePolicy + - uid: Contentstack.Core.Internals.Language + name: Language +- uid: Contentstack.Core.Models + name: Contentstack.Core.Models + items: + - uid: Contentstack.Core.Models.ContentType + name: ContentType + - uid: Contentstack.Core.Models.Entry + name: Entry + - uid: Contentstack.Core.Models.Query + name: Query + - uid: Contentstack.Core.Models.SyncStack + name: SyncStack + - uid: Contentstack.Core.Models.SyncType + name: SyncType diff --git a/docfx_project/docfx.json b/docfx_project/docfx.json new file mode 100644 index 0000000..bf4b7dc --- /dev/null +++ b/docfx_project/docfx.json @@ -0,0 +1,68 @@ +{ + "metadata": [ + { + "src": [ + { + "files": [ + "src/**.csproj" + ] + } + ], + "dest": "api", + "disableGitFeatures": false, + "disableDefaultFilter": false, + "filter": "filterRules.yml" + + } + ], + "build": { + "content": [ + { + "files": [ + "toc.yml", + "index.md", + "api/**.yml", + "api/index.md" + ] + } + ], + "resource": [ + { + "files": [ + "images/**" + ] + } + ], + "overwrite": [ + { + "files": [ + "apidoc/**.md" + ], + "exclude": [ + "obj/**", + "_site/**" + ] + } + ], + "globalMetadata": { + "_appTitle": "Contentstack - .NET SDK Documentation", + "_appLogoPath": "images/logo.svg", + "_appFaviconPath": "images/favicon.ico", + "_appFooter": "Copyright © 2012-2019 Contentstack. All Rights Reserved", + "_enableSearch": "true" + }, + "dest": "_site", + "globalMetadataFiles": [], + "fileMetadataFiles": [], + "template": [ + "default", + "Template" + ], + "postProcessors": [], + "markdownEngineName": "markdig", + "noLangKeyword": false, + "keepFileLink": false, + "cleanupCacheHistory": false, + "disableGitFeatures": false + } +} \ No newline at end of file diff --git a/docfx_project/filterRules.yml b/docfx_project/filterRules.yml new file mode 100644 index 0000000..7ec1f19 --- /dev/null +++ b/docfx_project/filterRules.yml @@ -0,0 +1,24 @@ +apiRules: +- exclude: + uidRegex: ^Contentstack\.Core\.Tests +- exclude: + uidRegex: ^Contentstack\.Core\.Internals\.ResponseType + type: Class +- exclude: + uidRegex: ^Contentstack\.Core\.Internals\.OrderBy + type: Class +- exclude: + uidRegex: ^Contentstack\.Core\.Internals\.NetworkStatus + type: Class +- exclude: + uidRegex: ^Contentstack\.Core\.Internals\.HttpMethods + type: Class +- exclude: + uidRegex: ^Contentstack\.Core\.Internals\.ContentstackError + type: Class +- exclude: + uidRegex: ^Contentstack\.Core\.Configuration + type: Class +- exclude: + uidRegex: ^Contentstack\.Core\.Models\.AssetLibrary + type: Class \ No newline at end of file diff --git a/docfx_project/images/favicon.ico b/docfx_project/images/favicon.ico new file mode 100755 index 0000000000000000000000000000000000000000..a1c0f9fa72c068d7f4477460a10df3e81cefeed2 GIT binary patch literal 32038 zcmeI5e~1=E7{^yiL=G`I4iPytL`+2TkPs75(<>xILfn@);))0pkqC(p5rjBIA|xUr zBH{?4I4q8ch!7F~kO&cp5b2LYBtpa)M8rR$uFtdgzIXes`|i%n&hDMQd+>F4XP=)l z&pbOjGw&J%^MWUXr=AMR+GeT`zAeZ&435n}?dE&{^qRR3C!9){+A0zYs)o+z85 z3DvF0zJ}Vy{nIIUgR(;@<eO4p88tPOEhT!jke{mZcdVYfcQ|LZR!GSnk);YWfsgFBJ>m-BkLU3fxgP|RlSLqTW+m7TT6yL~l)EU1{S~pX zn|X-|a-G_r4;}Sq-*tsv@}8c|1O4}$Z`~pfz5B3%{+$PH+}~a7#6RiZlAlen+eJ?& z9`t?$a@%2sMonMWTy_t5<+xN3=?vUJe5B(^sjpbwf}1G;uup6eFZ#6o`Sj4 z2kr^@2aP{W*)iCn>+oYiwTy-12IAF8;Ypdy}%Uo%c{* zeL0fzS5ilr*Vw+%tNo##DAV3F*-am$9em*FG#zPW=#%+m<{&ihz1EPq3*n#7{H&{t zG`(BWY)vae_ZDoBd1i;_PBa&{30|2GbD5Xxr1S4IThq$0eFwT-?HB#6c8doE@B4ea-&k36ILX-jY8XOU%Ke?RN+h2J-*^P@m= z{!%akP8Wp8Semq-GKo>q;RDec9J1v7vDZ;%=DJdf{S)YswI&Zxe<5cHkeG3mcOBmT zq@A6vp>^p;Sv=Bbj}(w=HGhJhzk%@hz-{F8lIJ9cX(ySCDdDpjm+@TH>pUUK&&XN` z);h{u4WIEo9%v{mkMGWeyeAx4`0yfb^PhWCL0-y85{WEl6TU0D(%bS zC-(PY|6z_i6N*5;!Q8F){U|nV5vRo`>F3LVjBjiqe6!lO(f=H{2h!psuj~PBxiMZJ zRiC4O2exB}ll|hKw>`lwzN3Et6sUha;G(zYsn_`H80Z`WQ~QDBH&OCeAFHkh*{8J~ zoB*wTS^>XlP5#v}+&PBpx~c1?j)6J`e8vD{Re5JQ!?>GuC|}So`LwZ2S@^sg{6ih& zy&KuwKUSvAK4sVbNAGL5X#cw&@s`gvDq9wQZv@-?Ao{jPrTewYuAgp_&s-d9!O?FM z&k+ya!J73i$UOjz*Pg1Zf9#?!C|PT?$@jLjQm=Eek6@R~A9l0B|1ZF{SHQt?prr55>Kt?2-}*fJeTuds9@G$VF;Y7C9>82{5B!&X8@~g? z{#}U9c%Nof^@QK6z#rB4udY|+m#H57uCo2Fnc7tq9sbLHheKerRD}8~%@l>gCpVt(^1yOW(a3ivPm zvy)tx^83y9ezyCDv*7_MR5%oqs{hT#Q7-?GV^SbF~*2%{6Fq|)QyZo zUMdf2RjUpe@2@XUj~+z6)qXW>=>g-wZLhZ3-0qK4@y_?YLM{3JZb`rg^%b&>_pd@L z{$BttdEAue%9Q_eZ~mw0zs#AL`r<-2hy9P{WInKj%mBet*YaNT&v|qaYjbP;yY^rI zNgdoNAB;hwwZ7>0V-mBTbgJ9P8ji=b%{ex$W&E|dbi}@~!|!beyy=tQ)$mPP8=q_1 znKcONPR1U$X^-shHW$6$P{+{Y{G2MQ&9KQOm%H#p`M)ebT;w;L2-{i@DgdZ5M{#XLWkv(VEo*17n|D!Hpqh%kr zqQ6{b8y1m`-!lJI$^1_dJImtjcK_x7o1qT&0@nEQ{=XpC`|j`TWwm=P*ZlcHY{1FCqxJ8q{czP+`yZ_g(>Rf&T%;B+B#v literal 0 HcmV?d00001 diff --git a/docfx_project/images/logo.svg b/docfx_project/images/logo.svg new file mode 100755 index 0000000..280c8cc --- /dev/null +++ b/docfx_project/images/logo.svg @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docfx_project/index.md b/docfx_project/index.md new file mode 100644 index 0000000..5e4a298 --- /dev/null +++ b/docfx_project/index.md @@ -0,0 +1,54 @@ + +# Contentstack - .Net SDK + +.NET SDK for Contentstack's Content Delivery API + +Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/). + +For more details about the namespaces and classes navigate menu to left. + +## Prerequisites + +To get started with C#, you will need: + +.net platform, IDE (Visual Studio) and NuGet. + +## SDK installation and setup + +The .Net SDK provided by contentstack.io is available for Xamarin, Windows Phone and legacy .Net applications. You can integrate contentstack with your application by following these steps. + +Open the terminal and install the contentstack module via 'Package Manager' command + +And via ‘.Net CLI’ + +To use the module in your application, you need to first Add Namespace to your class + +## Initialize SDK + +You will need to specify the API key, Access token, and Environment Name of your stack to initialize the SDK: + +or: + +Once you have initialized the SDK, you can start getting content in your app. + +## Basic Queries + +### Get a Single Entry + +To retrieve a single entry from a content type, use the code snippet given below: + +### Get Multiple Entries + +To retrieve multiple entries of a particular content type, use the code snippet given below: + +## Example + +To help you get started, we have created a sample console application that is powered by Contentstack .NET SDK. Click on the link below to read the tutorial of the app. + +[.NET News Console App](https://contentstack.com/docs/example-apps/build-a-news-app-using-contentstack-dot-net-sdk) + +## Helpful Links + +- [Contentstack Website](https://www.contentstack.com/) +- [Official Documentation](https://contentstack.com/docs) +- [Content Delivery API Docs](https://contentstack.com/docs/apis/content-delivery-api/) diff --git a/docfx_project/toc.yml b/docfx_project/toc.yml new file mode 100644 index 0000000..5990d63 --- /dev/null +++ b/docfx_project/toc.yml @@ -0,0 +1,3 @@ +- name: Api Documentation + href: api/ + homepage: api/index.md \ No newline at end of file From ffb258f91214d1dbdd26af50f3fe80e74ca0082f Mon Sep 17 00:00:00 2001 From: Uttam K Ukkoji Date: Thu, 11 Apr 2019 11:48:54 +0530 Subject: [PATCH 06/13] Contenttype Schema Fetch test class --- Contentstack.Core.Tests/ContentTypeTest.cs | 50 ++++++++++++++++++++++ Contentstack.Core.Tests/EntryTest.cs | 31 -------------- 2 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 Contentstack.Core.Tests/ContentTypeTest.cs diff --git a/Contentstack.Core.Tests/ContentTypeTest.cs b/Contentstack.Core.Tests/ContentTypeTest.cs new file mode 100644 index 0000000..f8d3dbc --- /dev/null +++ b/Contentstack.Core.Tests/ContentTypeTest.cs @@ -0,0 +1,50 @@ +using System; +using Xunit; +using Contentstack.Core.Models; +using System.Threading.Tasks; +using Contentstack.Core.Configuration; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using System.Collections; + +namespace Contentstack.Core.Tests +{ + public class ContentTypeTest + + { + ContentstackClient client = StackConfig.GetStack(); + String source = "source"; + + [Fact] + public async Task FetchContenTypeSchema() + { + ContentType contenttype = client.ContentType(source); + var result = await contenttype.Fetch(); + if (result == null) + { + Assert.False(true, "contenttype.FetchSchema() is not match with expected result."); + } + else + { + Assert.True(true); + } + } + + [Fact] + public async Task GetContentTypes() + { + var result = await client.getContentTypes(); + + if (result == null) + { + Assert.False(true, "client.getContentTypes is not match with expected result."); + } + else + { + Assert.True(true); + + } + } + } +} diff --git a/Contentstack.Core.Tests/EntryTest.cs b/Contentstack.Core.Tests/EntryTest.cs index 0ec85f0..dc7f89d 100644 --- a/Contentstack.Core.Tests/EntryTest.cs +++ b/Contentstack.Core.Tests/EntryTest.cs @@ -34,37 +34,6 @@ public async Task FetchByUid() { } } - [Fact] - public async Task GetContentTypes() - { - var result = await client.getContentTypes(); - - if (result == null) - { - Assert.False(true, "client.getContentTypes is not match with expected result."); - } - else - { - Assert.True(true); - - } - } - - [Fact] - public async Task FetchContenTypeSchema() - { - ContentType contenttype = client.ContentType(source); - var result = await contenttype.Fetch(); - if (result == null) - { - Assert.False(true, "contenttype.FetchSchema() is not match with expected result."); - } - else - { - Assert.True(true); - } - } - [Fact] public async Task IncludeReference() { ContentType contenttype = client.ContentType(source); From 8bc7dae9eb6015bdfd786a2cdf040501ee91519b Mon Sep 17 00:00:00 2001 From: Uttam K Ukkoji Date: Thu, 11 Apr 2019 12:03:12 +0530 Subject: [PATCH 07/13] Conflict resolved --- Contentstack.Core/ContentstackClient.cs | 89 +++---------------------- 1 file changed, 10 insertions(+), 79 deletions(-) diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index c70e329..f4da0ae 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -4,14 +4,6 @@ using Contentstack.Core.Configuration; using Microsoft.Extensions.Options; using Contentstack.Core.Models; -<<<<<<< HEAD -using System.Threading.Tasks; -using Newtonsoft.Json; -using System.Linq; -using System.Net; -using Newtonsoft.Json.Linq; -using System.IO; -======= using Newtonsoft.Json.Linq; using Newtonsoft.Json; using System.Linq; @@ -19,7 +11,6 @@ using System.Net; using System.IO; using System.Collections; ->>>>>>> ffb258f91214d1dbdd26af50f3fe80e74ca0082f namespace Contentstack.Core { @@ -36,31 +27,27 @@ internal string StackApiKey set; } private ContentstackOptions _options; -<<<<<<< HEAD internal string _SyncUrl -======= - private Dictionary UrlQueries = new Dictionary(); - private Dictionary _Headers = new Dictionary(); - private string _Url ->>>>>>> ffb258f91214d1dbdd26af50f3fe80e74ca0082f - { + { get { Config config = this.config; -<<<<<<< HEAD return String.Format("{0}/stacks/sync", config.BaseUrl); } } - -======= + private Dictionary UrlQueries = new Dictionary(); + private Dictionary _Headers = new Dictionary(); + private string _Url + { + get { return String.Format("{0}/content_types/", config.BaseUrl); } } private Dictionary _StackHeaders = new Dictionary(); ->>>>>>> ffb258f91214d1dbdd26af50f3fe80e74ca0082f + /// /// Initializes a instance of the class. /// @@ -100,62 +87,6 @@ public ContentstackClient(IOptions options) } - - internal static ContentstackError GetContentstackError(Exception ex) - { - Int32 errorCode = 0; - string errorMessage = string.Empty; - HttpStatusCode statusCode = HttpStatusCode.InternalServerError; - ContentstackError contentstackError = new ContentstackError(ex); - Dictionary errors = null; - //ContentstackError.OtherErrors errors = null; - - try - { - System.Net.WebException webEx = (System.Net.WebException)ex; - - using (var exResp = webEx.Response) - using (var stream = exResp.GetResponseStream()) - using (var reader = new StreamReader(stream)) - { - errorMessage = reader.ReadToEnd(); - JObject data = JObject.Parse(errorMessage.Replace("\r\n", "")); - //errorCode = ContentstackConvert.ToInt32(data.Property("error_code").Value); - //errorMessage = ContentstackConvert.ToString(data.Property("error_message").Value); - - JToken token = data["error_code"]; - if (token != null) - errorCode = token.Value(); - - token = data["error_message"]; - if (token != null) - errorMessage = token.Value(); - - token = data["errors"]; - if (token != null) - errors = token.ToObject>(); - - var response = exResp as HttpWebResponse; - if (response != null) - statusCode = response.StatusCode; - } - } - catch - { - errorMessage = ex.Message; - } - - contentstackError = new ContentstackError() - { - ErrorCode = errorCode, - ErrorMessage = errorMessage, - StatusCode = statusCode, - Errors = errors - }; - - return contentstackError; - } - public ContentstackClient(ContentstackOptions options) : this(new OptionsWrapper(options)) { @@ -603,7 +534,7 @@ public async Task SyncToken(string SyncToken) #region Private Functions -<<<<<<< HEAD + private async Task SyncPageinationRecursive(SyncStack syncStack) { while (syncStack.pagination_token != null) @@ -645,7 +576,8 @@ private string GetLocaleCode(Language language) throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); } return localeCode; -======= + } + private Dictionary GetHeader(Dictionary localHeader) { Dictionary mainHeader = _StackHeaders; @@ -683,7 +615,6 @@ private Dictionary GetHeader(Dictionary localHea { return _StackHeaders; } ->>>>>>> ffb258f91214d1dbdd26af50f3fe80e74ca0082f } private Dictionary GetHeader() From 4db3b188f416b5c140c1fe9cd8d182c77f3996a4 Mon Sep 17 00:00:00 2001 From: Uttam K Ukkoji Date: Thu, 11 Apr 2019 12:47:53 +0530 Subject: [PATCH 08/13] Content type fetch schema --- Contentstack.Core/ContentstackClient.cs | 11 +++++++++++ Contentstack.Core/Models/ContentType.cs | 11 ++++++++++- README.md | 6 +++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index f4da0ae..d35e210 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -205,6 +205,17 @@ internal void SetConfig(Config cnfig) #endregion #region Public Functions + /// + /// This method fetchs information of a all content types. + /// + /// + /// + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// ContentType contentType = stack.ContentType("contentType_name"); + /// var result = await contenttype.Fetch(); + /// + /// + /// The List of content types schema. public async Task getContentTypes() { Dictionary headers = GetHeader(_LocalHeaders); diff --git a/Contentstack.Core/Models/ContentType.cs b/Contentstack.Core/Models/ContentType.cs index aaf930a..d7d62f0 100644 --- a/Contentstack.Core/Models/ContentType.cs +++ b/Contentstack.Core/Models/ContentType.cs @@ -128,7 +128,16 @@ internal void SetStackInstance(ContentstackClient stack) #endregion #region Public Functions - + /// + /// This method fetchs information of a specific content type. + /// + /// + /// + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// var result = await client.getContentTypes(); + /// + /// + /// The Content-Type Schema Object. public async TaskFetch() { Dictionary headers = GetHeader(_Headers); diff --git a/README.md b/README.md index c506e3f..ef7fe02 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/) +[![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/) # Contentstack dotnet .NET SDK for Contentstack's Content Delivery API @@ -104,10 +104,10 @@ To help you get started, we have created a sample application that is powered by ### The MIT License (MIT) -Copyright © 2012-2018 [Contentstack](https://www.contentstack.com/). All Rights Reserved +Copyright © 2012-2019 [Contentstack](https://www.contentstack.com/). All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From 470e05093840eccecb68edf512c8d3ada3295b94 Mon Sep 17 00:00:00 2001 From: Uttam K Ukkoji Date: Thu, 11 Apr 2019 13:04:09 +0530 Subject: [PATCH 09/13] Content Type Fetch Schema --- Contentstack.Core.Tests/ContentTypeTest.cs | 2 +- Contentstack.Core/ContentstackClient.cs | 5 ++--- Contentstack.Core/Models/ContentType.cs | 9 +++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Contentstack.Core.Tests/ContentTypeTest.cs b/Contentstack.Core.Tests/ContentTypeTest.cs index f8d3dbc..31e6603 100644 --- a/Contentstack.Core.Tests/ContentTypeTest.cs +++ b/Contentstack.Core.Tests/ContentTypeTest.cs @@ -34,7 +34,7 @@ public async Task FetchContenTypeSchema() [Fact] public async Task GetContentTypes() { - var result = await client.getContentTypes(); + var result = await client.GetContentTypes(); if (result == null) { diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index d35e210..c9e4612 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -211,12 +211,11 @@ internal void SetConfig(Config cnfig) /// /// /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); - /// ContentType contentType = stack.ContentType("contentType_name"); - /// var result = await contenttype.Fetch(); + /// ContentType contentType = stack.GetContentTypes(); /// /// /// The List of content types schema. - public async Task getContentTypes() + public async Task GetContentTypes() { Dictionary headers = GetHeader(_LocalHeaders); Dictionary headerAll = new Dictionary(); diff --git a/Contentstack.Core/Models/ContentType.cs b/Contentstack.Core/Models/ContentType.cs index d7d62f0..f898b27 100644 --- a/Contentstack.Core/Models/ContentType.cs +++ b/Contentstack.Core/Models/ContentType.cs @@ -124,17 +124,18 @@ internal void SetStackInstance(ContentstackClient stack) { this.StackInstance = stack; this._StackHeaders = stack._LocalHeaders; - } + } #endregion - + #region Public Functions /// /// This method fetchs information of a specific content type. /// /// /// - /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); - /// var result = await client.getContentTypes(); + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// ContentType contenttype = stack.ContentType("contentType_name"); + /// var result = await contenttype.Fetch(); /// /// /// The Content-Type Schema Object. From de8b41b72b2fb9e97016fa16f3e37f4aa02b5a9d Mon Sep 17 00:00:00 2001 From: Uttam K Ukkoji Date: Thu, 11 Apr 2019 13:06:49 +0530 Subject: [PATCH 10/13] git ingnore file updated --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2bdf631..0c85ec1 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,3 @@ packages/ *.config *.nupkg *.nuspec -Contentstack.core/docfx_project/* From 70aabb5f3347491f6693c4b5adeef56f3f967900 Mon Sep 17 00:00:00 2001 From: Uttam K Ukkoji Date: Thu, 11 Apr 2019 15:24:15 +0530 Subject: [PATCH 11/13] LICENSE file added, Contentstack user-agent changed --- CHANGELOG.md | 23 +++++++++++++++++++ .../Contentstack.AspNetCore.csproj | 6 ++++- .../Contentstack.Core.Tests.csproj | 2 +- Contentstack.Core/Contentstack.Core.csproj | 14 ++++++++--- .../Internals/HTTPRequestHandler.cs | 2 +- Contentstack.Net.sln | 2 +- LICENSE | 21 +++++++++++++++++ README.md | 10 -------- docfx_project/docfx.json | 2 +- 9 files changed, 64 insertions(+), 18 deletions(-) create mode 100755 CHANGELOG.md create mode 100644 LICENSE diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100755 index 0000000..33115b9 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,23 @@ +### Version: 1.1.0 +#### Date: Apr-12-2019 + +##### New Features: +- ContentstackClient + - added method 'GetContentTypes' + - added method 'SyncRecursive' + - added method 'SyncRecursiveLanguage' + - added method 'SyncPaginationToken' + - added method 'SyncToken' + +- CotentType + - added method 'Fetch' + + ### Version: 1.0.6 + #### Date: Apr-12-2019 + +Localization support for Query and Entry is added. + +### Version: 1.0.0 +#### Date: Apr-12-2019 + +- Introduce ContentStack SDK for DOTNET. diff --git a/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj b/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj index 33352ab..a5ea355 100644 --- a/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj +++ b/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj @@ -6,9 +6,13 @@ contentstack.aspnetcore Contentstack Contentstack - 0.0.1 + 1.1.0 1.0.0 Main release + Copyright (c) 2012-2019 Contentstack (http://app.contentstack.com). All Rights Reserved + + https://github.com/contentstack/contentstack-dotnet + v1.0.0 diff --git a/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj b/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj index c087835..dd80891 100644 --- a/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj +++ b/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj @@ -4,7 +4,7 @@ netcoreapp2.0 false - 0.0.1 + 1.1.0 diff --git a/Contentstack.Core/Contentstack.Core.csproj b/Contentstack.Core/Contentstack.Core.csproj index b42e6b0..7bfccc3 100644 --- a/Contentstack.Core/Contentstack.Core.csproj +++ b/Contentstack.Core/Contentstack.Core.csproj @@ -5,10 +5,17 @@ contentstack.csharp Contentstack .NET SDK for the Contentstack Content Delivery API. - 1.0.6 + 1.1.0 Contentstack - Localization support for Query and Entry is added. - 0.0.1 + Fetching Content-Type schema +Stack Sync implemented + 1.1.0 + Copyright © 2012-2019 Contentstack. All Rights Reserved + + true + true + https://github.com/contentstack/contentstack-dotnet + v1.1.0 @@ -40,6 +47,7 @@ + diff --git a/Contentstack.Core/Internals/HTTPRequestHandler.cs b/Contentstack.Core/Internals/HTTPRequestHandler.cs index 41df875..f636209 100644 --- a/Contentstack.Core/Internals/HTTPRequestHandler.cs +++ b/Contentstack.Core/Internals/HTTPRequestHandler.cs @@ -38,7 +38,7 @@ public async Task ProcessRequest(string Url, Dictionary var request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; request.ContentType = "application/json"; - request.Headers["user-agent"]="DOTNET 1.0.0"; + request.Headers["user-agent"]="DOTNET 1.1.0"; if (Headers != default(IDictionary)) { foreach (var header in Headers) { diff --git a/Contentstack.Net.sln b/Contentstack.Net.sln index dd07403..b6da882 100644 --- a/Contentstack.Net.sln +++ b/Contentstack.Net.sln @@ -132,6 +132,6 @@ Global $0.XmlFormattingPolicy = $9 $9.scope = application/xml $0.StandardHeader = $10 - version = 0.0.1 + version = 1.1.0 EndGlobalSection EndGlobal diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5180831 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2012-2019 Contentstack (http://app.contentstack.com). All Rights Reserved + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index ef7fe02..c00d11f 100755 --- a/README.md +++ b/README.md @@ -101,13 +101,3 @@ To help you get started, we have created a sample application that is powered by - [Contentstack Website](https://www.contentstack.com) - [Official Documentation](https://contentstack.com/docs) - [Content Delivery API Docs](https://contentstack.com/docs/apis/content-delivery-api/) - -### The MIT License (MIT) - -Copyright © 2012-2019 [Contentstack](https://www.contentstack.com/). All Rights Reserved - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/docfx_project/docfx.json b/docfx_project/docfx.json index bf4b7dc..c58b504 100644 --- a/docfx_project/docfx.json +++ b/docfx_project/docfx.json @@ -48,7 +48,7 @@ "_appTitle": "Contentstack - .NET SDK Documentation", "_appLogoPath": "images/logo.svg", "_appFaviconPath": "images/favicon.ico", - "_appFooter": "Copyright © 2012-2019 Contentstack. All Rights Reserved", + "_appFooter": "Copyright © 2012-2019 Contentstack. All Rights Reserved", "_enableSearch": "true" }, "dest": "_site", From 188e81f46ede6949cf81655091e8cfd6c0bda35f Mon Sep 17 00:00:00 2001 From: Uttam K Ukkoji Date: Thu, 11 Apr 2019 15:51:28 +0530 Subject: [PATCH 12/13] Project setting update --- Contentstack.Core/Contentstack.Core.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Contentstack.Core/Contentstack.Core.csproj b/Contentstack.Core/Contentstack.Core.csproj index 7bfccc3..3b71851 100644 --- a/Contentstack.Core/Contentstack.Core.csproj +++ b/Contentstack.Core/Contentstack.Core.csproj @@ -13,9 +13,9 @@ Stack Sync implemented Copyright © 2012-2019 Contentstack. All Rights Reserved true - true https://github.com/contentstack/contentstack-dotnet v1.1.0 + https://github.com/contentstack/contentstack-dotnet/blob/master/LICENSE From 4e5fefedef836a5fa179f49c54c457764c8c919f Mon Sep 17 00:00:00 2001 From: Uttam K Ukkoji Date: Fri, 12 Apr 2019 12:40:09 +0530 Subject: [PATCH 13/13] Project file updated --- Contentstack.Core/Contentstack.Core.csproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/Contentstack.Core/Contentstack.Core.csproj b/Contentstack.Core/Contentstack.Core.csproj index 3b71851..0847152 100644 --- a/Contentstack.Core/Contentstack.Core.csproj +++ b/Contentstack.Core/Contentstack.Core.csproj @@ -13,9 +13,7 @@ Stack Sync implemented Copyright © 2012-2019 Contentstack. All Rights Reserved true - https://github.com/contentstack/contentstack-dotnet v1.1.0 - https://github.com/contentstack/contentstack-dotnet/blob/master/LICENSE