Skip to content

Commit 609172a

Browse files
committed
Fixed PR comments
1 parent 4c11b72 commit 609172a

6 files changed

Lines changed: 94 additions & 97 deletions

File tree

Contentstack.Core.Tests/LivePreviewTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public async Task setQueryWithLivePreview()
8282
};
8383
Lpclient.LivePreviewQueryAsync(query);
8484
var LPConfig = Lpclient.GetLivePreviewConfig();
85-
Assert.Equal(LPConfig.previewTimestamp, "preview_timestamp");
85+
Assert.Equal(LPConfig.PreviewTimestamp, "preview_timestamp");
8686
Assert.NotEmpty(LPConfig.PreviewToken);
8787
Assert.NotEmpty(LPConfig.PreviewToken);
8888
Assert.NotEmpty(LPConfig.Host);

Contentstack.Core/Configuration/LivePreviewConfig.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class LivePreviewConfig
1212
internal string ContentTypeUID { get; set; }
1313
internal string EntryUID { get; set; }
1414
internal JObject PreviewResponse { get; set; }
15-
public string releaseId {get; set;}
16-
public string previewTimestamp {get; set;}
15+
public string ReleaseId {get; set;}
16+
public string PreviewTimestamp {get; set;}
1717
}
1818
}

Contentstack.Core/ContentstackClient.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,13 @@ private async Task<JObject> GetLivePreviewData()
363363
throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig");
364364
}
365365

366-
if (!string.IsNullOrEmpty(this.LivePreviewConfig.releaseId))
366+
if (!string.IsNullOrEmpty(this.LivePreviewConfig.ReleaseId))
367367
{
368-
headerAll["release_id"] = this.LivePreviewConfig.releaseId;
368+
headerAll["release_id"] = this.LivePreviewConfig.ReleaseId;
369369
}
370-
if (!string.IsNullOrEmpty(this.LivePreviewConfig.previewTimestamp))
370+
if (!string.IsNullOrEmpty(this.LivePreviewConfig.PreviewTimestamp))
371371
{
372-
headerAll["preview_timestamp"] = this.LivePreviewConfig.previewTimestamp;
372+
headerAll["preview_timestamp"] = this.LivePreviewConfig.PreviewTimestamp;
373373
}
374374

375375
try
@@ -594,14 +594,14 @@ public async Task LivePreviewQueryAsync(Dictionary<string, string> query)
594594
this.LivePreviewConfig.LivePreview = hash;
595595
}
596596
if (query.Keys.Contains("release_id")) {
597-
string releaseId = null;
598-
query.TryGetValue("release_id", out releaseId);
599-
this.LivePreviewConfig.releaseId = releaseId;
597+
string ReleaseId = null;
598+
query.TryGetValue("release_id", out ReleaseId);
599+
this.LivePreviewConfig.ReleaseId = ReleaseId;
600600
}
601601
if (query.Keys.Contains("preview_timestamp")) {
602-
string previewTimestamp = null;
603-
query.TryGetValue("preview_timestamp", out previewTimestamp);
604-
this.LivePreviewConfig.previewTimestamp = previewTimestamp;
602+
string PreviewTimestamp = null;
603+
query.TryGetValue("preview_timestamp", out PreviewTimestamp);
604+
this.LivePreviewConfig.PreviewTimestamp = PreviewTimestamp;
605605
}
606606
this.LivePreviewConfig.PreviewResponse = await GetLivePreviewData();
607607
}

Contentstack.Core/Models/Asset.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ public string Url
139139
/// Uid of user who updated the file
140140
/// </summary>
141141
[JsonProperty(PropertyName = "updated_by")]
142-
public string UpdatedBy { get; set; }
143-
142+
public string UpdatedBy { get; set; }
143+
144144
/// <summary>
145145
/// Uid of user who updated the file
146146
/// </summary>
@@ -167,7 +167,7 @@ public string Url
167167
public Dictionary<string, object> Dimension { get; set; }
168168

