http service: rename kc to chat

This commit is contained in:
Adam
2019-01-05 10:02:17 -05:00
parent 598480dfe4
commit 5192a28cec
5 changed files with 26 additions and 24 deletions

View File

@@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.runelite.http.api.kc; package net.runelite.http.api.chat;
import java.io.IOException; import java.io.IOException;
import net.runelite.http.api.RuneLiteAPI; import net.runelite.http.api.RuneLiteAPI;
@@ -31,11 +31,12 @@ import okhttp3.Request;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import okhttp3.Response; import okhttp3.Response;
public class KillCountClient public class ChatClient
{ {
public boolean submit(String username, String boss, int kc) throws IOException public boolean submit(String username, String boss, int kc) throws IOException
{ {
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("chat")
.addPathSegment("kc") .addPathSegment("kc")
.addQueryParameter("name", username) .addQueryParameter("name", username)
.addQueryParameter("boss", boss) .addQueryParameter("boss", boss)
@@ -56,6 +57,7 @@ public class KillCountClient
public int get(String username, String boss) throws IOException public int get(String username, String boss) throws IOException
{ {
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("chat")
.addPathSegment("kc") .addPathSegment("kc")
.addQueryParameter("name", username) .addQueryParameter("name", username)
.addQueryParameter("boss", boss) .addQueryParameter("boss", boss)

View File

@@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.runelite.http.service.kc; package net.runelite.http.service.chat;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
@@ -36,18 +36,18 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/kc") @RequestMapping("/chat")
public class KillCountController public class ChatController
{ {
private final Cache<KillCountKey, Integer> cache = CacheBuilder.newBuilder() private final Cache<KillCountKey, Integer> killCountCache = CacheBuilder.newBuilder()
.expireAfterWrite(2, TimeUnit.MINUTES) .expireAfterWrite(2, TimeUnit.MINUTES)
.maximumSize(128L) .maximumSize(128L)
.build(); .build();
@Autowired @Autowired
private KillCountService killCountService; private ChatService chatService;
@PostMapping @PostMapping("/kc")
public void submit(@RequestParam String name, @RequestParam String boss, @RequestParam int kc) public void submit(@RequestParam String name, @RequestParam String boss, @RequestParam int kc)
{ {
if (kc <= 0) if (kc <= 0)
@@ -55,20 +55,20 @@ public class KillCountController
return; return;
} }
killCountService.setKc(name, boss, kc); chatService.setKc(name, boss, kc);
cache.put(new KillCountKey(name, boss), kc); killCountCache.put(new KillCountKey(name, boss), kc);
} }
@GetMapping @GetMapping("/kc")
public int get(@RequestParam String name, @RequestParam String boss) public int get(@RequestParam String name, @RequestParam String boss)
{ {
Integer kc = cache.getIfPresent(new KillCountKey(name, boss)); Integer kc = killCountCache.getIfPresent(new KillCountKey(name, boss));
if (kc == null) if (kc == null)
{ {
kc = killCountService.getKc(name, boss); kc = chatService.getKc(name, boss);
if (kc != null) if (kc != null)
{ {
cache.put(new KillCountKey(name, boss), kc); killCountCache.put(new KillCountKey(name, boss), kc);
} }
} }

View File

@@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.runelite.http.service.kc; package net.runelite.http.service.chat;
import java.time.Duration; import java.time.Duration;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -31,14 +31,14 @@ import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPool;
@Service @Service
public class KillCountService public class ChatService
{ {
private static final Duration KC_EXPIRE = Duration.ofMinutes(2); private static final Duration EXPIRE = Duration.ofMinutes(2);
private final JedisPool jedisPool; private final JedisPool jedisPool;
@Autowired @Autowired
public KillCountService(JedisPool jedisPool) public ChatService(JedisPool jedisPool)
{ {
this.jedisPool = jedisPool; this.jedisPool = jedisPool;
} }
@@ -57,7 +57,7 @@ public class KillCountService
{ {
try (Jedis jedis = jedisPool.getResource()) try (Jedis jedis = jedisPool.getResource())
{ {
jedis.setex("kc." + name + "." + boss, (int) KC_EXPIRE.getSeconds(), Integer.toString(kc)); jedis.setex("kc." + name + "." + boss, (int) EXPIRE.getSeconds(), Integer.toString(kc));
} }
} }
} }

View File

@@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.runelite.http.service.kc; package net.runelite.http.service.chat;
import lombok.Value; import lombok.Value;

View File

@@ -61,6 +61,7 @@ import net.runelite.client.input.KeyManager;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.util.StackFormatter; import net.runelite.client.util.StackFormatter;
import net.runelite.http.api.chat.ChatClient;
import net.runelite.http.api.hiscore.HiscoreClient; import net.runelite.http.api.hiscore.HiscoreClient;
import net.runelite.http.api.hiscore.HiscoreEndpoint; import net.runelite.http.api.hiscore.HiscoreEndpoint;
import net.runelite.http.api.hiscore.HiscoreResult; import net.runelite.http.api.hiscore.HiscoreResult;
@@ -68,7 +69,6 @@ import net.runelite.http.api.hiscore.HiscoreSkill;
import net.runelite.http.api.hiscore.SingleHiscoreSkillResult; import net.runelite.http.api.hiscore.SingleHiscoreSkillResult;
import net.runelite.http.api.hiscore.Skill; import net.runelite.http.api.hiscore.Skill;
import net.runelite.http.api.item.ItemPrice; import net.runelite.http.api.item.ItemPrice;
import net.runelite.http.api.kc.KillCountClient;
@PluginDescriptor( @PluginDescriptor(
name = "Chat Commands", name = "Chat Commands",
@@ -91,7 +91,7 @@ public class ChatCommandsPlugin extends Plugin
private static final String CMB_COMMAND_STRING = "!cmb"; private static final String CMB_COMMAND_STRING = "!cmb";
private final HiscoreClient hiscoreClient = new HiscoreClient(); private final HiscoreClient hiscoreClient = new HiscoreClient();
private final KillCountClient killCountClient = new KillCountClient(); private final ChatClient chatClient = new ChatClient();
private boolean logKills; private boolean logKills;
private HiscoreEndpoint hiscoreEndpoint; // hiscore endpoint for current player private HiscoreEndpoint hiscoreEndpoint; // hiscore endpoint for current player
@@ -285,7 +285,7 @@ public class ChatCommandsPlugin extends Plugin
{ {
try try
{ {
killCountClient.submit(playerName, boss, kc); chatClient.submit(playerName, boss, kc);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -325,7 +325,7 @@ public class ChatCommandsPlugin extends Plugin
final int kc; final int kc;
try try
{ {
kc = killCountClient.get(player, search); kc = chatClient.get(player, search);
} }
catch (IOException ex) catch (IOException ex)
{ {