more fixes, changes, support for new mojang API

This commit is contained in:
jomo
2014-04-18 14:35:18 +02:00
parent 7135d2690c
commit 0264f239ba
62 changed files with 4927 additions and 15 deletions

View File

@@ -136,17 +136,23 @@ class User < ActiveRecord::Base
# end
def get_profile
uri = URI.parse("https://api.mojang.com/profiles")
uri = URI.parse("https://api.mojang.com/profiles/minecraft")
http = Net::HTTP.new(uri.host, uri.port)
http.open_timeout = 5
http.read_timeout = 20
http.use_ssl = true
payload = { agent: "Minecraft", name: self.ign }
begin
response = http.post(uri.request_uri, payload.to_json, "Content-Type" => "application/json")
response = http.post(uri.request_uri, [self.ign].to_json, "Content-Type" => "application/json")
if response.code == "200"
return JSON.load(response.body)["profiles"][0]
data = JSON.load(response.body)
if data.length == 1
return data[0]
elsif data.length > 1
raise "Multiple accounts for user #{self.ign}: '#{response.body}'"
elsif data.length < 1
return nil
end
end
rescue => e
puts "----"