-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
515 additions
and
30 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
41 changes: 41 additions & 0 deletions
41
BoletoSimplesApiClient.IntegratedTests/EventApiIntegratedTest.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using NUnit.Framework; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace BoletoSimplesApiClient.IntegratedTests | ||
{ | ||
[TestFixture] | ||
public class EventApiIntegratedTest : IntegratedTestBase | ||
{ | ||
[Test] | ||
public async Task Get_Event_information_with_success() | ||
{ | ||
// Arrange | ||
var allEvents = await Client.Events.GetAsync(1, 250).ConfigureAwait(false); | ||
var itemsResponse = await allEvents.GetSuccessResponseAsync().ConfigureAwait(false); | ||
|
||
// Act | ||
var response = await Client.Events.GetAsync(itemsResponse.Items.First().Id).ConfigureAwait(false); | ||
var successResponse = await allEvents.GetSuccessResponseAsync().ConfigureAwait(false); | ||
var firstEvent = successResponse.Items.First(); | ||
|
||
// Assert | ||
Assert.That(response.IsSuccess, Is.True); | ||
Assert.That(firstEvent.Data.Object, Is.Not.Null); | ||
} | ||
|
||
[Test] | ||
public async Task List_Events_with_success() | ||
{ | ||
// Arrange | ||
var response = await Client.Events.GetAsync(1, 250).ConfigureAwait(false); | ||
|
||
// Act | ||
var successResponse = await response.GetSuccessResponseAsync().ConfigureAwait(false); | ||
|
||
// Assert | ||
Assert.That(response.IsSuccess, Is.True); | ||
Assert.That(successResponse.Items, Is.Not.Empty); | ||
} | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
BoletoSimplesApiClient.IntegratedTests/InstallmentApiIntegratedTests.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
348 changes: 324 additions & 24 deletions
348
BoletoSimplesApiClient.IntegratedTests/recorded-requests/http-requests-cassette.json
Large diffs are not rendered by default.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using BoletoSimplesApiClient.APIs.Events.Models; | ||
using BoletoSimplesApiClient.Common; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace BoletoSimplesApiClient.APIs.Events | ||
{ | ||
/// <summary> | ||
/// Api para consulta de eventos | ||
/// </summary> | ||
public sealed class EventsApi | ||
{ | ||
private readonly BoletoSimplesClient _client; | ||
private readonly HttpClientRequestBuilder _requestBuilder; | ||
private const string EVENTS_API = "/events"; | ||
|
||
public EventsApi(BoletoSimplesClient client) | ||
{ | ||
_client = client; | ||
_requestBuilder = new HttpClientRequestBuilder(client); | ||
} | ||
|
||
/// <summary> | ||
/// Informações do evento | ||
/// </summary> | ||
/// <param name="id">id do evento</param> | ||
/// <returns>Obtêm informações do evento</returns> | ||
/// <see cref="http://api.boletosimples.com.br/reference/v1/events/#informações-do-evento"/> | ||
public async Task<ApiResponse<EventData>> GetAsync(int id) | ||
{ | ||
var request = _requestBuilder.To(_client.Connection.GetBaseUri(), $"{EVENTS_API}/{id}") | ||
.WithMethod(HttpMethod.Get) | ||
.Build(); | ||
|
||
return await _client.SendAsync<EventData>(request); | ||
} | ||
|
||
/// <summary> | ||
/// Listar eventos paginado | ||
/// </summary> | ||
/// <param name="pageNumber">Numero da página</param> | ||
/// <param name="maxPerPage">Quantidade máxima por pagina, máximo e default são 250 items por página</param> | ||
/// <returns>Um resultado paginado contendo uma lista de eventos</returns> | ||
/// <exception cref="ArgumentException">Parametro máx per page superior ao limite de 250 itens</exception> | ||
/// <see cref="http://api.boletosimples.com.br/reference/v1/events/#listar-eventos"/> | ||
public async Task<PagedApiResponse<EventData>> GetAsync(int pageNumber, int maxPerPage = 250) | ||
{ | ||
if (maxPerPage > 250) | ||
throw new ArgumentException("o valor máximo para o argumento maxPerPage é 250"); | ||
|
||
|
||
var request = _requestBuilder.To(_client.Connection.GetBaseUri(), EVENTS_API) | ||
.WithMethod(HttpMethod.Get) | ||
.AppendQuery(new Dictionary<string, string> | ||
{ | ||
["page"] = pageNumber.ToString(), | ||
["per_page"] = maxPerPage.ToString() | ||
}) | ||
.Build(); | ||
|
||
return await _client.SendPagedAsync<EventData>(request); | ||
} | ||
} | ||
} |
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,38 @@ | ||
using BoletoSimplesApiClient.Common; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace BoletoSimplesApiClient.APIs.Events.Models | ||
{ | ||
[JsonRoot("event")] | ||
public class EventData | ||
{ | ||
/// <summary> | ||
/// ID do carnê | ||
/// </summary> | ||
public int Id { get; set; } | ||
|
||
/// <summary> | ||
/// Código do evento | ||
/// </summary> | ||
/// <see cref="http://api.boletosimples.com.br/webhooks/events"/> | ||
public string Code { get; set; } | ||
|
||
/// <summary> | ||
/// Mais informações relativas ao evento | ||
/// </summary> | ||
/// <see cref="http://api.boletosimples.com.br/webhooks/payloads"/> | ||
public EventDetail Data { get; set; } | ||
|
||
/// <summary> | ||
/// ID do carnê | ||
/// </summary> | ||
public DateTime? OccurredAt { get; set; } | ||
} | ||
|
||
public class EventDetail | ||
{ | ||
public object Object { get; set; } | ||
public Dictionary<string, string[]> Changes { 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
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