Skip to content

Commit

Permalink
Added China API region support
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnmbond committed Sep 18, 2024
1 parent 9f2b924 commit 8907985
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
15 changes: 15 additions & 0 deletions Meraki.Api/Data/ApiRegion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Meraki.Api.Data;
public enum ApiRegion
{
/// <summary>
/// The default region for the Meraki Dashboard API
/// This uses the "api.meraki.com" endpoint
/// </summary>
Default,

/// <summary>
/// The China region for the Meraki Dashboard API
/// This uses the "api.meraki.cn" endpoint
/// </summary>
China
}
11 changes: 8 additions & 3 deletions Meraki.Api/MerakiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public partial class MerakiClient : IDisposable
/// <summary>
/// A Meraki portal client
/// </summary>
/// <param name="options"></param>
/// <param name="logger"></param>
public MerakiClient(MerakiClientOptions options, ILogger? logger = default)
{
var apiClientVersion = new System.Version(ThisAssembly.AssemblyFileVersion);
Expand All @@ -34,7 +32,14 @@ public MerakiClient(MerakiClientOptions options, ILogger? logger = default)
_httpClientHandler = new AuthenticatedBackingOffHttpClientHandler(options ?? throw new ArgumentNullException(nameof(options)), this, _logger);
_httpClient = new HttpClient(_httpClientHandler)
{
BaseAddress = new Uri($"https://{options.ApiNode ?? "api"}.meraki.com/api/v1"),
BaseAddress = new Uri(
options.ApiRegion switch
{
ApiRegion.Default => $"https://{options.ApiNode ?? "api"}.meraki.com/api/v1",
ApiRegion.China => $"https://{options.ApiNode ?? "api"}.meraki.cn/api/v1",
_ => throw new ArgumentOutOfRangeException($"Unsupported API Region {options.ApiRegion}")
}
),
Timeout = TimeSpan.FromSeconds(options.HttpClientTimeoutSeconds)
};
_refitSettings = new RefitSettings
Expand Down
7 changes: 7 additions & 0 deletions Meraki.Api/MerakiClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
/// </summary>
public class MerakiClientOptions
{
/// <summary>
/// The API Region.
/// Defaults to "World", which is the default region for the Meraki Dashboard API.
/// Only change this if you are using the China API endpoint.
/// </summary>
public ApiRegion ApiRegion { get; set; } = ApiRegion.Default;

/// <summary>
/// The API Node (e.g. "n72").
/// This is optional, but highly recommended as directly addressing the correct instance will reduce propagation delays.
Expand Down

0 comments on commit 8907985

Please sign in to comment.