Skip to content

Commit

Permalink
Add track service
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Oct 23, 2023
1 parent c6d8a9e commit 1fc0bd6
Show file tree
Hide file tree
Showing 12 changed files with 403 additions and 23 deletions.
8 changes: 8 additions & 0 deletions src/main/java/net/luckperms/rest/LuckPermsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.luckperms.rest.service.ActionService;
import net.luckperms.rest.service.GroupService;
import net.luckperms.rest.service.MiscService;
import net.luckperms.rest.service.TrackService;
import net.luckperms.rest.service.UserService;

/**
Expand Down Expand Up @@ -60,6 +61,13 @@ static Builder builder() {
*/
GroupService groups();

/**
* Gets the track service.
*
* @return the track service
*/
TrackService tracks();

/**
* Gets the action service.
*
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/luckperms/rest/LuckPermsClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.luckperms.rest.service.ActionService;
import net.luckperms.rest.service.GroupService;
import net.luckperms.rest.service.MiscService;
import net.luckperms.rest.service.TrackService;
import net.luckperms.rest.service.UserService;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
Expand All @@ -42,6 +43,7 @@
class LuckPermsClientImpl implements LuckPermsClient {
private final UserService userService;
private final GroupService groupService;
private final TrackService trackService;
private final ActionService actionService;
private final MiscService miscService;

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

this.userService = retrofit.create(UserService.class);
this.groupService = retrofit.create(GroupService.class);
this.trackService = retrofit.create(TrackService.class);
this.actionService = retrofit.create(ActionService.class);
this.miscService = retrofit.create(MiscService.class);
}
Expand All @@ -74,6 +77,10 @@ public GroupService groups() {
return this.groupService;
}

public TrackService tracks() {
return this.trackService;
}

@Override
public ActionService actions() {
return this.actionService;
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/net/luckperms/rest/model/CreateTrackRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package net.luckperms.rest.model;

public class CreateTrackRequest extends AbstractModel {
private final String name;

public CreateTrackRequest(String name) {
this.name = name;
}

public String name() {
return this.name;
}
}
46 changes: 46 additions & 0 deletions src/main/java/net/luckperms/rest/model/Track.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package net.luckperms.rest.model;

import java.util.List;

public class Track extends AbstractModel {
private final String name;
private final List<String> groups;

public Track(String name, List<String> groups) {
this.name = name;
this.groups = groups;
}

public String name() {
return this.name;
}

public List<String> groups() {
return this.groups;
}
}
40 changes: 40 additions & 0 deletions src/main/java/net/luckperms/rest/model/UpdateTrackRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package net.luckperms.rest.model;

import java.util.List;

public class UpdateTrackRequest extends AbstractModel {
private final List<String> groups;

public UpdateTrackRequest(List<String> groups) {
this.groups = groups;
}

public List<String> username() {
return this.groups;
}
}
58 changes: 58 additions & 0 deletions src/main/java/net/luckperms/rest/service/TrackService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package net.luckperms.rest.service;

import net.luckperms.rest.model.CreateTrackRequest;
import net.luckperms.rest.model.Track;
import net.luckperms.rest.model.UpdateTrackRequest;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.PATCH;
import retrofit2.http.POST;
import retrofit2.http.Path;

import java.util.Set;

public interface TrackService {

@GET("/track")
Call<Set<String>> list();

@POST("/track")
Call<Track> create(@Body CreateTrackRequest req);

@GET("/track/{name}")
Call<Track> get(@Path("name") String name);

@PATCH("/track/{name}")
Call<Void> update(@Path("name") String name, @Body UpdateTrackRequest req);

@DELETE("/track/{name}")
Call<Void> delete(@Path("name") String name);

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ protected LuckPermsClient createClient() {
return LuckPermsClient.builder().baseUrl(baseUrl).build();
}

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

}
4 changes: 2 additions & 2 deletions src/test/java/me/lucko/luckperms/rest/ActionServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public void testSubmit() throws IOException {

Response<Void> resp = client.actions().submit(new Action(
System.currentTimeMillis() / 1000L,
new Action.Source(UUID.randomUUID(), randomUsername()),
new Action.Target(UUID.randomUUID(), randomUsername(), Action.Target.Type.USER),
new Action.Source(UUID.randomUUID(), randomName()),
new Action.Target(UUID.randomUUID(), randomName(), Action.Target.Type.USER),
"hello world"
)).execute();
assertTrue(resp.isSuccessful());
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/me/lucko/luckperms/rest/GroupServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class GroupServiceTest extends AbstractIntegrationTest {
public void testGroupCrud() throws IOException {
LuckPermsClient client = createClient();

String name = randomUsername();
String name = randomName();

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

String name = randomUsername();
String name = randomName();

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

String name = randomUsername();
String name = randomName();

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

String name = randomUsername();
String name = randomName();

// create a group
assertTrue(client.groups().create(new CreateGroupRequest(name)).execute().isSuccessful());
Expand Down Expand Up @@ -251,7 +251,7 @@ public void testGroupSearch() throws IOException {
}
}

String name = randomUsername();
String name = randomName();

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

String name = randomUsername();
String name = randomName();

// create a group
assertTrue(client.groups().create(new CreateGroupRequest(name)).execute().isSuccessful());
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/me/lucko/luckperms/rest/MiscServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@
package me.lucko.luckperms.rest;

import net.luckperms.rest.LuckPermsClient;
import net.luckperms.rest.model.Action;
import net.luckperms.rest.model.Health;
import org.junit.jupiter.api.Test;
import retrofit2.Response;

import java.io.IOException;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down
Loading

0 comments on commit 1fc0bd6

Please sign in to comment.