fishbans 1.0.0
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/CHANGELOG.md +4 -0
- data/lib/fishbans.rb +145 -0
- metadata +61 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: e807ff54ca15ada567d8e13f472c8b4f31f46700
|
|
4
|
+
data.tar.gz: 984f4a9bf3a8f6b01be9110c5ecda6f4cfb6f31c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f99d58c22d1b7ff441b9bb23fef758cd2a1bf8ae69fe92d122fee37e63cc9ff3959661f0445e11f19705b6381d1bc2918728a287fca115d193054cbbc0d12f13
|
|
7
|
+
data.tar.gz: eb9b80e8ac26b4555c8e0acfc46331e4c85875b9525540399460b13e47914856a95cb100acb230aa8ba16c9e2056827c40d52c0588e04ecd6419fd6b7b77bece
|
data/CHANGELOG.md
ADDED
data/lib/fishbans.rb
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
require 'httpclient'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
module Fishbans
|
|
5
|
+
extend self
|
|
6
|
+
@client = HTTPClient.new
|
|
7
|
+
@services = [
|
|
8
|
+
'mcbouncer',
|
|
9
|
+
'minebans',
|
|
10
|
+
'glizer',
|
|
11
|
+
'mcblockit',
|
|
12
|
+
'mcbans'
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
# Gets all bans on a user.
|
|
16
|
+
# @param username [String] The username to check.
|
|
17
|
+
# @return [Hash/Nil/String] Either a hash of arrays containing information on
|
|
18
|
+
# the user's bans, or nil if they aren't banned. An error string if the
|
|
19
|
+
# request failed.
|
|
20
|
+
def get_all_bans(username)
|
|
21
|
+
response = get("http://api.fishbans.com/bans/#{username}")
|
|
22
|
+
if response.is_a?(String)
|
|
23
|
+
return response
|
|
24
|
+
else
|
|
25
|
+
return parse_generic_ban_result(response)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Gets all bans for a given service for a user.
|
|
30
|
+
# @param username [String] The username to check.
|
|
31
|
+
# @param service [String] The service to check. Can be any of the values in
|
|
32
|
+
# the @services array.
|
|
33
|
+
# @return [Hash/Nil/Boolean/String] False if the service is not an accepted
|
|
34
|
+
# value. A hash of arrays containing information on the user's bans, or nil
|
|
35
|
+
# if they aren't banned. An error string if the request failed.
|
|
36
|
+
def get_ban_service(username, service)
|
|
37
|
+
service = service.downcase
|
|
38
|
+
|
|
39
|
+
if @services.include? service
|
|
40
|
+
response = get("http://api.fishbans.com/bans/#{username}/#{service}")
|
|
41
|
+
if response.is_a?(String)
|
|
42
|
+
return response
|
|
43
|
+
else
|
|
44
|
+
return parse_generic_ban_result(response)
|
|
45
|
+
end
|
|
46
|
+
else
|
|
47
|
+
return false
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Gets the total number of bans that the user has.
|
|
52
|
+
# @param username [String] The username to check.
|
|
53
|
+
# @return [Int/String] The number of bans the user has. An error string if the
|
|
54
|
+
# request failed.
|
|
55
|
+
def get_total_bans(username)
|
|
56
|
+
response = get("http://api.fishbans.com/stats/#{username}")
|
|
57
|
+
if response.is_a?(String)
|
|
58
|
+
return response
|
|
59
|
+
else
|
|
60
|
+
return response['stats']['totalbans']
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Gets the total number of bans by service that the user has.
|
|
65
|
+
# @param username [String] The username to check.
|
|
66
|
+
# @param service [String] The service to check. Can be any of the values in
|
|
67
|
+
# the @services array.
|
|
68
|
+
# @return [Int/Boolean/String] False if the service is not an accepted value.
|
|
69
|
+
# An int containing the number of bans the user has in the given service. An
|
|
70
|
+
# error string if the request failed.
|
|
71
|
+
def get_total_bans_service(username, service)
|
|
72
|
+
if @services.include?(service)
|
|
73
|
+
# Note that the /service part is not necessary, but it slightly improves
|
|
74
|
+
# performance of the API.
|
|
75
|
+
response = get("http://api.fishbans.com/stats/#{username}/#{service}")
|
|
76
|
+
if response.is_a?(String)
|
|
77
|
+
return response
|
|
78
|
+
else
|
|
79
|
+
return response['stats']['service'][service]
|
|
80
|
+
end
|
|
81
|
+
else
|
|
82
|
+
return false
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Gets the Minecraft UUID for the user.
|
|
87
|
+
# @param username [String] The username to get the ID for.
|
|
88
|
+
# @return [String] The user's UUID. An error string if the request failed.
|
|
89
|
+
def get_userid(username)
|
|
90
|
+
response = get("http://api.fishbans.com/uuid/#{username}")
|
|
91
|
+
if response.is_a?(String)
|
|
92
|
+
return response
|
|
93
|
+
else
|
|
94
|
+
return response['uuid']
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Gets username history for the user.
|
|
99
|
+
# @param username [String] The username to get history for.
|
|
100
|
+
# @return [Array/String] Array of strings containing old usernames. An error
|
|
101
|
+
# string if the request failed.
|
|
102
|
+
def get_username_history(username)
|
|
103
|
+
response = get("http://api.fishbans.com/history/#{username}")
|
|
104
|
+
if response.is_a?(String)
|
|
105
|
+
return response
|
|
106
|
+
else
|
|
107
|
+
return response['data']['history']
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
private
|
|
112
|
+
# Performs a basic GET request.
|
|
113
|
+
# @param url [String] The URL to get.
|
|
114
|
+
# @return [JSON/String] The parsed JSON of the response, or the error string.
|
|
115
|
+
def get(url)
|
|
116
|
+
url = URI.encode(url)
|
|
117
|
+
uri = URI.parse(url)
|
|
118
|
+
response = @client.get(uri)
|
|
119
|
+
if response['success']
|
|
120
|
+
return JSON.parse(response.body)
|
|
121
|
+
else
|
|
122
|
+
return response['error']
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Parses a basic ban result into a formatted hash.
|
|
127
|
+
# @param response [JSON] The response to parse.
|
|
128
|
+
# @return [Hash/Nil] Nil if there are no bans in the response, or a hash of
|
|
129
|
+
# arrays containing the user's bans.
|
|
130
|
+
def parse_generic_ban_result(response)
|
|
131
|
+
ret = {}
|
|
132
|
+
response['bans']['service'].each do |b, i|
|
|
133
|
+
next if i['bans'] == 0
|
|
134
|
+
i['ban_info'].each do |s, r|
|
|
135
|
+
ret[b] = [
|
|
136
|
+
i['bans'],
|
|
137
|
+
{ s => r }
|
|
138
|
+
]
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
return nil if ret.empty?
|
|
143
|
+
return ret
|
|
144
|
+
end
|
|
145
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: fishbans
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Eli Foster
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-10-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: httpclient
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
description: Accessing the Fishbans Minecraft API through HTTPClient. Has methods
|
|
28
|
+
for all Fishban APIs.
|
|
29
|
+
email: elifosterwy@gmail.com
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- CHANGELOG.md
|
|
35
|
+
- lib/fishbans.rb
|
|
36
|
+
homepage: https://github.com/elifoster/fishbans-rb
|
|
37
|
+
licenses:
|
|
38
|
+
- CC-BY-NC-ND-4.0
|
|
39
|
+
metadata:
|
|
40
|
+
issue_tracker: https://github.com/elifoster/fishbans-rb/issues
|
|
41
|
+
post_install_message:
|
|
42
|
+
rdoc_options: []
|
|
43
|
+
require_paths:
|
|
44
|
+
- lib
|
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '0'
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
requirements: []
|
|
56
|
+
rubyforge_project:
|
|
57
|
+
rubygems_version: 2.4.5.1
|
|
58
|
+
signing_key:
|
|
59
|
+
specification_version: 4
|
|
60
|
+
summary: A Ruby gem for accessing the Fishbans Minecraft API.
|
|
61
|
+
test_files: []
|