169169
/// <summary>
170-
/// Dimension Object of the asset containing Height and width
170+
/// Dimension Object of the asset publish details
171171
/// </summary>
172172
[JsonProperty(PropertyName = "publish_details")]
173173
public Dictionary<string, object> PublishDetails { get; set; }

Contentstack.Core/Models/Entry.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,13 @@ private string _Url
107107
/// });
108108
/// </code>
109109
/// </example>
110-
public Dictionary<string, object> Metadata { get; set; }
111-
112-
public Dictionary<string, object> publish_details { get; set; }
110+
public Dictionary<string, object> Metadata { get; set; }
111+
112+
/// <summary>
113+
/// Dimension Object of the entries publish details
114+
/// </summary>
115+
[JsonProperty(PropertyName = "publish_details")]
116+
public Dictionary<string, object> PublishDetails { get; set; }
113117

114118
/// <summary>
115119
/// Set key/value attributes of an current entry instance.
@@ -1403,13 +1407,13 @@ public async Task<T> Fetch<T>()
14031407
throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig");
14041408
}
14051409

1406-
if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId))
1410+
if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.ReleaseId))
14071411
{
1408-
headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId;
1409-
}
1410-
if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp))
1412+
headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ReleaseId;
1413+
}
1414+
if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewTimestamp))
14111415
{
1412-
headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp;
1416+
headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewTimestamp;
14131417
}
14141418

