Skip to content

Commit 1fc0bd6

Browse files
committed
Add track service
1 parent c6d8a9e commit 1fc0bd6

File tree

12 files changed

+403
-23
lines changed

12 files changed

+403
-23
lines changed

src/main/java/net/luckperms/rest/LuckPermsClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import net.luckperms.rest.service.ActionService;
2929
import net.luckperms.rest.service.GroupService;
3030
import net.luckperms.rest.service.MiscService;
31+
import net.luckperms.rest.service.TrackService;
3132
import net.luckperms.rest.service.UserService;
3233

3334
/**
@@ -60,6 +61,13 @@ static Builder builder() {
6061
*/
6162
GroupService groups();
6263

64+
/**
65+
* Gets the track service.
66+
*
67+
* @return the track service
68+
*/
69+
TrackService tracks();
70+
6371
/**
6472
* Gets the action service.
6573
*

src/main/java/net/luckperms/rest/LuckPermsClientImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import net.luckperms.rest.service.ActionService;
2929
import net.luckperms.rest.service.GroupService;
3030
import net.luckperms.rest.service.MiscService;
31+
import net.luckperms.rest.service.TrackService;
3132
import net.luckperms.rest.service.UserService;
3233
import okhttp3.Interceptor;
3334
import okhttp3.OkHttpClient;
@@ -42,6 +43,7 @@
4243
class LuckPermsClientImpl implements LuckPermsClient {
4344
private final UserService userService;
4445
private final GroupService groupService;
46+
private final TrackService trackService;
4547
private final ActionService actionService;
4648
private final MiscService miscService;
4749

@@ -60,6 +62,7 @@ class LuckPermsClientImpl implements LuckPermsClient {
6062

6163
this.userService = retrofit.create(UserService.class);
6264
this.groupService = retrofit.create(GroupService.class);
65+
this.trackService = retrofit.create(TrackService.class);
6366
this.actionService = retrofit.create(ActionService.class);
6467
this.miscService = retrofit.create(MiscService.class);
6568
}
@@ -74,6 +77,10 @@ public GroupService groups() {
7477
return this.groupService;
7578
}
7679

80+
public TrackService tracks() {
81+
return this.trackService;
82+
}
83+
7784
@Override
7885
public ActionService actions() {
7986
return this.actionService;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This file is part of LuckPerms, licensed under the MIT License.
3+
*
4+
* Copyright (c) lucko (Luck) <[email protected]>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
26+
package net.luckperms.rest.model;
27+
28+
public class CreateTrackRequest extends AbstractModel {
29+
private final String name;
30+
31+
public CreateTrackRequest(String name) {
32+
this.name = name;
33+
}
34+
35+
public String name() {
36+
return this.name;
37+
}
38+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* This file is part of LuckPerms, licensed under the MIT License.
3+
*
4+
* Copyright (c) lucko (Luck) <[email protected]>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
26+
package net.luckperms.rest.model;
27+
28+
import java.util.List;
29+
30+
public class Track extends AbstractModel {
31+
private final String name;
32+
private final List<String> groups;
33+
34+
public Track(String name, List<String> groups) {
35+
this.name = name;
36+
this.groups = groups;
37+
}
38+
39+
public String name() {
40+
return this.name;
41+
}
42+
43+
public List<String> groups() {
44+
return this.groups;
45+
}
46+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* This file is part of LuckPerms, licensed under the MIT License.
3+
*
4+
* Copyright (c) lucko (Luck) <[email protected]>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
26+
package net.luckperms.rest.model;
27+
28+
import java.util.List;
29+
30+
public class UpdateTrackRequest extends AbstractModel {
31+
private final List<String> groups;
32+
33+
public UpdateTrackRequest(List<String> groups) {
34+
this.groups = groups;
35+
}
36+
37+
public List<String> username() {
38+
return this.groups;
39+
}
40+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* This file is part of LuckPerms, licensed under the MIT License.
3+
*
4+
* Copyright (c) lucko (Luck) <[email protected]>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
26+
package net.luckperms.rest.service;
27+
28+
import net.luckperms.rest.model.CreateTrackRequest;
29+
import net.luckperms.rest.model.Track;
30+
import net.luckperms.rest.model.UpdateTrackRequest;
31+
import retrofit2.Call;
32+
import retrofit2.http.Body;
33+
import retrofit2.http.DELETE;
34+
import retrofit2.http.GET;
35+
import retrofit2.http.PATCH;
36+
import retrofit2.http.POST;
37+
import retrofit2.http.Path;
38+
39+
import java.util.Set;
40+
41+
public interface TrackService {
42+
43+
@GET("/track")
44+
Call<Set<String>> list();
45+
46+
@POST("/track")
47+
Call<Track> create(@Body CreateTrackRequest req);
48+
49+
@GET("/track/{name}")
50+
Call<Track> get(@Path("name") String name);
51+
52+
@PATCH("/track/{name}")
53+
Call<Void> update(@Path("name") String name, @Body UpdateTrackRequest req);
54+
55+
@DELETE("/track/{name}")
56+
Call<Void> delete(@Path("name") String name);
57+
58+
}

src/test/java/me/lucko/luckperms/rest/AbstractIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ protected LuckPermsClient createClient() {
6161
return LuckPermsClient.builder().baseUrl(baseUrl).build();
6262
}
6363

64-
protected static String randomUsername() {
65-
return "random" + ThreadLocalRandom.current().nextInt(99999);
64+
protected static String randomName() {
65+
return "random" + ThreadLocalRandom.current().nextInt(9999999);
6666
}
6767

6868
}

src/test/java/me/lucko/luckperms/rest/ActionServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public void testSubmit() throws IOException {
4343

4444
Response<Void> resp = client.actions().submit(new Action(
4545
System.currentTimeMillis() / 1000L,
46-
new Action.Source(UUID.randomUUID(), randomUsername()),
47-
new Action.Target(UUID.randomUUID(), randomUsername(), Action.Target.Type.USER),
46+
new Action.Source(UUID.randomUUID(), randomName()),
47+
new Action.Target(UUID.randomUUID(), randomName(), Action.Target.Type.USER),
4848
"hello world"
4949
)).execute();
5050
assertTrue(resp.isSuccessful());

src/test/java/me/lucko/luckperms/rest/GroupServiceTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class GroupServiceTest extends AbstractIntegrationTest {
5959
public void testGroupCrud() throws IOException {
6060
LuckPermsClient client = createClient();
6161

62-
String name = randomUsername();
62+
String name = randomName();
6363

6464
// create
6565
Response<Group> createResp = client.groups().create(new CreateGroupRequest(name)).execute();
@@ -93,7 +93,7 @@ public void testGroupCrud() throws IOException {
9393
public void testGroupList() throws IOException {
9494
LuckPermsClient client = createClient();
9595

96-
String name = randomUsername();
96+
String name = randomName();
9797

9898
// create a group
9999
assertTrue(client.groups().create(new CreateGroupRequest(name)).execute().isSuccessful());
@@ -108,7 +108,7 @@ public void testGroupList() throws IOException {
108108
public void testGroupNodes() throws IOException {
109109
LuckPermsClient client = createClient();
110110

111-
String name = randomUsername();
111+
String name = randomName();
112112

113113
// create a group
114114
assertTrue(client.groups().create(new CreateGroupRequest(name)).execute().isSuccessful());
@@ -213,7 +213,7 @@ public void testGroupNodes() throws IOException {
213213
public void testGroupMetadata() throws IOException {
214214
LuckPermsClient client = createClient();
215215

216-
String name = randomUsername();
216+
String name = randomName();
217217

218218
// create a group
219219
assertTrue(client.groups().create(new CreateGroupRequest(name)).execute().isSuccessful());
@@ -251,7 +251,7 @@ public void testGroupSearch() throws IOException {
251251
}
252252
}
253253

254-
String name = randomUsername();
254+
String name = randomName();
255255

256256
// create a group
257257
assertTrue(client.groups().create(new CreateGroupRequest(name)).execute().isSuccessful());
@@ -310,7 +310,7 @@ public void testGroupSearch() throws IOException {
310310
public void testGroupPermissionCheck() throws IOException {
311311
LuckPermsClient client = createClient();
312312

313-
String name = randomUsername();
313+
String name = randomName();
314314

315315
// create a group
316316
assertTrue(client.groups().create(new CreateGroupRequest(name)).execute().isSuccessful());

src/test/java/me/lucko/luckperms/rest/MiscServiceTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@
2626
package me.lucko.luckperms.rest;
2727

2828
import net.luckperms.rest.LuckPermsClient;
29-
import net.luckperms.rest.model.Action;
3029
import net.luckperms.rest.model.Health;
3130
import org.junit.jupiter.api.Test;
3231
import retrofit2.Response;
3332

3433
import java.io.IOException;
35-
import java.util.UUID;
3634

3735
import static org.junit.jupiter.api.Assertions.assertNotNull;
3836
import static org.junit.jupiter.api.Assertions.assertTrue;

0 commit comments

Comments
 (0)