aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/pina/Holodex.java
blob: 38c519a93dec46d00df91cfe2d5ed5c753d35204 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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);
        }
    }
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage