diff options
| author | Pinapelz <donaldshan1@outlook.com> | 2023-04-04 12:11:11 -0700 |
|---|---|---|
| committer | Pinapelz <donaldshan1@outlook.com> | 2023-04-04 12:11:11 -0700 |
| commit | 28550a86f6f9b4dea05e3c19fb89ab7e4f6996ef (patch) | |
| tree | bf88782db8c047ff26fdf8ab4c82002d4e7e8850 /src/main/java/com/pina/Holodex.java | |
Initial Commit
Diffstat (limited to 'src/main/java/com/pina/Holodex.java')
| -rw-r--r-- | src/main/java/com/pina/Holodex.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/main/java/com/pina/Holodex.java b/src/main/java/com/pina/Holodex.java new file mode 100644 index 0000000..38c519a --- /dev/null +++ b/src/main/java/com/pina/Holodex.java @@ -0,0 +1,44 @@ +package com.pina; + +import retrofit2.Call; +import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.jackson.JacksonConverterFactory; + +import java.io.IOException; +import java.util.List; + +public class Holodex { + private final HolodexService service; + + public Holodex(){ + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("https://holodex.net") + .addConverterFactory(JacksonConverterFactory.create()) + .build(); + service = retrofit.create(HolodexService.class); + } + public List<LiveStream> getLiveStreams() throws HolodexException { + Call<List<LiveStream>> call = service.getLiveStreams("channel,clip"); + return executeCall(call); + } + + public List<UpcomingStream> getUpcomingStreams() throws HolodexException { + Call<List<UpcomingStream>> call = service.getUpcomingStreams("channel,clip"); + return executeCall(call); + } + + private <T> T executeCall(Call<T> call) throws HolodexException { + try { + Response<T> response = call.execute(); + if (response.isSuccessful()) { + return response.body(); + } else { + throw new HolodexException("API returned error: " + response.code()); + } + } catch (IOException e) { + System.out.println(e); + throw new HolodexException("Failed to execute API call", e); + } + } +} |
