Skip to content

Commit

Permalink
optional prod url has been added when init sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
mElzantot committed Oct 2, 2024
1 parent 06402f5 commit d902dc7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
11 changes: 4 additions & 7 deletions src/Balance/SubsBase.SDK.Balance/BalanceSdk.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using SubsBase.Common.ApiClientHelper;
using SubsBase.SDK.Balance.Client;

Expand All @@ -17,13 +16,11 @@ public BalanceSdk(
)
{
_configuration = new BalanceConfiguration(publicKey, privateKey);
_configurationConstants = environment == Environment.Development
? new DevelopmentConstants(environmentBaseUrl)
: new ProductionConstants();
_configurationConstants = new ConfigurationConstants(environment, environmentBaseUrl);
}

public BalanceClient Balance => new BalanceClient(new ApiClient(new HttpClient(), _configurationConstants.BalanceUri), _configuration);
public BalanceMovementClient BalanceMovement => new BalanceMovementClient(new ApiClient(new HttpClient(), _configurationConstants.BalanceMovementUri), _configuration);
public OnHoldAmountClient OnHoldAmount => new OnHoldAmountClient(new ApiClient(new HttpClient(), _configurationConstants.OnHoldAmountUri), _configuration);
public BalanceClient Balance => new (new ApiClient(new HttpClient(), _configurationConstants.BalanceUri), _configuration);
public BalanceMovementClient BalanceMovement => new (new ApiClient(new HttpClient(), _configurationConstants.BalanceMovementUri), _configuration);
public OnHoldAmountClient OnHoldAmount => new (new ApiClient(new HttpClient(), _configurationConstants.OnHoldAmountUri), _configuration);

}
24 changes: 7 additions & 17 deletions src/Balance/SubsBase.SDK.Balance/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,19 @@ public class IConfigurationConstants
public string OnHoldAmountUri;
}

public class DevelopmentConstants : IConfigurationConstants
public class ConfigurationConstants : IConfigurationConstants
{
private const string DefaultBaseUrl = "http://api.dev.subsbase.xyz";
private const string DevBaseUrl = "http://api.dev.subsbase.xyz";
private const string ProdBaseUrl = "http://api.subsbase.io";

public DevelopmentConstants(string? baseUrl = null)
public ConfigurationConstants(Environment environment, string? baseUrl = null)
{
if (string.IsNullOrEmpty(baseUrl))
{
baseUrl = DefaultBaseUrl;
}
baseUrl = !string.IsNullOrEmpty(baseUrl) ? baseUrl.TrimEnd().Trim('/') :
environment == Environment.Development ? DevBaseUrl : ProdBaseUrl;

BalanceUri = $"{baseUrl}/balance/";
BalanceMovementUri = $"{baseUrl}/balance/balance-movement/";
OnHoldAmountUri = $"{baseUrl}/balance/on-hold-amount/";
}
}

public class ProductionConstants : IConfigurationConstants
{
public ProductionConstants()
{
BalanceUri = "http://api.subsbase.io/balance/";
BalanceMovementUri = "http://api.subsbase.io/balance/balance-movement/";
OnHoldAmountUri = "http://api.subsbase.io/balance/on-hold-amount/";
}
}
}

0 comments on commit d902dc7

Please sign in to comment.