Skip to content

Commit a018c7d

Browse files
authored
Seasons (#59)
* Added calls to create seasons and partial seasons * Ignored tests that rely on Mockbin * Properly disable test * Enabled test again * Added season calls * Refactored season creation * Tweaks * Removed unnecessary slash in request URLs * Refactoring * Version bump
1 parent 245cd46 commit a018c7d

17 files changed

+593
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ Then you can refer to seatsio-java as a regular package:
3030
```
3131
// build.gradle
3232
dependencies {
33-
compile 'com.github.seatsio:seatsio-java:67.4.0'
33+
compile 'com.github.seatsio:seatsio-java:68.0.0'
3434
}
3535
3636
// pom.xml
3737
<dependency>
3838
<groupId>com.github.seatsio</groupId>
3939
<artifactId>seatsio-java</artifactId>
40-
<version>67.4.0</version>
40+
<version>68.0.0</version>
4141
</dependency>
4242
```
4343

src/main/java/seatsio/SeatsioClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import seatsio.reports.charts.ChartReports;
77
import seatsio.reports.events.EventReports;
88
import seatsio.reports.usage.UsageReports;
9+
import seatsio.seasons.Seasons;
910
import seatsio.subaccounts.Subaccounts;
1011
import seatsio.util.UnirestWrapper;
1112
import seatsio.workspaces.Workspaces;
@@ -20,6 +21,7 @@ public class SeatsioClient {
2021
public final HoldTokens holdTokens;
2122
public final Charts charts;
2223
public final Events events;
24+
public final Seasons seasons;
2325
public final EventReports eventReports;
2426
public final ChartReports chartReports;
2527
public final UsageReports usageReports;
@@ -33,6 +35,7 @@ public SeatsioClient(String secretKey, String workspaceKey, String baseUrl) {
3335
this.holdTokens = new HoldTokens(baseUrl, unirest);
3436
this.charts = new Charts(baseUrl, unirest);
3537
this.events = new Events(baseUrl, unirest);
38+
this.seasons = new Seasons(baseUrl, unirest);
3639
this.eventReports = new EventReports(baseUrl, unirest);
3740
this.chartReports = new ChartReports(baseUrl, unirest);
3841
this.usageReports = new UsageReports(baseUrl, unirest);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package seatsio.seasons;
2+
3+
import seatsio.events.Event;
4+
import seatsio.events.TableBookingConfig;
5+
import seatsio.util.ValueObject;
6+
7+
import java.util.List;
8+
9+
public class Season extends ValueObject {
10+
11+
public long id;
12+
public String key;
13+
public Event seasonEvent;
14+
public List<Event> events;
15+
public List<String> partialSeasonKeys;
16+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package seatsio.seasons;
2+
3+
import seatsio.events.TableBookingConfig;
4+
5+
import java.util.List;
6+
7+
public class SeasonParams {
8+
9+
private String key;
10+
private List<String> eventKeys;
11+
private Integer numberOfEvents;
12+
private TableBookingConfig tableBookingConfig;
13+
private String socialDistancingRulesetKey;
14+
15+
public SeasonParams() {
16+
}
17+
18+
public String key() {
19+
return key;
20+
}
21+
22+
public SeasonParams key(String key) {
23+
this.key = key;
24+
return this;
25+
}
26+
27+
public SeasonParams eventKeys(List<String> eventKeys) {
28+
this.eventKeys = eventKeys;
29+
return this;
30+
}
31+
32+
public List<String> eventKeys() {
33+
return eventKeys;
34+
}
35+
36+
public SeasonParams numberOfEvents(Integer numberOfEvents) {
37+
this.numberOfEvents = numberOfEvents;
38+
return this;
39+
}
40+
41+
public Integer numberOfEvents() {
42+
return numberOfEvents;
43+
}
44+
45+
public SeasonParams tableBookingConfig(TableBookingConfig tableBookingConfig) {
46+
this.tableBookingConfig = tableBookingConfig;
47+
return this;
48+
}
49+
50+
public TableBookingConfig tableBookingConfig() {
51+
return tableBookingConfig;
52+
}
53+
54+
public String socialDistancingRulesetKey() {
55+
return socialDistancingRulesetKey;
56+
}
57+
58+
public SeasonParams socialDistancingRulesetKey(String socialDistancingRulesetKey) {
59+
this.socialDistancingRulesetKey = socialDistancingRulesetKey;
60+
return this;
61+
}
62+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package seatsio.seasons;
2+
3+
import seatsio.json.JsonObjectBuilder;
4+
import seatsio.util.Lister;
5+
import seatsio.util.Page;
6+
import seatsio.util.PageFetcher;
7+
import seatsio.util.UnirestWrapper;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
import java.util.stream.Stream;
12+
13+
import static seatsio.json.JsonObjectBuilder.aJsonObject;
14+
import static seatsio.json.SeatsioGson.gson;
15+
16+
public class Seasons {
17+
18+
private final String baseUrl;
19+
private final UnirestWrapper unirest;
20+
21+
public Seasons(String baseUrl, UnirestWrapper unirest) {
22+
this.baseUrl = baseUrl;
23+
this.unirest = unirest;
24+
}
25+
26+
public Season create(String chartKey) {
27+
return create(chartKey, new SeasonParams());
28+
}
29+
30+
public Season create(String chartKey, SeasonParams seasonParams) {
31+
JsonObjectBuilder request = aJsonObject()
32+
.withProperty("chartKey", chartKey)
33+
.withPropertyIfNotNull("key", seasonParams.key())
34+
.withPropertyIfNotNull("eventKeys", seasonParams.eventKeys())
35+
.withPropertyIfNotNull("numberOfEvents", seasonParams.numberOfEvents())
36+
.withPropertyIfNotNull("tableBookingConfig", seasonParams.tableBookingConfig())
37+
.withPropertyIfNotNull("socialDistancingRulesetKey", seasonParams.socialDistancingRulesetKey());
38+
String response = unirest.stringResponse(UnirestWrapper.post(baseUrl + "/seasons")
39+
.body(request.build().toString()));
40+
return gson().fromJson(response, Season.class);
41+
}
42+
43+
public Stream<Season> listAll() {
44+
return list().all();
45+
}
46+
47+
public Page<Season> listFirstPage() {
48+
return listFirstPage(null);
49+
}
50+
51+
public Page<Season> listFirstPage(Integer pageSize) {
52+
return list().firstPage(pageSize);
53+
}
54+
55+
public Page<Season> listPageAfter(long id) {
56+
return listPageAfter(id, null);
57+
}
58+
59+
public Page<Season> listPageAfter(long id, Integer pageSize) {
60+
return list().pageAfter(id, pageSize);
61+
}
62+
63+
public Page<Season> listPageBefore(long id) {
64+
return listPageBefore(id, null);
65+
}
66+
67+
public Page<Season> listPageBefore(long id, Integer pageSize) {
68+
return list().pageBefore(id, pageSize);
69+
}
70+
71+
private Lister<Season> list() {
72+
return new Lister<>(new PageFetcher<>(baseUrl, "/seasons", unirest, Season.class));
73+
}
74+
75+
public Season retrieve(String key) {
76+
String response = unirest.stringResponse(UnirestWrapper.get(baseUrl + "/seasons/{key}")
77+
.routeParam("key", key));
78+
return gson().fromJson(response, Season.class);
79+
}
80+
81+
public void delete(String key) {
82+
unirest.stringResponse(UnirestWrapper.delete(baseUrl + "/seasons/{key}")
83+
.routeParam("key", key));
84+
}
85+
86+
public Season createEvents(String key, List<String> eventKeys) {
87+
return doCreateEvents(key, eventKeys, null);
88+
}
89+
90+
public Season createEvents(String key, int numberOfEvents) {
91+
return doCreateEvents(key, null, numberOfEvents);
92+
}
93+
94+
private Season doCreateEvents(String key, List<String> eventKeys, Integer numberOfEvents) {
95+
JsonObjectBuilder request = aJsonObject()
96+
.withPropertyIfNotNull("eventKeys", eventKeys)
97+
.withPropertyIfNotNull("numberOfEvents", numberOfEvents);
98+
String response = unirest.stringResponse(UnirestWrapper.post(baseUrl + "/seasons/{key}/actions/create-events")
99+
.routeParam("key", key)
100+
.body(request.build().toString()));
101+
return gson().fromJson(response, Season.class);
102+
}
103+
104+
public Season createPartialSeason(String topLevelSeasonKey, String key, List<String> eventKeys) {
105+
JsonObjectBuilder request = aJsonObject()
106+
.withPropertyIfNotNull("key", key)
107+
.withPropertyIfNotNull("eventKeys", eventKeys);
108+
String response = unirest.stringResponse(UnirestWrapper.post(baseUrl + "/seasons/{topLevelSeasonKey}/partial-seasons")
109+
.routeParam("topLevelSeasonKey", topLevelSeasonKey)
110+
.body(request.build().toString()));
111+
return gson().fromJson(response, Season.class);
112+
}
113+
114+
public Season retrievePartialSeason(String topLevelSeasonKey, String partialSeasonKey) {
115+
String response = unirest.stringResponse(UnirestWrapper.get(baseUrl + "/seasons/{topLevelSeasonKey}/partial-seasons/{partialSeasonKey}")
116+
.routeParam("topLevelSeasonKey", topLevelSeasonKey)
117+
.routeParam("partialSeasonKey", partialSeasonKey));
118+
return gson().fromJson(response, Season.class);
119+
}
120+
121+
public void deletePartialSeason(String topLevelSeasonKey, String partialSeasonKey) {
122+
unirest.stringResponse(UnirestWrapper.delete(baseUrl + "/seasons/{topLevelSeasonKey}/partial-seasons/{partialSeasonKey}")
123+
.routeParam("topLevelSeasonKey", topLevelSeasonKey)
124+
.routeParam("partialSeasonKey", partialSeasonKey));
125+
}
126+
127+
public Season removeEventFromPartialSeason(String topLevelSeasonKey, String partialSeasonKey, String eventKey) {
128+
String response = unirest.stringResponse(UnirestWrapper.delete(baseUrl + "/seasons/{topLevelSeasonKey}/partial-seasons/{partialSeasonKey}/events/{eventKey}")
129+
.routeParam("topLevelSeasonKey", topLevelSeasonKey)
130+
.routeParam("partialSeasonKey", partialSeasonKey)
131+
.routeParam("eventKey", eventKey));
132+
return gson().fromJson(response, Season.class);
133+
}
134+
135+
public Season addEventsToPartialSeason(String topLevelSeasonKey, String partialSeasonKey, List<String> eventKeys) {
136+
JsonObjectBuilder request = aJsonObject().withProperty("eventKeys", eventKeys);
137+
String response = unirest.stringResponse(UnirestWrapper.post(baseUrl + "/seasons/{topLevelSeasonKey}/partial-seasons/{partialSeasonKey}/actions/add-events")
138+
.routeParam("topLevelSeasonKey", topLevelSeasonKey)
139+
.routeParam("partialSeasonKey", partialSeasonKey)
140+
.body(request.build().toString()));
141+
return gson().fromJson(response, Season.class);
142+
}
143+
}

src/main/java/seatsio/util/PageFetcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Page<T> fetchBefore(long id, Map<String, Object> parameters, Integer page
6666
}
6767

6868
private HttpRequest buildRequest(Map<String, Object> parameters, Integer pageSize) {
69-
HttpRequest request = get(baseUrl + "/" + url)
69+
HttpRequest request = get(baseUrl + url)
7070
.queryString(parameters);
7171
routeParams.forEach(request::routeParam);
7272
queryParams.entrySet().stream()

src/test/java/seatsio/events/CreateEventTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public void chartKeyIsRequired() {
3737
public void eventKeyCanBePassedIn() {
3838
Chart chart = client.charts.create();
3939

40-
Event event = client.events.create(chart.key, "eventje");
40+
Event event = client.events.create(chart.key, "anEvent");
4141

42-
assertThat(event.key).isEqualTo("eventje");
42+
assertThat(event.key).isEqualTo("anEvent");
4343
}
4444

4545
@Test
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package seatsio.seasons;
2+
3+
import org.junit.jupiter.api.Test;
4+
import seatsio.SeatsioClientTest;
5+
6+
import static com.google.common.collect.Lists.newArrayList;
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
9+
public class AddEventsToPartialSeasonTest extends SeatsioClientTest {
10+
11+
@Test
12+
public void test() {
13+
String chartKey = createTestChart();
14+
client.seasons.create(chartKey, new SeasonParams().key("aSeason").eventKeys(newArrayList("event1", "event2")));
15+
client.seasons.createPartialSeason("aSeason", "aPartialSeason", null);
16+
17+
Season updatedPartialSeason = client.seasons.addEventsToPartialSeason("aSeason", "aPartialSeason", newArrayList("event1", "event2"));
18+
19+
assertThat(updatedPartialSeason.events)
20+
.extracting(s -> s.key)
21+
.containsExactly("event1", "event2");
22+
}
23+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package seatsio.seasons;
2+
3+
import org.junit.jupiter.api.Test;
4+
import seatsio.SeatsioClientTest;
5+
6+
import static com.google.common.collect.Lists.newArrayList;
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
9+
public class CreateEventsInSeasonTest extends SeatsioClientTest {
10+
11+
@Test
12+
public void eventKeys() {
13+
String chartKey = createTestChart();
14+
Season season = client.seasons.create(chartKey);
15+
16+
Season updatedSeason = client.seasons.createEvents(season.key, newArrayList("event1", "event2"));
17+
18+
assertThat(updatedSeason.events)
19+
.extracting(s -> s.key)
20+
.containsExactly("event1", "event2");
21+
}
22+
23+
@Test
24+
public void numberOfEvents() {
25+
String chartKey = createTestChart();
26+
Season season = client.seasons.create(chartKey);
27+
28+
Season updatedSeason = client.seasons.createEvents(season.key, 2);
29+
30+
assertThat(updatedSeason.events).hasSize(2);
31+
}
32+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package seatsio.seasons;
2+
3+
import org.junit.jupiter.api.Test;
4+
import seatsio.SeatsioClientTest;
5+
import seatsio.charts.Chart;
6+
7+
import static com.google.common.collect.Lists.newArrayList;
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
public class CreatePartialSeasonTest extends SeatsioClientTest {
11+
12+
@Test
13+
public void keyCanBePassedIn() {
14+
Chart chart = client.charts.create();
15+
Season topLevelSeason = client.seasons.create(chart.key, new SeasonParams().key("aTopLevelSeason"));
16+
17+
Season partialSeason = client.seasons.createPartialSeason(topLevelSeason.key, "aPartialSeason", null);
18+
19+
assertThat(partialSeason.key).isEqualTo("aPartialSeason");
20+
}
21+
22+
@Test
23+
public void eventKeysCanBePassedIn() {
24+
Chart chart = client.charts.create();
25+
SeasonParams seasonParams = new SeasonParams()
26+
.key("aTopLevelSeason")
27+
.eventKeys(newArrayList("event1", "event2", "event3"));
28+
Season topLevelSeason = client.seasons.create(chart.key, seasonParams);
29+
30+
Season season = client.seasons.createPartialSeason(topLevelSeason.key, null, newArrayList("event1", "event3"));
31+
32+
assertThat(season.events).extracting(event -> event.key).containsExactly("event1", "event3");
33+
}
34+
}

0 commit comments

Comments
 (0)