14151419
isLivePreview = true;
@@ -1493,12 +1497,12 @@ internal void ParseObject(JObject jsonObj, string url = null)
14931497
this.jObject = jsonObj;
14941498
this._ObjectAttributes = jsonObj.ToObject<Dictionary<string, object>>();
14951499
if (_ObjectAttributes != null && _ObjectAttributes.ContainsKey("_metadata"))
1496-
{
1500+
{
14971501
var jObject = (Newtonsoft.Json.Linq.JObject)_ObjectAttributes["_metadata"];
14981502
var _metadataJSON = new Dictionary<string, object>();
1499-
foreach (var property in jObject.Properties())
1500-
{
1501-
_metadataJSON[property.Name] = property.Value.ToObject<object>();
1503+
foreach (var property in jObject.Properties())
1504+
{
1505+
_metadataJSON[property.Name] = property.Value.ToObject<object>();
15021506
}
15031507
List<string> iterator = _metadataJSON.Keys.ToList();
15041508
Metadata = new Dictionary<string, object>();

Contentstack.Core/Models/Query.cs

Lines changed: 62 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public class Query
1919

2020
internal Dictionary<string, object> _FormHeaders = new Dictionary<string, object>();
2121
private Dictionary<string, object> _Headers = new Dictionary<string, object>();
22-
private Dictionary<string, object> UrlQueries = new Dictionary<string, object>();
22+
private Dictionary<string, object> UrlQueries = new Dictionary<string, object>();
2323

2424
protected Dictionary<string, object> QueryValueJson = new Dictionary<string, object>();
25-
private string _ResultJson = string.Empty; private CachePolicy _CachePolicy;
25+
private string _ResultJson = string.Empty; private CachePolicy _CachePolicy;
2626
private ContentType ContentTypeInstance { get; set; }
2727
private ContentstackClient TaxonomyInstance { get; set; }
2828
protected virtual string _Url
@@ -54,11 +54,11 @@ protected virtual string _Url
5454
/// });
5555
/// </code>
5656
/// </example>
57-
public string ContentTypeId { get; set; }
58-
public ContentstackClient Stack { get; private set; }
59-
57+
public string ContentTypeId { get; set; }
58+
public ContentstackClient Stack { get; private set; }
59+
6060
#endregion
61-
61+
6262
#region Internal Constructors
6363
internal Query()
6464
{
@@ -67,7 +67,7 @@ internal Query()
6767
internal Query(string contentTypeName)
6868
{
6969
this.ContentTypeId = contentTypeName;
70-
}
70+
}
7171
internal Query(ContentstackClient Tax)
7272
{
7373
SetTaxonomyInstance(Tax);
@@ -136,13 +136,13 @@ internal void SetTaxonomyInstance(ContentstackClient Tax)
136136
{
137137
this.TaxonomyInstance = Tax;
138138
//SetLocale("en-us");
139-
}
140-
141-
139+
}
140+
141+
142142
#endregion
143-
143+
144144
#region Public Functions
145-
145+
146146
/// <summary>
147147
/// Set Language instance
148148
/// </summary>
@@ -1822,33 +1822,26 @@ public async Task<ContentstackCollection<T>> FindOne<T>()
18221822
private ContentstackCollection<T> parseJObject<T>(JObject jObject)
18231823
{
18241824

1825-
if(this.TaxonomyInstance!=null)
1826-
{
1827-
var entries = jObject.SelectToken("$.entries").ToObject<IEnumerable<T>>(this.TaxonomyInstance.Serializer);
1828-
var collection = jObject.ToObject<ContentstackCollection<T>>(this.TaxonomyInstance.Serializer);
1829-
foreach (var entry in entries)
1830-
{
1831-
if (entry.GetType() == typeof(Entry))
1832-
{
1833-
(entry as Entry).SetContentTypeInstance(this.ContentTypeInstance);
1834-
}
1835-
}
1836-
collection.Items = entries;
1837-
return collection;
1838-
1839-
} else
1840-
{
1841-
var entries = jObject.SelectToken("$.entries").ToObject<IEnumerable<T>>(this.ContentTypeInstance.StackInstance.Serializer);
1842-
var collection = jObject.ToObject<ContentstackCollection<T>>(this.ContentTypeInstance.StackInstance.Serializer);
1843-
foreach (var entry in entries)
1844-
{
1845-
if (entry.GetType() == typeof(Entry))
1846-
{
1847-
(entry as Entry).SetContentTypeInstance(this.ContentTypeInstance);
1848-
}
1849-
}
1850-
collection.Items = entries;
1851-
return collection;
1825+
if(this.TaxonomyInstance!=null)
1826+
{
1827+
var entries = jObject.SelectToken("$.entries").ToObject<IEnumerable<T>>(this.TaxonomyInstance.Serializer);
1828+
var collection = jObject.ToObject<ContentstackCollection<T>>(this.TaxonomyInstance.Serializer);
1829+
collection.Items = entries;
1830+
return collection;
1831+
1832+
} else
1833+
{
1834+
var entries = jObject.SelectToken("$.entries").ToObject<IEnumerable<T>>(this.ContentTypeInstance.StackInstance.Serializer);
1835+
var collection = jObject.ToObject<ContentstackCollection<T>>(this.ContentTypeInstance.StackInstance.Serializer);
1836+
foreach (var entry in entries)
1837+
{
1838+
if (entry.GetType() == typeof(Entry))
1839+
{
1840+
(entry as Entry).SetContentTypeInstance(this.ContentTypeInstance);
1841+
}
1842+
}
1843+
collection.Items = entries;
1844+
return collection;
18521845
}
18531846

18541847
}
@@ -1874,13 +1867,13 @@ private async Task<JObject> Exec()
18741867
throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig");
18751868
}
18761869

1877-
if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId))
1870+
if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.ReleaseId))
18781871
{
1879-
headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId;
1880-
}
1881-
if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp))
1872+
headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ReleaseId;
1873+
}
1874+
if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewTimestamp))
18821875
{
1883-
headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp;
1876+
headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewTimestamp;
18841877
}
18851878

18861879
isLivePreview = true;
@@ -1901,12 +1894,12 @@ private async Task<JObject> Exec()
19011894
}
19021895
}
19031896

1904-
if(this.TaxonomyInstance!=null && this.TaxonomyInstance._LocalHeaders!=null)
1905-
{
1897+
if(this.TaxonomyInstance!=null && this.TaxonomyInstance._LocalHeaders!=null)
1898+
{
19061899
foreach (var header in this.TaxonomyInstance._LocalHeaders)
19071900
{
19081901
headerAll.Add(header.Key, (string)header.Value);
1909-
}
1902+
}
19101903
}
19111904
if (!isLivePreview && headerAll.ContainsKey("preview_token"))
19121905
{
@@ -1921,13 +1914,13 @@ private async Task<JObject> Exec()
19211914
headerAll.Remove("preview_timestamp");
19221915
}
19231916

