Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next: Region and Include Metadata Support Added #30

Merged
merged 6 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .github/workflows/sast-scan.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/sca-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
- name: Setup .NET Core @ Latest
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'
dotnet-version: "7.0.x"
- name: Run Dotnet Restore
run: |
dotnet restore
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/dotnet@master
uses: snyk/actions/dotnet@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
Expand Down
11 changes: 0 additions & 11 deletions .github/workflows/secrets-scan.yml

This file was deleted.

8 changes: 4 additions & 4 deletions Contentstack.AspNetCore/Contentstack.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<PackageId>contentstack.aspnetcore</PackageId>
<Authors>Contentstack</Authors>
<Owners>Contentstack</Owners>
<PackageVersion>2.10.0</PackageVersion>
<PackageVersion>2.11.0</PackageVersion>
<Description>Main release</Description>
<Copyright>Copyright (c) 2012-2023 Contentstack (http://app.contentstack.com). All Rights Reserved</Copyright>
<PackageProjectUrl>https://github.com/contentstack/contentstack-dotnet</PackageProjectUrl>
<PackageTags>v2.10.0</PackageTags>
<ReleaseVersion>2.10.0</ReleaseVersion>
<PackageTags>v2.11.0</PackageTags>
<ReleaseVersion>2.11.0</ReleaseVersion>
<Configurations>Release;Debug</Configurations>
</PropertyGroup>

Expand All @@ -29,6 +29,6 @@
<PackageReference Include="NuGet.Build.Packaging" Version="0.2.2"><PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="contentstack.csharp" Version="2.9.0" />
<PackageReference Include="contentstack.csharp" Version="2.10.0" />
</ItemGroup>
</Project>
7 changes: 2 additions & 5 deletions Contentstack.Core.Tests/AssetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
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;
using Newtonsoft.Json.Linq;
using Contentstack.Utils;
namespace Contentstack.Core.Tests
{
public class AssetTest
Expand Down Expand Up @@ -128,7 +124,8 @@ public async Task FetchAssetsIncludeRelativeURL()
[Fact]
public async Task FetchAssetCountAsync()
{
AssetLibrary assetLibrary = client.AssetLibrary().SetLocale("en-us");
AssetLibrary assetLibrary = client.AssetLibrary().
IncludeMetadata().SetLocale("en-us");
JObject jObject = await assetLibrary.Count();
if (jObject == null)
{
Expand Down
12 changes: 6 additions & 6 deletions Contentstack.Core.Tests/Contentstack.Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>

<IsPackable>false</IsPackable>
<ReleaseVersion>2.10.0</ReleaseVersion>
<ReleaseVersion>2.11.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion Contentstack.Core.Tests/EntryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task FetchByUid() {
ContentType contenttype = client.ContentType(source);
string uid = await GetUID("source1");
Entry sourceEntry = contenttype.Entry(uid);

sourceEntry.IncludeMetadata();
await sourceEntry.Fetch<Entry>().ContinueWith((t) =>
{
Entry result = t.Result;
Expand Down
1 change: 1 addition & 0 deletions Contentstack.Core.Tests/QueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public async Task FetchEntriesPublishFallback()
ContentstackCollection<Entry> entries = await client.ContentType(source).Query()
.SetLocale("ja-jp")
.IncludeFallback()
.IncludeMetadata()
.Find<Entry>();
;
Assert.True(entries.Items.Count() > 0);
Expand Down
1 change: 1 addition & 0 deletions Contentstack.Core.Tests/StackConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static ContentstackClient GetStack()
DeliveryToken = delivery_token,
Environment = environment,
Host = host,

};

ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper<Configuration.ContentstackOptions>(contentstackOptions));
Expand Down
4 changes: 2 additions & 2 deletions Contentstack.Core/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ internal string regionCode()
{
if (Region == ContentstackRegion.US) return "";
ContentstackRegionCode[] regionCodes = Enum.GetValues(typeof(ContentstackRegionCode)).Cast<ContentstackRegionCode>().ToArray();
return string.Format("{0}-", regionCodes[(int)Region].ToString());
return string.Format("{0}-", regionCodes[(int)Region].ToString().Replace("_", "-"));
}

internal string HostURL
{
get
{
if (Region == ContentstackRegion.EU)
if (Region == ContentstackRegion.EU || Region == ContentstackRegion.AZURE_EU || Region == ContentstackRegion.AZURE_NA)
return "cdn.contentstack.com";
return "cdn.contentstack.io";
}
Expand Down
10 changes: 5 additions & 5 deletions Contentstack.Core/Contentstack.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<PackageId>contentstack.csharp</PackageId>
<Authors>Contentstack</Authors>
<Description>.NET SDK for the Contentstack Content Delivery API.</Description>
<PackageVersion>2.10.0</PackageVersion>
<PackageVersion>2.11.0</PackageVersion>
<Owners>Contentstack</Owners>
<PackageReleaseNotes>Reference in entry Live preview support added</PackageReleaseNotes>
<Copyright>Copyright © 2012-2023 Contentstack. All Rights Reserved</Copyright>
<PackOnBuild>true</PackOnBuild>
<PackageTags>v2.10.0</PackageTags>
<PackageTags>v2.11.0</PackageTags>
<PackageProjectUrl>https://github.com/contentstack/contentstack-dotnet</PackageProjectUrl>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<ReleaseVersion>2.10.0</ReleaseVersion>
<ReleaseVersion>2.11.0</ReleaseVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -26,9 +26,9 @@
<AllowUnsafeBlocks></AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="Markdig" Version="0.31.0" />
<PackageReference Include="Markdig" Version="0.33.0" />
<PackageReference Include="contentstack.utils" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
Expand Down
18 changes: 16 additions & 2 deletions Contentstack.Core/Internals/ContentstackRegion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@ public enum ContentstackRegion
/// <summary>
/// To specify EU region.
/// </summary>
EU
EU,
/// <summary>
/// To specify EU region.
/// </summary>
AZURE_EU,

/// <summary>
/// To specify EU region.
/// </summary>
AZURE_NA
}


internal enum ContentstackRegionCode
{
us,

eu
eu,

azure_eu,

azure_na

}
}
2 changes: 1 addition & 1 deletion Contentstack.Core/Internals/HttpRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<string> ProcessRequest(string Url, Dictionary<string, object>
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET";
request.ContentType = "application/json";
request.Headers["x-user-agent"]="contentstack-dotnet/2.10.0";
request.Headers["x-user-agent"]="contentstack-dotnet/2.11.0";
if (Branch != null)
{
request.Headers["branch"] = Branch;
Expand Down
30 changes: 30 additions & 0 deletions Contentstack.Core/Models/Asset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,36 @@ public Asset includeFallback()
return this;
}



/// <summary>
/// This call includes metadata in the response.
/// </summary>
/// <returns>Current instance of Asset, 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;);
/// Asset asset = stack.Asset(&quot;asset_uid&quot;);
/// asset.IncludeMetadata();
/// asset.Fetch&lt;Product&gt;().ContinueWith((assetResult) =&gt; {
/// //Your callback code.
/// });
/// </code>
/// </example>
public Asset IncludeMetadata()
{
try
{
this.UrlQueries.Add("include_metadata", "true");
}
catch (Exception e)
{
throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e);
}
return this;
}


/// <summary>
/// Include branch for publish content.
/// </summary>
Expand Down
30 changes: 30 additions & 0 deletions Contentstack.Core/Models/AssetLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,36 @@ public void IncludeCount()
UrlQueries.Add("include_count", "true");
}




/// <summary>
/// This call includes metadata in the response.
/// </summary>
/// <returns>Current instance of AssetLibrary, 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;);
/// AssetLibrary assetLibrary = stack.AssetLibrary();
/// assetLibrary.IncludeMetadata();
/// ContentstackCollection&gt;Asset&lt; contentstackCollection = await assetLibrary.FetchAll();
/// </code>
/// </example>
public AssetLibrary IncludeMetadata()
{
try
{
UrlQueries.Add("include_metadata", "true");
}
catch (Exception e)
{
throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e);
}
return this;
}



/// <summary>
/// This method includes the relative url of assets.
/// </summary>
Expand Down
31 changes: 31 additions & 0 deletions Contentstack.Core/Models/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,37 @@ public Entry IncludeFallback()
return this;
}


/// <summary>
/// Include metadata includes metadata.
/// </summary>
/// <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 entry = stack.ContentType(&quot;contentType_id&quot;).Entry(&quot;entry_uid&quot;);
/// entry.IncludeMetadata();
/// entry.Fetch&lt;Product&gt;().ContinueWith((entryResult) =&gt; {
/// //Your Metadata code.
/// });
/// </code>
/// </example>
public Entry IncludeMetadata()
{
try
{
UrlQueries.Add("include_metadata", "true");
}
catch (Exception e)
{
throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e);
}
return this;
}




/// <summary>
/// Include branch for publish content.
/// </summary>
Expand Down
29 changes: 29 additions & 0 deletions Contentstack.Core/Models/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,35 @@ public Query IncludeCount()
return this;
}



/// <summary>
/// This call includes metadata in the response.
/// </summary>
/// <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.IncludeMetadata();
/// csQuery.Find&lt;Product&gt;().ContinueWith((queryResult) =&gt; {
/// //Your metadata code.
/// });
/// </code>
/// </example>
public Query IncludeMetadata()
{
try
{
UrlQueries.Add("include_metadata", "true");
}
catch (Exception e)
{
throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e);
}
return this;
}

/// <summary>
/// This method also includes owner information for all the entries returned in the response.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Contentstack.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ Global
$0.XmlFormattingPolicy = $9
$9.scope = application/xml
$0.StandardHeader = $10
version = 2.10.0
version = 2.11.0
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.1.404"
"version": "7.0.400"
}
}
Loading