Skip to content

Commit

Permalink
[CC] Refatora código da conta
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelEstevamReis committed Dec 18, 2023
1 parent f3288e6 commit 2b2ace1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
17 changes: 5 additions & 12 deletions Sicoob.Conta/SicoobContaCorrente.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ public sealed class SicoobContaCorrente : Shared.Sicoob
// > APIs tipo "Swagger":
// https://developers.sicoob.com.br/#!/apis

private readonly int numeroContaCorrente;
private ClientInfo clientApi;

public Shared.Models.ConfiguracaoAPI ConfigApi { get; }

public SicoobContaCorrente(Shared.Models.ConfiguracaoAPI configApi, System.Security.Cryptography.X509Certificates.X509Certificate2? certificado = null)
public SicoobContaCorrente(Shared.Models.ConfiguracaoAPI configApi, int NumeroContaCorrente, System.Security.Cryptography.X509Certificates.X509Certificate2? certificado = null)
: base(configApi, certificado)
{
ConfigApi = configApi;
numeroContaCorrente = NumeroContaCorrente;
}

protected override void setupClients(HttpClientHandler handler)
Expand All @@ -44,24 +47,14 @@ protected override void atualizaClients(TokenResponse token)
/// O recurso de Saldo retorna o valor disponível atual e o limite de crédito (cheque especial) de uma conta corrente.
/// </summary>
public async Task<ResultadoResponse<SaldoResponse>> ObterSaldoAsync()
=> await ExecutaChamadaAsync(() => clientApi.GetAsync<ResultadoResponse<SaldoResponse>>("/conta-corrente/v2/saldo"));
/// <summary>
/// O recurso de Saldo retorna o valor disponível atual e o limite de crédito (cheque especial) de uma conta corrente.
/// </summary>
public async Task<ResultadoResponse<SaldoResponse>> ObterSaldoAsync(string numeroContaCorrente)
=> await ExecutaChamadaAsync(() => clientApi.GetAsync<ResultadoResponse<SaldoResponse>>("/conta-corrente/v2/saldo", new { numeroContaCorrente }));


/// <summary>
/// O recurso de Extrato retorna todas as transações ocorridas em uma conta corrente no devido mês e ano.
/// Há um limite de 3 meses
/// </summary>
public async Task<ResultadoResponse<ExtratoResponse>> ObterExtratoAsync(int mes, int ano)
=> await ExecutaChamadaAsync(() => clientApi.GetAsync<ResultadoResponse<ExtratoResponse>>($"/conta-corrente/v2/extrato/{mes}/{ano}"));
/// <summary>
/// O recurso de Extrato retorna todas as transações ocorridas em uma conta corrente no devido mês e ano.
/// Há um limite de 3 meses
/// </summary>
public async Task<ResultadoResponse<ExtratoResponse>> ObterExtratoAsync(int mes, int ano, string numeroContaCorrente)
=> await ExecutaChamadaAsync(() => clientApi.GetAsync<ResultadoResponse<ExtratoResponse>>($"/conta-corrente/v2/extrato/{mes}/{ano}", new { numeroContaCorrente }));

}
4 changes: 2 additions & 2 deletions Sicoob.Testes/TestesApiConta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public static async Task Run_ContaCorrente()
//};
//File.WriteAllText("config_CC.json", JsonConvert.SerializeObject(cfg));

var cCorrente = new SicoobContaCorrente(cfg);
var cCorrente = new SicoobContaCorrente(cfg, 00000);
await cCorrente.SetupAsync();

var extrato = await cCorrente.ObterExtratoAsync(12, 2023);
var saldo = await cCorrente.ObterSaldoAsync();
var extrato = await cCorrente.ObterExtratoAsync(12, 2022);
}
public static async Task Run_ContaPoupanca()
{
Expand Down

0 comments on commit 2b2ace1

Please sign in to comment.