mojang 1.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +5 -5
  2. data/lib/errors.rb +1 -1
  3. data/lib/mojang.rb +19 -36
  4. metadata +8 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6c44a0dac6fa4c910273329517229956c875dac6
4
- data.tar.gz: e0de84e87ac781be46818e8b455a0571d1906cec
2
+ SHA256:
3
+ metadata.gz: 2955c17e484341fe800541d53d9464796b9699954956cc3c834040022d541e62
4
+ data.tar.gz: 59d3d6cf56987bef1c0ee6fd1b85cfed18bb93c3fdabf7a1a7ef71378b8d0aae
5
5
  SHA512:
6
- metadata.gz: a14c81231962006186e8bf2e0e2371bda7e9fcd84039a93fb03ed7d8ddbf62e9dcf55e53fb528e03dd14a4216f3d4525a0dff1c3f3696f5c2f7b3d29a1643caa
7
- data.tar.gz: e0e9699dabdf7483be7a9e95f278544e07240a745268f090fef20a48c51e5e5de5c093958bcca372c6a5245df347efb80b419f047b8d586531ce097d3427d610
6
+ metadata.gz: 066bf06261ee40c316bb1cd77b92cf52ce737eb285900fdf57ea34c9d3f47babe8d8c297e671543f0767d335484ce56281bb2fe20f9717eb0c61f8a89142adee
7
+ data.tar.gz: 4253a83f9ceae4f18b8dc5fe1bf4ec77df0b41e622d165f295e010061907bc11dffd262ba68e827ad61f3f869ad143d80bcdcb05baa6fea4dfc6bc74b1278b85
@@ -22,7 +22,7 @@ module Mojang
22
22
  end
23
23
 
24
24
  def message
25
- "#{@msg} (#{@error}"
25
+ "#{@msg} (#{@error})"
26
26
  end
27
27
  end
28
28
  end
@@ -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
- 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
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
- response == 'true'
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: 1.0.1
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: 2016-04-03 00:00:00.000000000 Z
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: '2.15'
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: '2.15'
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
- rubyforge_project:
71
- rubygems_version: 2.5.1
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: []