minecraft version
This commit is contained in:
parent
e0699931c3
commit
eeb05fa7d1
21
src/modules/minecraft_version.cr
Normal file
21
src/modules/minecraft_version.cr
Normal 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
|
Loading…
Reference in New Issue
Block a user