minecraft_auth 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/minecraft_auth.rb +35 -23
- data/lib/minecraft_auth/version.rb +1 -1
- data/test/test_account.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c6e5ce906333cbb04f2cf2bcf707e329d2221ab
|
4
|
+
data.tar.gz: 5422341b61b6d09a3b60b6adb36d5c7802fd63da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4feb3c77ee1582229213d4583e457357a72e5d38ca899148ce500f1e98d2ff97bffef95ebe5a76592f873d5aaaddf22ab80016aeccc137da26ddc9cf066acc4e
|
7
|
+
data.tar.gz: 48e1e2322099d6abce7c7c68c8ff4797bc9821b9e04818486e9ff6b056e4542902dc3bb6d649c05b57ad04fddbe16ec178b159738a9531bf5ec030029f82d082
|
data/lib/minecraft_auth.rb
CHANGED
@@ -10,6 +10,18 @@ module MinecraftAuth
|
|
10
10
|
Account.new(user, pass)
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.username_to_uuid(username)
|
14
|
+
response = HTTParty.post("https://api.mojang.com/profiles/minecraft",
|
15
|
+
:body => [username].to_json,
|
16
|
+
:headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
|
17
|
+
)
|
18
|
+
if response.length >= 1
|
19
|
+
return response[0]["id"]
|
20
|
+
else
|
21
|
+
return nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
13
25
|
class Account
|
14
26
|
attr_reader :username
|
15
27
|
attr_reader :password
|
@@ -23,15 +35,15 @@ module MinecraftAuth
|
|
23
35
|
|
24
36
|
response = HTTParty.post("#{PROTOCOL}#{BASE_URL}#{ENDPOINT}",
|
25
37
|
:body => {
|
26
|
-
|
38
|
+
:"agent" => {
|
27
39
|
:"name" => "Minecraft",
|
28
40
|
:"version" => 1
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
41
|
+
},
|
42
|
+
:"username" => "#{@username}",
|
43
|
+
:"password" => "#{@password}"
|
44
|
+
}.to_json,
|
45
|
+
:headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
|
46
|
+
)
|
35
47
|
# No Error
|
36
48
|
if not response['error']
|
37
49
|
@access_token = response['accessToken']
|
@@ -44,27 +56,27 @@ module MinecraftAuth
|
|
44
56
|
@profiles << Profile.new(profile['name'], profile['id'], selected)
|
45
57
|
end
|
46
58
|
# Error in response
|
47
|
-
|
48
|
-
|
49
|
-
end
|
59
|
+
else
|
60
|
+
raise AccountError, response["errorMessage"]
|
50
61
|
end
|
51
62
|
end
|
63
|
+
end
|
52
64
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
65
|
+
class Profile
|
66
|
+
attr_reader :name
|
67
|
+
attr_reader :id
|
68
|
+
attr_reader :selected
|
57
69
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
70
|
+
def initialize(name, id, selected)
|
71
|
+
@id = id
|
72
|
+
@name = name
|
73
|
+
@selected = selected
|
63
74
|
end
|
75
|
+
end
|
64
76
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
77
|
+
class AccountError < StandardError
|
78
|
+
def initialize(message)
|
79
|
+
super()
|
69
80
|
end
|
70
81
|
end
|
82
|
+
end
|
data/test/test_account.rb
CHANGED
@@ -8,6 +8,14 @@ class AccountTest < Test::Unit::TestCase
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
+
def test_uuid
|
12
|
+
assert_equal "2d5aa9cdaeb049189930461fc9b91cc5", MinecraftAuth.username_to_uuid('Jake0oo0')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_bad_uuid
|
16
|
+
assert_nil MinecraftAuth.username_to_uuid('DoesNotExistUser')
|
17
|
+
end
|
18
|
+
|
11
19
|
# This can be tested if necessary, otherwise credentials should remain private.
|
12
20
|
# def test_valid
|
13
21
|
# assert_raise MinecraftAuth::AccountError do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minecraft_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jake
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|