mojang 1.0.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mojang.rb +13 -35
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8eb306005063f2d6ab339d300aee099c0d495ede0a4496ba24e1a0cb14aa6e38
|
4
|
+
data.tar.gz: 9c85b85c208a471ea15ae4e557c5dcaf84e88a695ddc71f52551b70c1b022911
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d7110ea93a6647e70d4e6cb66612b76977b2d934675205c3898f0f3d3aa63bfa73109fd207145f3da293590f0034497037137f8346c0b5114b6c9cc50b12e19
|
7
|
+
data.tar.gz: c67e8af66afa9d68e6b90b3bc3687c60aa5068d9c9493bb92bc93e50adcb5d68b4b89a842cf34d60841691d7001f995e5a9f465328272dd7f0f7589e8224d20e
|
data/lib/mojang.rb
CHANGED
@@ -28,24 +28,20 @@ module Mojang
|
|
28
28
|
# @return [String] The username's user ID.
|
29
29
|
def userid(username, date = nil)
|
30
30
|
self.profile(username, date, 'id')
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
# @return [Boolean] Whether they have paid or not.
|
44
|
-
def has_paid?(username)
|
45
|
-
params = { user: username }
|
46
|
-
response = Curl.get('https://minecraft.net/haspaid.jsp', params).body_str
|
31
|
+
profile_str = "https://api.mojang.com/users/profiles/minecraft/#{username}"
|
32
|
+
# If the provided date (or 0, if not provided) does not return anything, try without any date provided at all.
|
33
|
+
# This is necessary because for users with name history's *have* you have to provide some date (and 0 is valid),
|
34
|
+
# while for users who do *not* have name history, giving a date (including 0) will return 204 No Content.
|
35
|
+
# If it is *still* empty after both tries, then error.
|
36
|
+
response = Curl.get(profile_str, { at: date.to_i }).body_str
|
37
|
+
response = Curl.get(profile_str).body_str if response.empty?
|
38
|
+
fail NoSuchUserError.new(query) if response.empty?
|
39
|
+
json = Oj.load(response)
|
40
|
+
if json.key?('error')
|
41
|
+
fail Mojang::Errors::MojangError.new(json['error'], json['errorMessage'])
|
42
|
+
end
|
47
43
|
|
48
|
-
|
44
|
+
json['id']
|
49
45
|
end
|
50
46
|
|
51
47
|
# Gets a user's name history from their UUID.
|
@@ -66,22 +62,4 @@ module Mojang
|
|
66
62
|
|
67
63
|
ret
|
68
64
|
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
# Gets the profile data.
|
73
|
-
# @param query [String] Either a username or an ID; they are handled in the same way.
|
74
|
-
# @param date [Date] The date to get at.
|
75
|
-
# @param return_val [String] The key in the returned hash to return.
|
76
|
-
# @return [String] The returned value for the return_val key.
|
77
|
-
def self.profile(query, date, return_val)
|
78
|
-
params = { at: date.to_i }
|
79
|
-
response = Curl.get("https://api.mojang.com/users/profiles/minecraft/#{query}", params).body_str
|
80
|
-
fail NoSuchUserError.new(query) if response.empty?
|
81
|
-
json = Oj.load(response)
|
82
|
-
if json.key?('error')
|
83
|
-
fail MojangError.new(json['error'], json['errorMessage'])
|
84
|
-
end
|
85
|
-
return json[return_val]
|
86
|
-
end
|
87
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mojang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eli Foster
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curb
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '3.
|
33
|
+
version: '3.9'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '3.
|
40
|
+
version: '3.9'
|
41
41
|
description: A Ruby library accessing the Mojang and Minecraft web APIs
|
42
42
|
email: elifosterwy@gmail.com
|
43
43
|
executables: []
|