1924-
if(this.ContentTypeInstance!=null)
1925-
{
1926-
mainJson.Add("environment", this.ContentTypeInstance?.StackInstance.Config.Environment);
1917+
if(this.ContentTypeInstance!=null)
1918+
{
1919+
mainJson.Add("environment", this.ContentTypeInstance?.StackInstance.Config.Environment);
19271920
}
1928-
if (this.TaxonomyInstance!=null && this.TaxonomyInstance.Config.Environment != null)
1929-
{
1930-
mainJson.Add("environment", this.TaxonomyInstance?.Config.Environment);
1921+
else if (this.TaxonomyInstance!=null && this.TaxonomyInstance.Config.Environment != null)
1922+
{
1923+
mainJson.Add("environment", this.TaxonomyInstance?.Config.Environment);
19311924
}
19321925
if (QueryValueJson != null && QueryValueJson.Count > 0)
19331926
mainJson.Add("query", QueryValueJson);
@@ -1938,28 +1931,28 @@ private async Task<JObject> Exec()
19381931
}
19391932

19401933
try
1941-
{
1942-
if(this.TaxonomyInstance!=null)
1943-
{
1944-
HttpRequestHandler requestHandler = new HttpRequestHandler(this.TaxonomyInstance);
1945-
var branch = this.TaxonomyInstance.Config.Branch != null ? this.TaxonomyInstance.Config.Branch : "main";
1946-
var outputResult = await requestHandler.ProcessRequest(this._Url, headerAll, mainJson, Branch: branch, isLivePreview: isLivePreview, timeout: this.TaxonomyInstance.Config.Timeout);
1947-
return JObject.Parse(ContentstackConvert.ToString(outputResult, "{}"));
1948-
}
1949-
else
1950-
{
1951-
HttpRequestHandler requestHandler = new HttpRequestHandler(this.ContentTypeInstance.StackInstance);
1952-
var outputResult = await requestHandler.ProcessRequest(_Url, headerAll, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, isLivePreview: isLivePreview, timeout: this.ContentTypeInstance.StackInstance.Config.Timeout);
1953-
return JObject.Parse(ContentstackConvert.ToString(outputResult, "{}"));
1934+
{
1935+
if(this.TaxonomyInstance!=null)
1936+
{
1937+
HttpRequestHandler requestHandler = new HttpRequestHandler(this.TaxonomyInstance);
1938+
var branch = this.TaxonomyInstance.Config.Branch != null ? this.TaxonomyInstance.Config.Branch : "main";
1939+
var outputResult = await requestHandler.ProcessRequest(this._Url, headerAll, mainJson, Branch: branch, isLivePreview: isLivePreview, timeout: this.TaxonomyInstance.Config.Timeout);
1940+
return JObject.Parse(ContentstackConvert.ToString(outputResult, "{}"));
1941+
}
1942+
else
1943+
{
1944+
HttpRequestHandler requestHandler = new HttpRequestHandler(this.ContentTypeInstance.StackInstance);
1945+
var outputResult = await requestHandler.ProcessRequest(_Url, headerAll, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, isLivePreview: isLivePreview, timeout: this.ContentTypeInstance.StackInstance.Config.Timeout);
1946+
return JObject.Parse(ContentstackConvert.ToString(outputResult, "{}"));
19541947
}
19551948
}
19561949
catch (Exception ex)
19571950
{
19581951
throw GetContentstackError(ex);
19591952
}
1960-
}
1961-
1962-
1953+
}
1954+
1955+
19631956
#region Private Functions
19641957
private Dictionary<string, object> GetHeader(Dictionary<string, object> localHeader)
19651958
{

0 commit comments

Comments
 (0)