update minecraft name changes automatically

This commit is contained in:
jomo
2015-02-08 00:32:52 +01:00
parent c45a888e1e
commit e887e3d1da
2 changed files with 34 additions and 1 deletions

View File

@@ -27,4 +27,26 @@ require "open-uri"
yt
end
def fetch_name(uuid)
uri = URI.parse("https://api.mojang.com/user/profiles/#{CGI.escape(uuid)}/names")
http = Net::HTTP.new(uri.host, uri.port)
http.open_timeout = 3
http.read_timeout = 3
http.use_ssl = true
begin
response = http.get(uri)
if response.code == "200"
data = JSON.load(response.body)
return data.last["name"]
end
rescue => e
Rails.logger.error "----"
Rails.logger.error "Failed to get mojang profile for #{uuid}"
Rails.logger.error e.message
Rails.logger.error "----"
return nil
end
end
end