diff options
| -rw-r--r-- | pom.xml | 8 | ||||
| -rw-r--r-- | src/main/java/App.java | 8 | ||||
| -rw-r--r-- | src/main/java/com/pina/Channel.java | 4 | ||||
| -rw-r--r-- | src/main/java/com/pina/Holodex.java | 15 | ||||
| -rw-r--r-- | src/main/java/com/pina/HolodexService.java | 18 | ||||
| -rw-r--r-- | src/main/java/com/pina/LiveStream.java | 12 | ||||
| -rw-r--r-- | src/main/java/com/pina/query/LiveStreamsQueryBuilder.java | 154 | ||||
| -rw-r--r-- | src/test/java/HolodexServiceTest.java | 13 | ||||
| -rw-r--r-- | src/test/java/org/example/AppTest.java | 38 |
9 files changed, 220 insertions, 50 deletions
@@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <groupId>org.example</groupId> + <groupId>com.pina</groupId> <artifactId>HldexWrapper</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> @@ -33,5 +33,11 @@ <artifactId>converter-jackson</artifactId> <version>2.9.0</version> </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <version>RELEASE</version> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/src/main/java/App.java b/src/main/java/App.java index 73691fb..8e1090f 100644 --- a/src/main/java/App.java +++ b/src/main/java/App.java @@ -1,6 +1,7 @@ import com.pina.Holodex; import com.pina.HolodexException; import com.pina.LiveStream; +import com.pina.query.LiveStreamsQueryBuilder; import java.util.List; @@ -10,9 +11,12 @@ public class App { Holodex holodex = new Holodex(); try { - List<LiveStream> liveStreams = holodex.getLiveStreams(); + LiveStreamsQueryBuilder query = new LiveStreamsQueryBuilder(); + query.setChannelId("UCBQd84IW8OvM8H5jftHdvmw"); + query.setStatus("live"); + List<LiveStream> liveStreams = holodex.getLiveStreams(query); for (LiveStream stream : liveStreams) { - System.out.println(stream.title + " by " + stream.channel.name); + System.out.println(stream.title + " is live with " + stream.live_viewers + " viewers" + stream.id); } } catch (HolodexException e) { System.err.println("Failed to get live streams: " + e.getMessage()); diff --git a/src/main/java/com/pina/Channel.java b/src/main/java/com/pina/Channel.java index 36cf499..3f84a10 100644 --- a/src/main/java/com/pina/Channel.java +++ b/src/main/java/com/pina/Channel.java @@ -4,9 +4,11 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) public class Channel { - public String english_name; public String id; + public String english_name; public String name; + public String org; + public String suborg; public String photo; public String type; } diff --git a/src/main/java/com/pina/Holodex.java b/src/main/java/com/pina/Holodex.java index 38c519a..48e3e9c 100644 --- a/src/main/java/com/pina/Holodex.java +++ b/src/main/java/com/pina/Holodex.java @@ -1,5 +1,6 @@ package com.pina; +import com.pina.query.LiveStreamsQueryBuilder; import retrofit2.Call; import retrofit2.Response; import retrofit2.Retrofit; @@ -18,13 +19,19 @@ public class Holodex { .build(); service = retrofit.create(HolodexService.class); } - public List<LiveStream> getLiveStreams() throws HolodexException { - Call<List<LiveStream>> call = service.getLiveStreams("channel,clip"); + public List<LiveStream> getLiveStreams(LiveStreamsQueryBuilder queryBuilder) throws HolodexException { + Call<List<LiveStream>> call = service.getLiveStreams(queryBuilder.getChannelId(), queryBuilder.getId(), + queryBuilder.getInclude(), queryBuilder.getLang(), + queryBuilder.getLimit(), queryBuilder.getMaxUpcomingHours(), + queryBuilder.getMentionedChannelId(), queryBuilder.getOffset(), + queryBuilder.getOrder(), queryBuilder.getOrg(), + queryBuilder.getPaginated(), queryBuilder.getSort(), + queryBuilder.getStatus(), queryBuilder.getTopic(), + queryBuilder.getType()); return executeCall(call); } - public List<UpcomingStream> getUpcomingStreams() throws HolodexException { - Call<List<UpcomingStream>> call = service.getUpcomingStreams("channel,clip"); + Call<List<UpcomingStream>> call = service.getUpcomingStreams("channel"); return executeCall(call); } diff --git a/src/main/java/com/pina/HolodexService.java b/src/main/java/com/pina/HolodexService.java index 98351ca..e12c13e 100644 --- a/src/main/java/com/pina/HolodexService.java +++ b/src/main/java/com/pina/HolodexService.java @@ -7,7 +7,23 @@ import retrofit2.http.Query; public interface HolodexService { @GET("/api/v2/live") - Call<List<LiveStream>> getLiveStreams(@Query("include") String include); + Call<List<LiveStream>> getLiveStreams( + @Query("channel_id") String channel_id, + @Query("id") String id, + @Query("include") String include, + @Query("lang") String lang, + @Query("limit") Integer limit, + @Query("max_upcoming_hours") Integer offset, + @Query("mentioned_channel_id") String mentioned_channel_id, + @Query("offset") Integer max_upcoming_hours, + @Query("order") String order, + @Query("org") String org, + @Query("paginated") String paginated, + @Query("sort") String sort, + @Query("status") String status, + @Query("topic") String topic, + @Query("type") String type + ); @GET("/api/v2/upcoming") Call<List<UpcomingStream>> getUpcomingStreams(@Query("include") String include); diff --git a/src/main/java/com/pina/LiveStream.java b/src/main/java/com/pina/LiveStream.java index 5e1d7a9..fa37148 100644 --- a/src/main/java/com/pina/LiveStream.java +++ b/src/main/java/com/pina/LiveStream.java @@ -2,15 +2,21 @@ package com.pina; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class LiveStream { public String id; public String title; - public String thumbnail; + public String type; + public String topic; + public String published_at; + public String available_at; + public int duration; public String status; - public int viewers; + public String start_scheduled; + public String start_actual; + public String thumbnail; + public int live_viewers; public Channel channel; } diff --git a/src/main/java/com/pina/query/LiveStreamsQueryBuilder.java b/src/main/java/com/pina/query/LiveStreamsQueryBuilder.java new file mode 100644 index 0000000..ca7f86e --- /dev/null +++ b/src/main/java/com/pina/query/LiveStreamsQueryBuilder.java @@ -0,0 +1,154 @@ +package com.pina.query; + +public class LiveStreamsQueryBuilder { + private String channelId; + private String id; + private String include; + private String lang; + private Integer limit; + private Integer maxUpcomingHours; + private String mentionedChannelId; + private Integer offset; + private String order; + private String org; + private String paginated; + private String sort; + private String status; + private String topic; + private String type; + + public LiveStreamsQueryBuilder setChannelId(String channelId) { + this.channelId = channelId; + return this; + } + + public LiveStreamsQueryBuilder setId(String id) { + this.id = id; + return this; + } + + public LiveStreamsQueryBuilder setInclude(String include) { + this.include = include; + return this; + } + + public LiveStreamsQueryBuilder setLang(String lang) { + this.lang = lang; + return this; + } + + public LiveStreamsQueryBuilder setLimit(Integer limit) { + this.limit = limit; + return this; + } + + public LiveStreamsQueryBuilder setMaxUpcomingHours(Integer maxUpcomingHours) { + this.maxUpcomingHours = maxUpcomingHours; + return this; + } + + public LiveStreamsQueryBuilder setMentionedChannelId(String mentionedChannelId) { + this.mentionedChannelId = mentionedChannelId; + return this; + } + + public LiveStreamsQueryBuilder setOffset(Integer offset) { + this.offset = offset; + return this; + } + + public LiveStreamsQueryBuilder setOrder(String order) { + this.order = order; + return this; + } + + public LiveStreamsQueryBuilder setOrg(String org) { + this.org = org; + return this; + } + + public LiveStreamsQueryBuilder setPaginated(String paginated) { + this.paginated = paginated; + return this; + } + + public LiveStreamsQueryBuilder setSort(String sort) { + this.sort = sort; + return this; + } + + public LiveStreamsQueryBuilder setStatus(String status) { + this.status = status; + return this; + } + + public LiveStreamsQueryBuilder setTopic(String topic) { + this.topic = topic; + return this; + } + + public LiveStreamsQueryBuilder setType(String type) { + this.type = type; + return this; + } + + public String getChannelId() { + return channelId; + } + + public String getId() { + return id; + } + + public String getInclude() { + return include; + } + + public String getLang() { + return lang; + } + + public Integer getLimit() { + return limit; + } + + public Integer getMaxUpcomingHours() { + return maxUpcomingHours; + } + + public String getMentionedChannelId() { + return mentionedChannelId; + } + + public Integer getOffset() { + return offset; + } + + public String getOrder() { + return order; + } + + public String getOrg() { + return org; + } + + public String getPaginated() { + return paginated; + } + + public String getSort() { + return sort; + } + + public String getStatus() { + return status; + } + + public String getTopic() { + return topic; + } + + public String getType() { + return type; + } +}
\ No newline at end of file diff --git a/src/test/java/HolodexServiceTest.java b/src/test/java/HolodexServiceTest.java new file mode 100644 index 0000000..a05913e --- /dev/null +++ b/src/test/java/HolodexServiceTest.java @@ -0,0 +1,13 @@ +import com.pina.HolodexService; +import com.pina.LiveStream; +import org.junit.jupiter.api.Test; + +public class HolodexServiceTest { + + @Test + public void testGetLiveStreams() throws Exception { + //TOOD: Implement testcase using mocking + } + + +} diff --git a/src/test/java/org/example/AppTest.java b/src/test/java/org/example/AppTest.java deleted file mode 100644 index d5f435d..0000000 --- a/src/test/java/org/example/AppTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.example; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } -} |
