mojang 1.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/errors.rb +1 -1
- data/lib/mojang.rb +19 -36
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2955c17e484341fe800541d53d9464796b9699954956cc3c834040022d541e62
|
4
|
+
data.tar.gz: 59d3d6cf56987bef1c0ee6fd1b85cfed18bb93c3fdabf7a1a7ef71378b8d0aae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 066bf06261ee40c316bb1cd77b92cf52ce737eb285900fdf57ea34c9d3f47babe8d8c297e671543f0767d335484ce56281bb2fe20f9717eb0c61f8a89142adee
|
7
|
+
data.tar.gz: 4253a83f9ceae4f18b8dc5fe1bf4ec77df0b41e622d165f295e010061907bc11dffd262ba68e827ad61f3f869ad143d80bcdcb05baa6fea4dfc6bc74b1278b85
|
data/lib/errors.rb
CHANGED
data/lib/mojang.rb
CHANGED
@@ -26,35 +26,36 @@ module Mojang
|
|
26
26
|
# @param username [String] The username.
|
27
27
|
# @param date [Date] The date to get the ID at.
|
28
28
|
# @return [String] The username's user ID.
|
29
|
+
# @raise [Mojang::Errors::MojangError]
|
30
|
+
# @raise [Mojang::Errors::NoSuchUserError]
|
29
31
|
def userid(username, date = nil)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
# @param username [String] The username to check.
|
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
|
32
|
+
profile_str = "https://api.mojang.com/users/profiles/minecraft/#{username}"
|
33
|
+
# If the provided date (or 0, if not provided) does not return anything, try without any date provided at all.
|
34
|
+
# This is necessary because for users with name history's *have* you have to provide some date (and 0 is valid),
|
35
|
+
# while for users who do *not* have name history, giving a date (including 0) will return 204 No Content.
|
36
|
+
# If it is *still* empty after both tries, then error.
|
37
|
+
response = Curl.get(profile_str, { at: date.to_i }).body_str
|
38
|
+
response = Curl.get(profile_str).body_str if response.empty?
|
39
|
+
fail Mojang::Errors::NoSuchUserError.new(username) if response.empty?
|
40
|
+
json = Oj.load(response)
|
41
|
+
if json.key?('error')
|
42
|
+
fail Mojang::Errors::MojangError.new(json['error'], json['errorMessage'])
|
43
|
+
end
|
47
44
|
|
48
|
-
|
45
|
+
json['id']
|
49
46
|
end
|
50
47
|
|
51
48
|
# Gets a user's name history from their UUID.
|
52
49
|
# @param uuid [String] The user's ID (see #{userid}).
|
53
50
|
# @return [Hash<Symbol/Time, String>] A hash of all the names. Key is either :original, or the Time object of when
|
54
51
|
# the name was changed. Value is always the name at that point in time.
|
52
|
+
# @raise [Mojang::Errors::MojangError]
|
55
53
|
def name_history(uuid)
|
56
54
|
response = Curl.get("https://api.mojang.com/user/profiles/#{uuid}/names").body_str
|
57
55
|
json = Oj.load(response)
|
56
|
+
if json.key?('error')
|
57
|
+
fail Mojang::Errors::MojangError.new(json['error'], json['errorMessage'])
|
58
|
+
end
|
58
59
|
ret = {}
|
59
60
|
json.each do |hash|
|
60
61
|
if hash.key?('changedToAt')
|
@@ -66,22 +67,4 @@ module Mojang
|
|
66
67
|
|
67
68
|
ret
|
68
69
|
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
70
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eli Foster
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-18 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: '
|
33
|
+
version: '3.11'
|
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: '
|
40
|
+
version: '3.11'
|
41
41
|
description: A Ruby library accessing the Mojang and Minecraft web APIs
|
42
42
|
email: elifosterwy@gmail.com
|
43
43
|
executables: []
|
@@ -52,7 +52,7 @@ licenses:
|
|
52
52
|
- MIT
|
53
53
|
metadata:
|
54
54
|
issue_tracker: https://github.com/elifoster/mojang-rb/issues
|
55
|
-
post_install_message:
|
55
|
+
post_install_message:
|
56
56
|
rdoc_options: []
|
57
57
|
require_paths:
|
58
58
|
- lib
|
@@ -67,9 +67,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
requirements: []
|
70
|
-
|
71
|
-
|
72
|
-
signing_key:
|
70
|
+
rubygems_version: 3.2.3
|
71
|
+
signing_key:
|
73
72
|
specification_version: 4
|
74
73
|
summary: Mojang and Minecraft web APIs in Ruby
|
75
74
|
test_files: []
|