Skip to content

Commit 7498881

Browse files
authored
Merge pull request #46 from contentstack/feat/DX-745-variants-implementation
feat: ✨ add variant method implementation on Entry and Query
2 parents 8e83c50 + ed664a1 commit 7498881

File tree

3 files changed

+115
-17
lines changed

3 files changed

+115
-17
lines changed

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ fileignoreconfig:
1010
- filename: Contentstack.Core/Models/Asset.cs
1111
checksum: 98b819cb9b1e6a9a9e5394ac23c07bc642a41c0c7512d169afc63afe3baa6fb3
1212
- filename: Contentstack.Core/Models/Query.cs
13-
checksum: 9237bb4d3e862fad7f3c6d9bad47873758a18617dc9c90d28015dcea267fcd9e
13+
checksum: ceea632e4ea870f35ad3bd313e9f8b4e5ec21aa86f006fca2e0a32945999ba67

Contentstack.Core/Models/Entry.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,56 @@ public void RemoveHeader(string key)
378378

379379
}
380380

381+
382+
383+
/// <summary>
384+
/// To set variants header using Entry instance.
385+
/// </summary>
386+
/// <param name="variant_header">Entry instance</param>
387+
/// <returns>Current instance of Entry, this will be useful for a chaining calls.</returns>
388+
/// <example>
389+
/// <code>
390+
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
391+
/// Entry csEntry = stack.ContentType(&quot;contentType_id&quot;).Entry(&quot;entry_uid&quot;);
392+
///
393+
/// csEntry.Variant("variant_entry_1");
394+
/// csEntry.Fetch&lt;Product&gt;().ContinueWith((entryResult) =&gt; {
395+
/// //Your callback code.
396+
/// //var result = entryResult.Result.GetMetadata();
397+
/// });
398+
/// </code>
399+
/// </example>
400+
public Entry Variant(string variant_header)
401+
{
402+
this.SetHeader("x-cs-variant-uid", variant_header);
403+
return this;
404+
}
405+
406+
407+
408+
/// <summary>
409+
/// To set multiple variants headers using Entry instance.
410+
/// </summary>
411+
/// <param name="variant_headers">Entry instance</param>
412+
/// <returns>Current instance of Entry, this will be useful for a chaining calls.</returns>
413+
/// <example>
414+
/// <code>
415+
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
416+
/// Entry csEntry = stack.ContentType(&quot;contentType_id&quot;).Query();
417+
///
418+
/// csEntry.Variant(new List<string> { "variant_entry_1", "variant_entry_2", "variant_entry_3" });
419+
/// csEntry.Fetch&lt;Product&gt;().ContinueWith((entryResult) =&gt; {
420+
/// //Your callback code.
421+
/// //var result = entryResult.Result.GetMetadata();
422+
/// });
423+
/// </code>
424+
/// </example>
425+
public Entry Variant(List<string> variant_headers)
426+
{
427+
this.SetHeader("x-cs-variant-uid", string.Join(",", variant_headers));
428+
return this;
429+
}
430+
381431
/// <summary>
382432
/// Get metadata of entry.
383433
/// </summary>

Contentstack.Core/Models/Query.cs

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,8 +1242,8 @@ public Query Only(String[] fieldUid)
12421242
}
12431243

12441244
return this;
1245-
}
1246-
1245+
}
1246+
12471247
/// <summary>
12481248
/// Specifies an array of only keys that would be included in the response.
12491249
/// </summary>
@@ -1266,14 +1266,14 @@ public Query IncludeOnlyReference(string[] keys, string referenceKey)
12661266
if (keys != null && keys.Length > 0)
12671267
{
12681268
var referenceKeys = new string[] { referenceKey };
1269-
if (UrlQueries.ContainsKey("include[]") == false)
1270-
{
1269+
if (UrlQueries.ContainsKey("include[]") == false)
1270+
{
12711271
UrlQueries.Add("include[]", referenceKeys);
1272-
1273-
}
1274-
if (UrlQueries.ContainsKey($"only[{ referenceKey}][]") == false)
1275-
{
1276-
UrlQueries.Add($"only[{referenceKey}][]", keys);
1272+
1273+
}
1274+
if (UrlQueries.ContainsKey($"only[{ referenceKey}][]") == false)
1275+
{
1276+
UrlQueries.Add($"only[{referenceKey}][]", keys);
12771277
}
12781278
}
12791279
return this;
@@ -1333,14 +1333,14 @@ public Query IncludeExceptReference(string[] keys, string referenceKey)
13331333
if (keys != null && keys.Length > 0)
13341334
{
13351335
var referenceKeys = new string[] { referenceKey };
1336-
if (UrlQueries.ContainsKey("include[]") == false)
1337-
{
1336+
if (UrlQueries.ContainsKey("include[]") == false)
1337+
{
13381338
UrlQueries.Add("include[]", referenceKeys);
1339-
1340-
}
1341-
if (UrlQueries.ContainsKey($"except[{ referenceKey}][]") == false)
1342-
{
1343-
UrlQueries.Add($"except[{referenceKey}][]", keys);
1339+
1340+
}
1341+
if (UrlQueries.ContainsKey($"except[{ referenceKey}][]") == false)
1342+
{
1343+
UrlQueries.Add($"except[{referenceKey}][]", keys);
13441344
}
13451345
}
13461346
return this;
@@ -1686,6 +1686,54 @@ public Query SetCachePolicy(CachePolicy cachePolicy)
16861686
return this;
16871687
}
16881688

1689+
1690+
1691+
/// <summary>
1692+
/// To set variants header using query instance.
1693+
/// </summary>
1694+
/// <param name="Variant">Query instance</param>
1695+
/// <returns>Current instance of Query, this will be useful for a chaining calls.</returns>
1696+
/// <example>
1697+
/// <code>
1698+
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
1699+
/// Query csQuery = stack.ContentType(&quot;contentType_id&quot;).Query();
1700+
///
1701+
/// csQuery.Variant("variant_entry_1");
1702+
/// csQuery.Find&lt;Product&gt;().ContinueWith((queryResult) =&gt; {
1703+
/// //Your callback code.
1704+
/// });
1705+
/// </code>
1706+
/// </example>
1707+
public Query Variant(string variant_header)
1708+
{
1709+
this.SetHeader("x-cs-variant-uid", variant_header);
1710+
return this;
1711+
}
1712+
1713+
1714+
1715+
/// <summary>
1716+
/// To set multiple variants headers using query instance.
1717+
/// </summary>
1718+
/// <param name="Variant">Query instance</param>
1719+
/// <returns>Current instance of Query, this will be useful for a chaining calls.</returns>
1720+
/// <example>
1721+
/// <code>
1722+
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
1723+
/// Query csQuery = stack.ContentType(&quot;contentType_id&quot;).Query();
1724+
///
1725+
/// csQuery.Variant(new List<string> { "variant_entry_1", "variant_entry_2", "variant_entry_3" });
1726+
/// csQuery.Find&lt;Product&gt;().ContinueWith((queryResult) =&gt; {
1727+
/// //Your callback code.
1728+
/// });
1729+
/// </code>
1730+
/// </example>
1731+
public Query Variant(List<string> variant_headers)
1732+
{
1733+
this.SetHeader("x-cs-variant-uid", string.Join(",", variant_headers));
1734+
return this;
1735+
}
1736+
16891737
/// <summary>
16901738
/// Execute a Query and Caches its result (Optional)
16911739
/// </summary>

0 commit comments

Comments
 (0)