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

com.sdcalmes.sleeper.StatImpl Maven / Gradle / Ivy

package com.sdcalmes.sleeper;

import retrofit2.Response;
import retrofit2.Retrofit;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * The type Stat.
 */
class StatImpl
{

    private final transient  Stats statsEndpoint;

    /**
     * Instantiates a new Stat.
     *
     * @param retrofit the retrofit
     */
    StatImpl (final Retrofit retrofit)
    {
        statsEndpoint = retrofit.create(Stats.class);
    }

    /**
     * Gets weekly stats.
     *
     * @param seasonType the season type
     * @param season     the season
     * @param week       the week
     * @return the weekly stats
     * @throws SleeperError the sleeper error
     * @throws IOException  the io exception
     */
    public Map getWeeklyStats(String seasonType, String season, String week) throws SleeperError, IOException
    {
        Map statMap;
        Response> r = statsEndpoint.getWeeklyStats(seasonType, season, week).execute();
        if (r.isSuccessful())
        {
            statMap = r.body();
        }
        else
        {
            throw ErrorUtils.parseError(r);
        }

        return  statMap;
    }

    /**
     * Gets season stats.
     *
     * @param seasonType the season type
     * @param season     the season
     * @return the season stats
     * @throws SleeperError the sleeper error
     * @throws IOException  the io exception
     */
    public Map getSeasonStats(String seasonType, String season) throws SleeperError, IOException
    {
        Map statMap;
        Response> r = statsEndpoint.getSeasonStats(seasonType, season).execute();
        if (r.isSuccessful())
        {
            statMap = r.body();
        }
        else
        {
            throw ErrorUtils.parseError(r);
        }
        return  statMap;
    }

    /**
     * Gets weekly projections.
     *
     * @param seasonType the season type
     * @param season     the season
     * @param week       the week
     * @return the weekly projections
     * @throws SleeperError the sleeper error
     * @throws IOException  the io exception
     */
    public Map getWeeklyProjections(String seasonType, String season, String week) throws SleeperError, IOException
    {
        Map statMap;
        Response> r = statsEndpoint.getWeeklyProjections(seasonType, season, week).execute();
        if (r.isSuccessful())
        {
            statMap = r.body();
        }
        else
        {
            throw ErrorUtils.parseError(r);
        }
        return  statMap;
    }

    /**
     * Gets season projections.
     *
     * @param seasonType the season type
     * @param season     the season
     * @return the season projections
     * @throws SleeperError the sleeper error
     * @throws IOException  the io exception
     */
    public Map getSeasonProjections(String seasonType, String season) throws SleeperError, IOException
    {
        Map statMap;
        Response> r = statsEndpoint.getSeasonProjections(seasonType, season).execute();
        if (r.isSuccessful())
        {
            statMap = r.body();
        }
        else
        {
            throw ErrorUtils.parseError(r);
        }

        return  statMap;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy