mojang_api 0.0.1
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 +7 -0
- data/.gitignore +34 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +13 -0
- data/Rakefile +2 -0
- data/console.rb +9 -0
- data/lib/mojang_api.rb +36 -0
- data/lib/mojang_api/profile.rb +80 -0
- data/lib/mojang_api/version.rb +3 -0
- data/lib/mojang_api/whitelist.rb +8 -0
- data/lib/mojang_api/whitelist/base.rb +51 -0
- data/lib/mojang_api/whitelist/one_seven.rb +14 -0
- data/lib/mojang_api/whitelist/one_six.rb +14 -0
- data/mojang_api.gemspec +25 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bffb2c03109fdb1916fc77f8877571ce641f2651
|
4
|
+
data.tar.gz: 45fbbf50a9a2bdf73912bf4670ee97017ca133cd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1ab345871c85dc76003f7ab4f1820cc918be1b5686ac2d7dc4d0f7c42f3bdd9a2b6cb8c4f4d4f945a5bc5cdd0512bc1e5f5873ced145aa227012bc605475cd90
|
7
|
+
data.tar.gz: dc2025f7f387d55230d887cfb626078689b28905b02c8ada52ce03d06c1ebf716a2af393ca70b75c171b01b5bef8545be34aa5f4e7776888545aab132dcdfe07
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
Gemfile.lock
|
30
|
+
.ruby-version
|
31
|
+
.ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 down slope
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 downslope7
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# MojangApi
|
2
|
+
|
3
|
+
A quick ruby gem for utilizing the Mojang Profile/UUID api and managing multiple versions of whitelists.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
MojangApi.get_profile_from_name('downslope7')
|
9
|
+
|
10
|
+
MojangApi.get_profile_from_uuid('8cf6171562164903bb03e9653c4eba15')
|
11
|
+
|
12
|
+
MojangApi.get_profiles_from_name_list(['notch','Dinnerbone', 'Djinnibone', 'downslope7'])
|
13
|
+
```
|
data/Rakefile
ADDED
data/console.rb
ADDED
data/lib/mojang_api.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
require "mojang_api/version"
|
4
|
+
require "mojang_api/profile"
|
5
|
+
require "mojang_api/whitelist"
|
6
|
+
|
7
|
+
module MojangApi
|
8
|
+
def self.get_profile_from_name(name, opts={})
|
9
|
+
game = opts.fetch(:game, 'minecraft')
|
10
|
+
uuid_time = opts.fetch(:at_time, Time.now)
|
11
|
+
|
12
|
+
p = Profile.new name: name, uuid_time: uuid_time, game: game
|
13
|
+
p.load_uuid
|
14
|
+
p
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get_uuid_from_name(name, opts={})
|
18
|
+
get_profile_from_name(name, opts).uuid
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.get_profile_from_uuid(uuid, opts={})
|
22
|
+
game = opts.fetch(:game, 'minecraft')
|
23
|
+
|
24
|
+
p = Profile.new uuid: uuid, game: game
|
25
|
+
p.load_name
|
26
|
+
p
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.get_name_from_uuid(uuid, opts={})
|
30
|
+
get_profile_from_uuid(uuid, opts).name
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.get_profiles_from_name_list(name_list)
|
34
|
+
Profile.load_from_name_list(name_list)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module MojangApi
|
2
|
+
class Profile
|
3
|
+
include HTTParty
|
4
|
+
base_uri "https://api.mojang.com"
|
5
|
+
|
6
|
+
def initialize(params={})
|
7
|
+
@name = params.fetch(:name, nil)
|
8
|
+
@game = params.fetch(:game, 'minecraft')
|
9
|
+
self.uuid = params.fetch(:uuid, nil)
|
10
|
+
@uuid_time = params.fetch(:uuid_time, Time.now)
|
11
|
+
end
|
12
|
+
|
13
|
+
def uuid
|
14
|
+
@uuid || load_uuid(@uuid_time)
|
15
|
+
end
|
16
|
+
|
17
|
+
def uuid=(new_uuid)
|
18
|
+
new_uuid = new_uuid.strip.tr('-', '')
|
19
|
+
raise "UUID is incorrect length." if new_uuid.length != 32
|
20
|
+
@uuid = new_uuid
|
21
|
+
end
|
22
|
+
|
23
|
+
def dashed_uuid
|
24
|
+
"#{uuid[0..7]}-#{uuid[8..11]}-#{uuid[12..15]}-#{uuid[16..19]}-#{uuid[20..31]}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def name
|
28
|
+
@name || load_name
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_uuid(at = nil)
|
32
|
+
opts = { format: :json }
|
33
|
+
opts[:query] = { at: at.to_i } if at
|
34
|
+
response = self.class.get("/users/profiles/#{@game}/#{@name}", opts)
|
35
|
+
@uuid = response['id']
|
36
|
+
@uuid_time = at.nil? ? Time.now : at
|
37
|
+
@uuid
|
38
|
+
end
|
39
|
+
|
40
|
+
def load_name
|
41
|
+
response = self.class.get("/user/profiles/#{@uuid}/names", format: :json)
|
42
|
+
if response.ok?
|
43
|
+
if response.length > 1
|
44
|
+
raise "Multiple names for that UUID, unknown behavior!"
|
45
|
+
end
|
46
|
+
|
47
|
+
else
|
48
|
+
raise "Unable to find that UUID."
|
49
|
+
end
|
50
|
+
@name = response[0]
|
51
|
+
@name
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_whitelist_format(version = :v17)
|
55
|
+
{
|
56
|
+
uuid: formatted_uuid,
|
57
|
+
name: name
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
class << self
|
62
|
+
def load_from_name_list(usernames = [], game='minecraft')
|
63
|
+
all_responses = []
|
64
|
+
usernames = usernames.reject(&:empty?)
|
65
|
+
usernames.uniq.each_slice(100) do |username_slice|
|
66
|
+
opts = {
|
67
|
+
body: username_slice.to_json,
|
68
|
+
headers: {"Content-Type" => "application/json"}
|
69
|
+
}
|
70
|
+
response = post("/profiles/#{game}",opts)
|
71
|
+
all_responses += response.map {|result| new(name: result['name'], uuid: result['id'], game: game)}
|
72
|
+
end
|
73
|
+
|
74
|
+
all_responses.sort_by! { |profile| profile.name }
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module MojangApi
|
2
|
+
module Whitelist
|
3
|
+
class Base
|
4
|
+
attr_reader :profiles
|
5
|
+
|
6
|
+
def initialize(profiles = [])
|
7
|
+
@profiles = profiles
|
8
|
+
end
|
9
|
+
|
10
|
+
def load_from(filename)
|
11
|
+
f = File.open(filename, "r")
|
12
|
+
parse f
|
13
|
+
f.close
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def save_to(filename)
|
18
|
+
File.open(filename, "w") { |f| f.write(serialize) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_version(version)
|
22
|
+
case version
|
23
|
+
when :v16
|
24
|
+
OneSix.new(@profiles.dup)
|
25
|
+
when :v17
|
26
|
+
OneSeven.new(@profiles.dup)
|
27
|
+
else
|
28
|
+
raise "No such version!"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class << self
|
33
|
+
def load_from(filename)
|
34
|
+
instance = new
|
35
|
+
instance.load_from(filename)
|
36
|
+
instance
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
def parse(input)
|
42
|
+
raise 'Not Implemented'
|
43
|
+
end
|
44
|
+
|
45
|
+
def serialize
|
46
|
+
raise 'Not Implemented'
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MojangApi
|
2
|
+
module Whitelist
|
3
|
+
class OneSix < Base
|
4
|
+
protected
|
5
|
+
|
6
|
+
def parse(input)
|
7
|
+
usernames = []
|
8
|
+
input.each_line { |username| usernames << username.strip }
|
9
|
+
@profiles = MojangApi.get_profiles_from_name_list(usernames)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/mojang_api.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mojang_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mojang_api"
|
8
|
+
spec.version = MojangApi::VERSION
|
9
|
+
spec.authors = ["downslope7"]
|
10
|
+
spec.email = ["downslope7@lovesyourmom.com"]
|
11
|
+
spec.summary = %q{Mojang UUID/profile API}
|
12
|
+
spec.description = %q{Get Mojang profile information coming from a username or a UUID. Will also read in whitelist data and output whitelists in pre-1.7 and 1.7+ formats.}
|
13
|
+
spec.homepage = "https://github.com/downslope7/mojang_api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "pry"
|
24
|
+
spec.add_dependency "httparty"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mojang_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- downslope7
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Get Mojang profile information coming from a username or a UUID. Will
|
70
|
+
also read in whitelist data and output whitelists in pre-1.7 and 1.7+ formats.
|
71
|
+
email:
|
72
|
+
- downslope7@lovesyourmom.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- console.rb
|
84
|
+
- lib/mojang_api.rb
|
85
|
+
- lib/mojang_api/profile.rb
|
86
|
+
- lib/mojang_api/version.rb
|
87
|
+
- lib/mojang_api/whitelist.rb
|
88
|
+
- lib/mojang_api/whitelist/base.rb
|
89
|
+
- lib/mojang_api/whitelist/one_seven.rb
|
90
|
+
- lib/mojang_api/whitelist/one_six.rb
|
91
|
+
- mojang_api.gemspec
|
92
|
+
homepage: https://github.com/downslope7/mojang_api
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.2.2
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Mojang UUID/profile API
|
116
|
+
test_files: []
|