Skip to content

Commit

Permalink
feat: ✨ add variant method implementation on Entry and Query
Browse files Browse the repository at this point in the history
  • Loading branch information
nadeem-cs committed Jul 12, 2024
1 parent b537bc9 commit 5f516d1
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ fileignoreconfig:
- filename: Contentstack.Core/Models/Asset.cs
checksum: 98b819cb9b1e6a9a9e5394ac23c07bc642a41c0c7512d169afc63afe3baa6fb3
- filename: Contentstack.Core/Models/Query.cs
checksum: 9237bb4d3e862fad7f3c6d9bad47873758a18617dc9c90d28015dcea267fcd9e
checksum: ceea632e4ea870f35ad3bd313e9f8b4e5ec21aa86f006fca2e0a32945999ba67
50 changes: 50 additions & 0 deletions Contentstack.Core/Models/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,56 @@ public void RemoveHeader(string key)

}



/// <summary>
/// To set variants header using Entry instance.
/// </summary>
/// <param name="variant_header">Entry instance</param>
/// <returns>Current instance of Entry, this will be useful for a chaining calls.</returns>
/// <example>
/// <code>
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
/// Entry csEntry = stack.ContentType(&quot;contentType_id&quot;).Entry(&quot;entry_uid&quot;);
///
/// csEntry.Variant("variant_entry_1");
/// csEntry.Fetch&lt;Product&gt;().ContinueWith((entryResult) =&gt; {
/// //Your callback code.
/// //var result = entryResult.Result.GetMetadata();
/// });
/// </code>
/// </example>
public Entry Variant(string variant_header)
{
this.SetHeader("x-cs-variant-uid", variant_header);
return this;
}



/// <summary>
/// To set multiple variants headers using Entry instance.
/// </summary>
/// <param name="variant_headers">Entry instance</param>
/// <returns>Current instance of Entry, this will be useful for a chaining calls.</returns>
/// <example>
/// <code>
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
/// Entry csEntry = stack.ContentType(&quot;contentType_id&quot;).Query();
///
/// csEntry.Variant(new List<string> { "variant_entry_1", "variant_entry_2", "variant_entry_3" });
/// csEntry.Fetch&lt;Product&gt;().ContinueWith((entryResult) =&gt; {
/// //Your callback code.
/// //var result = entryResult.Result.GetMetadata();
/// });
/// </code>
/// </example>
public Entry Variant(List<string> variant_headers)
{
this.SetHeader("x-cs-variant-uid", string.Join(",", variant_headers));
return this;
}

/// <summary>
/// Get metadata of entry.
/// </summary>
Expand Down
80 changes: 64 additions & 16 deletions Contentstack.Core/Models/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,8 @@ public Query Only(String[] fieldUid)
}

return this;
}

}

/// <summary>
/// Specifies an array of only keys that would be included in the response.
/// </summary>
Expand All @@ -1266,14 +1266,14 @@ public Query IncludeOnlyReference(string[] keys, string referenceKey)
if (keys != null && keys.Length > 0)
{
var referenceKeys = new string[] { referenceKey };
if (UrlQueries.ContainsKey("include[]") == false)
{
if (UrlQueries.ContainsKey("include[]") == false)
{
UrlQueries.Add("include[]", referenceKeys);

}
if (UrlQueries.ContainsKey($"only[{ referenceKey}][]") == false)
{
UrlQueries.Add($"only[{referenceKey}][]", keys);

}
if (UrlQueries.ContainsKey($"only[{ referenceKey}][]") == false)
{
UrlQueries.Add($"only[{referenceKey}][]", keys);
}
}
return this;
Expand Down Expand Up @@ -1333,14 +1333,14 @@ public Query IncludeExceptReference(string[] keys, string referenceKey)
if (keys != null && keys.Length > 0)
{
var referenceKeys = new string[] { referenceKey };
if (UrlQueries.ContainsKey("include[]") == false)
{
if (UrlQueries.ContainsKey("include[]") == false)
{
UrlQueries.Add("include[]", referenceKeys);

}
if (UrlQueries.ContainsKey($"except[{ referenceKey}][]") == false)
{
UrlQueries.Add($"except[{referenceKey}][]", keys);

}
if (UrlQueries.ContainsKey($"except[{ referenceKey}][]") == false)
{
UrlQueries.Add($"except[{referenceKey}][]", keys);
}
}
return this;
Expand Down Expand Up @@ -1686,6 +1686,54 @@ public Query SetCachePolicy(CachePolicy cachePolicy)
return this;
}



/// <summary>
/// To set variants header using query instance.
/// </summary>
/// <param name="Variant">Query instance</param>
/// <returns>Current instance of Query, this will be useful for a chaining calls.</returns>
/// <example>
/// <code>
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
/// Query csQuery = stack.ContentType(&quot;contentType_id&quot;).Query();
///
/// csQuery.Variant("variant_entry_1");
/// csQuery.Find&lt;Product&gt;().ContinueWith((queryResult) =&gt; {
/// //Your callback code.
/// });
/// </code>
/// </example>
public Query Variant(string variant_header)
{
this.SetHeader("x-cs-variant-uid", variant_header);
return this;
}



/// <summary>
/// To set multiple variants headers using query instance.
/// </summary>
/// <param name="Variant">Query instance</param>
/// <returns>Current instance of Query, this will be useful for a chaining calls.</returns>
/// <example>
/// <code>
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
/// Query csQuery = stack.ContentType(&quot;contentType_id&quot;).Query();
///
/// csQuery.Variant(new List<string> { "variant_entry_1", "variant_entry_2", "variant_entry_3" });
/// csQuery.Find&lt;Product&gt;().ContinueWith((queryResult) =&gt; {
/// //Your callback code.
/// });
/// </code>
/// </example>
public Query Variant(List<string> variant_headers)
{
this.SetHeader("x-cs-variant-uid", string.Join(",", variant_headers));
return this;
}

/// <summary>
/// Execute a Query and Caches its result (Optional)
/// </summary>
Expand Down

0 comments on commit 5f516d1

Please sign in to comment.