Skip to content

Commit

Permalink
Add option for management client base url (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roblinde authored Oct 9, 2024
1 parent 60f9e57 commit 77b0a35
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
10 changes: 5 additions & 5 deletions Contentful.AspNetCore/Contentful.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Description>Official .NET SDK for the Contentful Content Delivery and Management API for ASP.NET core.</Description>
<PackageId>contentful.aspnetcore</PackageId>
<NeutralLanguage>en-US</NeutralLanguage>
<VersionPrefix>8.2.0</VersionPrefix>
<VersionPrefix>8.2.1</VersionPrefix>
<TargetFramework>netstandard2.0</TargetFramework>
<Authors>Contentful</Authors>
<Copyright>Contentful GmbH.</Copyright>
Expand All @@ -13,10 +13,10 @@
<PackageProjectUrl>https://github.com/contentful/contentful.net</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<Version>8.2.0</Version>
<AssemblyVersion>8.2.0.0</AssemblyVersion>
<Version>8.2.1</Version>
<AssemblyVersion>8.2.1.0</AssemblyVersion>
<RepositoryUrl>https://github.com/contentful/contentful.net</RepositoryUrl>
<FileVersion>8.2.0.0</FileVersion>
<FileVersion>8.2.1.0</FileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard1.5\Contentful.AspNetCore.xml</DocumentationFile>
Expand All @@ -25,7 +25,7 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="contentful.csharp" Version="8.2.0" />
<PackageReference Include="contentful.csharp" Version="8.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor" Version="2.2.0" />
Expand Down
31 changes: 31 additions & 0 deletions Contentful.Core.Tests/ContentfulManagementClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,37 @@ public async Task DeletingASpaceShouldCallCorrectUrl(string id)
Assert.Equal($"https://api.contentful.com/spaces/{id}", requestUrl);
}

[Fact]
public async Task UpdatingBaseUrlShouldCallCorrectUrl()
{
//Arrange

var client = new ContentfulManagementClient(_httpClient, new ContentfulOptions()
{
DeliveryApiKey = "123",
ManagementApiKey = "564",
SpaceId = "666",
UsePreviewApi = false,
ManagementBaseUrl = "https://apa.contentful.com/spaces/"
});
_handler.Response = new HttpResponseMessage();
var requestUrl = "";
var requestMethod = HttpMethod.Trace;
_handler.VerifyRequest = (HttpRequestMessage request) =>
{
requestMethod = request.Method;
requestUrl = request.RequestUri.ToString();
};


//Act
await client.DeleteSpace("123");

//Assert
Assert.Equal(HttpMethod.Delete, requestMethod);
Assert.Equal($"https://apa.contentful.com/spaces/123", requestUrl);
}

[Fact]
public async Task GetContentTypesShouldDeserializeCorrectly()
{
Expand Down
8 changes: 7 additions & 1 deletion Contentful.Core/Configuration/ContentfulOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,17 @@ public class ContentfulOptions
public string Environment { get; set; }

/// <summary>
/// Gets or sets the base URL for the Contentful API.
/// Gets or sets the base URL for the Contentful devliery API.
/// Default is "https://cdn.contentful.com/spaces/".
/// </summary>
public string BaseUrl { get; set; } = "https://cdn.contentful.com/spaces/";

/// <summary>
/// Gets or sets the base URL for the Contentful management API.
/// Default is "https://api.contentful.com/spaces/".
/// </summary>
public string ManagementBaseUrl { get; set; } = "https://api.contentful.com/spaces/";

/// <summary>
/// Whether to use HTTP compression for responses. Only disable if you are hosting in the same datacenter as contentful
/// Default is true
Expand Down
2 changes: 1 addition & 1 deletion Contentful.Core/Contentful.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PackageId>contentful.csharp</PackageId>
<AssemblyTitle>contentful.net</AssemblyTitle>
<NeutralLanguage>en-US</NeutralLanguage>
<VersionPrefix>8.2.0</VersionPrefix>
<VersionPrefix>8.2.1</VersionPrefix>
<TargetFramework>netstandard2.0</TargetFramework>
<Authors>Contentful</Authors>
<Copyright>Contentful GmbH.</Copyright>
Expand Down
2 changes: 2 additions & 0 deletions Contentful.Core/ContentfulManagementClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public ContentfulManagementClient(HttpClient httpClient, ContentfulOptions optio
throw new ArgumentException("The ContentfulOptions cannot be null.", nameof(options));
}

_baseUrl = options.ManagementBaseUrl ?? _baseUrl;

SerializerSettings.Converters.Add(new ExtensionJsonConverter());
SerializerSettings.Converters.Add(new ContentJsonConverter());
}
Expand Down

0 comments on commit 77b0a35

Please sign in to comment.