From eeb05fa7d1dbdd8cb0aecb3f8a21761bd0722edb Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Fri, 7 Oct 2022 21:11:35 +0300 Subject: [PATCH] minecraft version --- src/modules/minecraft_version.cr | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/modules/minecraft_version.cr diff --git a/src/modules/minecraft_version.cr b/src/modules/minecraft_version.cr new file mode 100644 index 0000000..bc8935c --- /dev/null +++ b/src/modules/minecraft_version.cr @@ -0,0 +1,21 @@ +require "json" +require "http/client" + +get "/api/v1.0/minecraft_version" do |env| + minecraft_url = "https://launchermeta.mojang.com/mc/game/version_manifest_v2.json" + + # TODO: Кеширование + response = HTTP::Client.get minecraft_url + + version_manifest = JSON.parse(response.body) + + if env.params.query["json"]? + env.response.content_type = "application/json" + version = {release: version_manifest["latest"]["release"]}.to_json + + version + else + env.response.content_type = "text/plain" + version_manifest["latest"]["release"].to_s + end +end