io.induct.yle.api.programs.YleProgramsApi Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yle-api Show documentation
Show all versions of yle-api Show documentation
Uploads all artifacts belonging to configuration ':archives'
The newest version!
package io.induct.yle.api.programs;
import com.fasterxml.jackson.core.type.TypeReference;
import io.induct.rest.ApiResponse;
import io.induct.rest.Request;
import io.induct.yle.api.StandardizedApi;
import io.induct.yle.api.YleId;
import io.induct.yle.api.common.Language;
import io.induct.yle.api.programs.domain.CuratedList;
import io.induct.yle.api.programs.domain.Item;
import io.induct.yle.api.programs.domain.NowPlaying;
import io.induct.yle.api.programs.domain.items.Service;
import io.induct.yle.api.programs.domain.search.ItemSearch;
import javax.inject.Inject;
import java.util.List;
/**
* @since 2015-05-30
*/
public class YleProgramsApi extends StandardizedApi {
public static final String PROGRAMS_BASE_URL = "https://external.api.yle.fi";
private final TypeReference>> listOfServices;
private final TypeReference>> listOfItems;
private final TypeReference> singleItem;
private final TypeReference>> listOfCuratedLists;
private final TypeReference>> nowPlaying;
@Inject
public YleProgramsApi() {
super(PROGRAMS_BASE_URL);
this.listOfServices = new TypeReference>>() {};
this.listOfItems = new TypeReference>>() {};
this.singleItem = new TypeReference>() {};
this.listOfCuratedLists = new TypeReference>>() {};
this.nowPlaying = new TypeReference>>() {};
}
public ApiResponse> listServices(Service.Type type, int limit, int offset) {
Request request = createRequestBuilder()
.withPath("/v1/programs/services.json")
.withParams(params -> {
params.put("type", type.value());
params.put("limit", Integer.toString(limit));
params.put("offset", Integer.toString(offset));
})
.build();
return handleApiCall(request, listOfServices);
}
public ApiResponse> search(ItemSearch search) {
Request request = createRequestBuilder()
.withPath("/v1/programs/items.json")
.withParams(params -> {
params.putAll(search.getParams());
})
.build();
return handleApiCall(request, listOfItems);
}
public ApiResponse> listCuratedLists(Language language, CuratedList.Type type, int limit, int offset) {
Request request = createRequestBuilder()
.withPath("/v1/programs/lists.json")
.withParams(params -> {
params.put("language", language.getLanguageCode());
params.put("type", type.value());
params.put("limit", Integer.toString(limit));
params.put("offset", Integer.toString(offset));
})
.build();
return handleApiCall(request, listOfCuratedLists);
}
public ApiResponse- getItem(YleId yleId) {
Request request = createRequestBuilder()
.withPath("/v1/programs/items/" + yleId.identity() + ".json")
.build();
return handleApiCall(request, singleItem);
}
public ApiResponse
> nowPlaying(String id) {
Request request = createRequestBuilder()
.withPath("/v1/programs/nowplaying/" + id + ".json")
.withParams(params -> {
params.put("start", Integer.toString(-1));
params.put("end", Integer.toString(1));
})
.build();
return handleApiCall(request, nowPlaying);
}
}