-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from adzshaf/refactor/initialization-client
refactor: add multiple instance of endpoint
- Loading branch information
Showing
139 changed files
with
3,500 additions
and
1,645 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace Xendit.net.Model.Balance | ||
{ | ||
using System.Threading.Tasks; | ||
using Xendit.net.Enum; | ||
using Xendit.net.Struct; | ||
|
||
public class Balance | ||
{ | ||
/// <summary> | ||
/// Get balance from your account based on given account type. | ||
/// </summary> | ||
/// <param name="accountType">Selected balance type <see cref="BalanceAccountType"/>.</param> | ||
/// <param name="headers">Custom headers <see cref="HeaderParameter"/>. Use property based on <see href="https://developers.xendit.co/api-reference/#get-balance"/>.</param> | ||
/// <returns>A Task of <see cref="BalanceResponse"/>.</returns> | ||
public static async Task<BalanceResponse> Get(BalanceAccountType? accountType = null, HeaderParameter? headers = null) | ||
{ | ||
BalanceClient client = new BalanceClient(); | ||
return await client.Get(accountType, headers); | ||
} | ||
} | ||
} |
28 changes: 12 additions & 16 deletions
28
Xendit.net/Xendit.net/Model/Balance.cs → ...Xendit.net/Model/Balance/BalanceClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,36 @@ | ||
namespace Xendit.net.Model | ||
namespace Xendit.net.Model.Balance | ||
{ | ||
using System.Net.Http; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
using Xendit.net.Enum; | ||
using Xendit.net.Network; | ||
using Xendit.net.Struct; | ||
|
||
public class Balance | ||
public class BalanceClient : BaseClient | ||
{ | ||
[JsonPropertyName("balance")] | ||
public long Value { get; set; } | ||
public BalanceClient(string apiKey = null, INetworkClient requestClient = null, string baseUrl = null) | ||
: base(apiKey, requestClient, baseUrl) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Get balance from your account based on given account type. | ||
/// </summary> | ||
/// <param name="accountType">Selected balance type <see cref="BalanceAccountType"/>.</param> | ||
/// <param name="headers">Custom headers <see cref="HeaderParameter"/>. Use property based on <see href="https://developers.xendit.co/api-reference/#get-balance"/>.</param> | ||
/// <returns>A Task of <see cref="Balance"/>.</returns> | ||
public static async Task<Balance> Get(BalanceAccountType? accountType = null, HeaderParameter? headers = null) | ||
{ | ||
return await GetBalanceRequest(accountType, headers); | ||
} | ||
|
||
private static async Task<Balance> GetBalanceRequest(BalanceAccountType? accountType, HeaderParameter? headers) | ||
/// <returns>A Task of <see cref="BalanceResponse"/>.</returns> | ||
public async Task<BalanceResponse> Get(BalanceAccountType? accountType = null, HeaderParameter? headers = null) | ||
{ | ||
string url = string.Format("{0}{1}", XenditConfiguration.ApiUrl, "/balance"); | ||
|
||
string url = "/balance"; | ||
if (accountType != null) | ||
{ | ||
string accountTypeParam = JsonSerializer.Deserialize<string>(JsonSerializer.Serialize(accountType)); | ||
url = string.Format("{0}{1}{2}", url, "?account_type=", accountTypeParam); | ||
} | ||
|
||
var balance = await XenditConfiguration.RequestClient.Request<Balance>(HttpMethod.Get, headers, url); | ||
return balance; | ||
var client = this.requestClient ?? XenditConfiguration.RequestClient; | ||
return await client.Request<BalanceResponse>(HttpMethod.Get, url, this.ApiKey, this.BaseUrl, headers); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Xendit.net.Model.Balance | ||
{ | ||
using System.Text.Json.Serialization; | ||
|
||
public class BalanceResponse | ||
{ | ||
[JsonPropertyName("balance")] | ||
public long Balance { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
namespace Xendit.net.Model | ||
{ | ||
using Xendit.net.Network; | ||
|
||
public class BaseClient | ||
{ | ||
protected string apiKey; | ||
protected string baseUrl; | ||
protected INetworkClient requestClient; | ||
|
||
public BaseClient(string apiKey = null, INetworkClient requestClient = null, string baseUrl = null) | ||
{ | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
this.requestClient = requestClient; | ||
} | ||
|
||
public string ApiKey | ||
{ | ||
get => this.apiKey; | ||
set => this.apiKey = value; | ||
} | ||
|
||
public string BaseUrl | ||
{ | ||
get => this.baseUrl; | ||
set => this.baseUrl = value; | ||
} | ||
|
||
public INetworkClient RequestClient | ||
{ | ||
get => this.requestClient; | ||
set => this.requestClient = value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.