Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Commit

Permalink
Refatorando projeto, limpando e otimizando o código.
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoxkk0 committed Sep 14, 2020
1 parent 62f54c5 commit bf29d4a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# JavaRastreio
Api feita em java, para realizar o rastreio de encomendas.
Projeto não otimizado, ainda falta dar uma polida no código, porem tudo funciona.

Para utilizar o projeto, crie um novo objeto do tipo `RastreioAPI`, passe o SRO como argumento e seja feliz.
Api feita em java, para realizar o rastreio de encomendas.
Para utilizar basta chamar esse método abaixo.

Métodos disponíveis na classe:
`public String getCurrentStatus()` * Retorna o "local" atual da encomenda.

`public String getEvents()` * Retorna uma array em formato json com todos os eventos da encomenda.

`public String getSro()` * Retorna o Sro usado para a consulta.
```
Rastreio rastreio = RastreioAPI.getRastreio("BR123456789BR");
```
4 changes: 2 additions & 2 deletions src/main/java/br/com/brunoxkk0/core/Rastreio.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public class Rastreio {

SRO sro;
LinkedHashSet<Event> events;
private final SRO sro;
private final LinkedHashSet<Event> events;

public Rastreio(SRO sro, LinkedHashSet<Event> events){
this.sro = sro;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/br/com/brunoxkk0/core/SRO.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public class SRO {

private final String sro;


public SRO(String sro) throws InvalidSroException {

if(sro == null || !SROParser.match(sro)) throw new InvalidSroException();
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/br/com/brunoxkk0/utils/RequestProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ public class RequestProcessor {

private final LinkedHashSet<Event> events;

public RequestProcessor(byte[] data){
public RequestProcessor(byte[] data) throws InvalidSroException {
Document document = Jsoup.parse(new String(data, StandardCharsets.UTF_8));

Elements element = document.body().getElementsByClass("listEvent sro");

events = new LinkedHashSet<>();

if(element != null){
if(element != null && !element.isEmpty()) {
for (Element row : element.select("tr")) {
events.add(new Event(
row.getElementsByClass("sroDtEvent").text(),
row.getElementsByClass("sroLbEvent").text()
));
}
}else{
throw new InvalidSroException();
}

}
Expand Down

0 comments on commit bf29d4a

Please sign in to comment.