Skip to content

Commit

Permalink
Merge pull request #1 from open-fidias/atilacamurca-patch-1
Browse files Browse the repository at this point in the history
Arquivo maven.yml adicionado; Suporte a paginação de boletos recebidos
  • Loading branch information
atilacamurca authored Jul 9, 2020
2 parents 1b6b3e6 + aefbe24 commit f31a93e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Java CI with Maven

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn -B package --file pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ public String getByIds(Set<String> pedidos) throws IOException, PJBankException
return responseObject.getString("linkBoleto");
}

public List<ExtratoBoleto> get(Date inicio, Date fim, StatusPagamentoBoleto pago) throws URISyntaxException, IOException, PJBankException, java.text.ParseException {
public List<ExtratoBoleto> get(Date inicio, Date fim, StatusPagamentoBoleto pago, Integer pagina) throws URISyntaxException, IOException, PJBankException, java.text.ParseException {
PJBankClient client = new PJBankClient(this.endPoint.concat("/transacoes"));
HttpGet httpGet = client.getHttpGetClient();
httpGet.addHeader("x-chave", this.getChave());
this.adicionarFiltros(httpGet, inicio, fim, pago);
this.adicionarFiltros(httpGet, inicio, fim, pago, pagina);

String response = EntityUtils.toString(client.doRequest(httpGet).getEntity());
JSONArray extratoObject = new JSONArray(response);
Expand Down Expand Up @@ -152,14 +152,15 @@ public List<ExtratoBoleto> get(Date inicio, Date fim, StatusPagamentoBoleto pago
return extratos;
}

private void adicionarFiltros(HttpRequestBase httpRequestClient, Date inicio, Date fim, StatusPagamentoBoleto pago)
private void adicionarFiltros(HttpRequestBase httpRequestClient, Date inicio, Date fim, StatusPagamentoBoleto pago, Integer pagina)
throws URISyntaxException {
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
URIBuilder uriBuilder = new URIBuilder(httpRequestClient.getURI());

uriBuilder.addParameter("data_inicio", formatter.format(inicio));
uriBuilder.addParameter("data_fim", formatter.format(fim));
uriBuilder.addParameter("pago", pago.getName());
uriBuilder.addParameter("pagina", pagina.toString());

httpRequestClient.setURI(uriBuilder.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ public void get() throws IOException, JSONException, PJBankException, ParseExcep
BoletosManager manager = new BoletosManager(this.credencial, this.chave);
LocalDate inicio = LocalDate.of(2001, 1, 29);
LocalDate fim = LocalDate.now();
List<ExtratoBoleto> extratos = manager.get(Date.from(inicio.atStartOfDay(ZoneId.systemDefault()).toInstant()), Date.from(fim.atStartOfDay(ZoneId.systemDefault()).toInstant()), StatusPagamentoBoleto.ABERTO);
List<ExtratoBoleto> extratos = manager.get(Date.from(inicio.atStartOfDay(ZoneId.systemDefault()).toInstant()), Date.from(fim.atStartOfDay(ZoneId.systemDefault()).toInstant()), StatusPagamentoBoleto.ABERTO, 1);
for (ExtratoBoleto extrato : extratos) {
Assert.assertThat(extrato.getDataPagamento(), nullValue(Date.class));
}

extratos = manager.get(Date.from(inicio.atStartOfDay(ZoneId.systemDefault()).toInstant()), Date.from(fim.atStartOfDay(ZoneId.systemDefault()).toInstant()), StatusPagamentoBoleto.PAGO);
extratos = manager.get(Date.from(inicio.atStartOfDay(ZoneId.systemDefault()).toInstant()), Date.from(fim.atStartOfDay(ZoneId.systemDefault()).toInstant()), StatusPagamentoBoleto.PAGO, 1);
for (ExtratoBoleto extrato : extratos) {
Assert.assertThat(extrato.getDataPagamento(), not(nullValue(Date.class)));
}
Expand Down

0 comments on commit f31a93e

Please sign in to comment.