All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.jimmydbe.GenresClient Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
package io.github.jimmydbe;

import io.github.jimmydbe.entities.BaseGenreResponse;
import io.github.jimmydbe.entities.BaseResponse;
import io.github.jimmydbe.entities.Genre;
import io.github.jimmydbe.exceptions.GamesDbException;
import io.github.jimmydbe.exceptions.ParsingException;
import kong.unirest.GenericType;
import kong.unirest.HttpResponse;
import kong.unirest.Unirest;

import java.util.List;
import java.util.stream.Collectors;

class GenresClient extends Client {

    protected GenresClient(String apiKey) {
        super(apiKey);
    }

    protected List getAllGenres() throws ParsingException, GamesDbException {

        final HttpResponse> response = Unirest.get(TheGamesDbClient.BASE_URL + "/v1/Genres")
                .queryString("apikey", getApiKey())
                .asObject(new GenericType>() {
                });

        checkForErrors(response);

        return response.getBody()
                .getData()
                .getGenres()
                .values()
                .stream()
                .collect(Collectors.toList());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy