mojang 1.0.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mojang.rb +13 -35
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 871ba643bb251bad85c2d2f9f1e8c0bc5a83ed6ba116db0bd43c9353b329b37e
4
- data.tar.gz: 8a1ff13f8de818d4e3396ca193c2522ae9f3a5884e887fe52b5a7e05329ddb03
3
+ metadata.gz: 8eb306005063f2d6ab339d300aee099c0d495ede0a4496ba24e1a0cb14aa6e38
4
+ data.tar.gz: 9c85b85c208a471ea15ae4e557c5dcaf84e88a695ddc71f52551b70c1b022911
5
5
  SHA512:
6
- metadata.gz: 22b93cc476c28a687326f85508161204ae14d4cc5ef8b52442bec5b38ecbdb8a5f399e7f1933ee0dceb2ec402cec65f044e92543c2ce332c40bba38233ee6359
7
- data.tar.gz: 7a22815fe1b6ba43c90ea9affd7b874ed5251edefc96e2b24f1c670b393eac21cfc64c6c9fa2ed14f35c3a1ad39914062240a0f9e5e5e29e0efc5cc87fe6b9a0
6
+ metadata.gz: 2d7110ea93a6647e70d4e6cb66612b76977b2d934675205c3898f0f3d3aa63bfa73109fd207145f3da293590f0034497037137f8346c0b5114b6c9cc50b12e19
7
+ data.tar.gz: c67e8af66afa9d68e6b90b3bc3687c60aa5068d9c9493bb92bc93e50adcb5d68b4b89a842cf34d60841691d7001f995e5a9f465328272dd7f0f7589e8224d20e
@@ -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
- end
32
-
33
- # Gets the username for the given UUID at the given time.
34
- # @param uuid [String] The user's UUID (see #{userid})
35
- # @param date [Date] The date to get the name at.
36
- # @return [String] The user's username at the given time.
37
- def username(uuid, date = nil)
38
- self.profile(uuid, date, 'name')
39
- end
40
-
41
- # Gets whether the given username has paid for Minecraft.
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
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
- response == 'true'
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: 1.0.3
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-08-01 00:00:00.000000000 Z
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.8'
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.8'
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: []