-
Notifications
You must be signed in to change notification settings - Fork 1
Gerenciando Nests
João Victor Oliveira edited this page Jan 19, 2025
·
1 revision
O gerenciando de nests é simples, bastando você utilizando este código inicial:
public class Main {
public static void main(String[] args) {
PteroAPI.initPteroAPI("https://example.com.br", "TOKEN", ManagerPolicy.ALL);
NestManager nestManager = PteroAPI.getManager(NestManager.class);
}
}
Para listar todos os nests, você precisará chamar a função "listNests", que retorna um CompletableFuture, do tipo lista de nests.
public class Main {
public static void main(String[] args) {
PteroAPI.initPteroAPI("https://example.com.br", "TOKEN", ManagerPolicy.ALL);
NestManager nestManager = PteroAPI.getManager(NestManager.class);
CompletableFuture<List<Nest>> completableFuture = nestManager.listNest();
completableFuture.thenAccept(nestList -> nestList.forEach(nest -> System.out.println("The nest: " + nest.getName() + " is present"))).exceptionally(throwable -> {
throw new RuntimeException(throwable);
});
}
}
Para pegar as informações de um nest, você precisará chamar a função "getNest", que retorna um CompletableFuture, do tipo Nest.
public class Main {
public static void main(String[] args) {
PteroAPI.initPteroAPI("https://example.com.br", "TOKEN", ManagerPolicy.ALL);
NestManager nestManager = PteroAPI.getManager(NestManager.class);
CompletableFuture<Nest> completableFuture = nestManager.getNest(1L);
completableFuture.thenAccept(nest -> System.out.println("The nest: " + nest.getName() + " is present")).exceptionally(throwable -> {
throw new RuntimeException(throwable);
});
}
}
Para listar todos os eggs, você precisará chamar a função "listEggs", que retorna um CompletableFuture, do tipo lista de eggs.
public class Main {
public static void main(String[] args) {
PteroAPI.initPteroAPI("https://example.com.br", "TOKEN", ManagerPolicy.ALL);
NestManager nestManager = PteroAPI.getManager(NestManager.class);
CompletableFuture<List<Egg>> completableFuture = nestManager.listEggs(1L);
completableFuture.thenAccept(nestList -> nestList.forEach(egg -> System.out.println("The egg: " + egg.getDescription() + " is present"))).exceptionally(throwable -> {
throw new RuntimeException(throwable);
});
}
}
Para pegar as informações de um egg, você precisará chamar a função "getEgg", que retorna um CompletableFuture, do tipo Egg.
public class Main {
public static void main(String[] args) {
PteroAPI.initPteroAPI("https://example.com.br", "TOKEN", ManagerPolicy.ALL);
NestManager nestManager = PteroAPI.getManager(NestManager.class);
CompletableFuture<Egg> completableFuture = nestManager.getEgg(1L, 1L);
completableFuture.thenAccept(egg -> System.out.println("The egg: " + egg.getId() + " is present")).exceptionally(throwable -> {
throw new RuntimeException(throwable);
});
}
}