Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 9667a52

Browse files
committed
Add gifted subs and sub tiers to the api and tipeeestream
1 parent 94111c8 commit 9667a52

File tree

3 files changed

+84
-7
lines changed

3 files changed

+84
-7
lines changed

src/main/java/org/codeoverflow/chatoverflow/api/io/dto/stat/stream/Subscription.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ public class Subscription<T extends User> {
88
private final T subscriber;
99
private final OffsetDateTime time;
1010
private final int resub;
11+
private final SubscriptionTier tier;
12+
private final boolean gifted;
13+
private final T donor;
1114

12-
public Subscription(T subscriber, int resub, OffsetDateTime time) {
15+
public Subscription(T subscriber, OffsetDateTime time, int resub, SubscriptionTier tier, boolean gifted, T donor) {
1316
this.subscriber = subscriber;
1417
this.time = time;
1518
this.resub = resub;
19+
this.tier = tier;
20+
this.gifted = gifted;
21+
this.donor = donor;
1622
}
1723

1824
/**
@@ -24,6 +30,15 @@ public T getSubscriber() {
2430
return subscriber;
2531
}
2632

33+
/**
34+
* Get the time when the user started following
35+
*
36+
* @return follow start time
37+
*/
38+
public OffsetDateTime getTime() {
39+
return time;
40+
}
41+
2742
/**
2843
* Returns how often that user has subscribed
2944
*
@@ -34,11 +49,29 @@ public int getResub() {
3449
}
3550

3651
/**
37-
* Get the time when the user started following
52+
* Returns the tier of the subscription {@link SubscriptionTier}.
3853
*
39-
* @return follow start time
54+
* @return the sub tier
4055
*/
41-
public OffsetDateTime getTime() {
42-
return time;
56+
public SubscriptionTier getTier() {
57+
return tier;
58+
}
59+
60+
/**
61+
* Returns if the sub was gifted by someone else or not
62+
*
63+
* @return it the sub was gifted
64+
*/
65+
public boolean isGifted() {
66+
return gifted;
67+
}
68+
69+
/**
70+
* Returns the donor of the subscription if it was gifted.
71+
*
72+
* @return the donor of the sub
73+
*/
74+
public T getDonor() {
75+
return donor;
4376
}
4477
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.codeoverflow.chatoverflow.api.io.dto.stat.stream;
2+
3+
import java.util.Arrays;
4+
5+
/**
6+
* Represents the tier of a {@link Subscription}.
7+
*/
8+
public enum SubscriptionTier {
9+
PRIME, // Free for the user, same as a tier 1 for the streamer.
10+
TIER1, // 4.99
11+
TIER2, // 9.99
12+
TIER3, // 24.99
13+
UNKNOWN;
14+
15+
/**
16+
* Converts the tier to a string, e.g. {@link #TIER1} is "tier 1", {@link #PRIME} is "prime" and
17+
* {@link #UNKNOWN} is "unknown".
18+
*
19+
* @return the tier formatted as a string.
20+
*/
21+
@Override
22+
public String toString() {
23+
switch (this) {
24+
case PRIME: return "prime";
25+
case TIER1: return "tier 1";
26+
case TIER2: return "tier 2";
27+
case TIER3: return "tier 3";
28+
default: return "unknown";
29+
}
30+
}
31+
32+
/**
33+
* Parse the tier from a string
34+
*
35+
* @param tier the tier of the sub. 0 is prime, 1 is tier 1 and so on.
36+
* @return the sub-tier represented by the passed number or {@link #UNKNOWN}.
37+
*/
38+
public static SubscriptionTier parse(int tier) {
39+
return Arrays.stream(values())
40+
.filter(e -> e.ordinal() == tier)
41+
.findAny().orElse(UNKNOWN);
42+
}
43+
}

src/main/java/org/codeoverflow/chatoverflow/api/io/dto/stat/stream/tipeeestream/TipeeestreamSubscription.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
import org.codeoverflow.chatoverflow.api.io.dto.User;
44
import org.codeoverflow.chatoverflow.api.io.dto.stat.stream.Subscription;
5+
import org.codeoverflow.chatoverflow.api.io.dto.stat.stream.SubscriptionTier;
56

67
import java.time.OffsetDateTime;
78

89
public class TipeeestreamSubscription extends Subscription<User> {
910

1011
private final TipeeestreamProvider provider;
1112

12-
public TipeeestreamSubscription(User subscriber, int resub, OffsetDateTime time, TipeeestreamProvider provider) {
13-
super(subscriber, resub, time);
13+
public TipeeestreamSubscription(User subscriber, OffsetDateTime time, int resub, SubscriptionTier tier, boolean gifted, User donor, TipeeestreamProvider provider) {
14+
super(subscriber, time, resub, tier, gifted, donor);
1415
this.provider = provider;
1516
}
1617

0 commit comments

Comments
 (0)