minecraft version

This commit is contained in:
Alexander Popov 2022-10-07 21:11:35 +03:00
parent e0699931c3
commit eeb05fa7d1
Signed by: iiiypuk
GPG Key ID: D8C9B59A9F04A70C

View File

@ -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