fishbans 1.1.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06f227a174210eb010e8dd19316428c6a990ba25
4
- data.tar.gz: 6526c7c298b8cb1b23682278380b5aa3b6e839f0
3
+ metadata.gz: 8afd3ab3a10bb5c4fd3749df793ec8a329ba8750
4
+ data.tar.gz: 239ee72e8c6559c1484d5beff351529876024841
5
5
  SHA512:
6
- metadata.gz: c29b2241ddd6d93e094b0dfa96e7bf198f55b3530886c68c0301c1ddf5e5ea0908b4c10eacca16ccedcca6005299460c8f5d64ebd14128a04272a0535d3bc952
7
- data.tar.gz: 389eaa3a1001a38eff9a3c4c18261444336abbdb4bb5948346e27428187605b1434bb03c6cc60cb2ac98d7a0e6f927bebdfc77241f3a6c1950598ae5174dcd9c
6
+ metadata.gz: 0edc84dbb944088d4fe827c44787acc37cccf27b2ee0650ea8c70630745bba5ebac3b3e380344876c93fbd3d0b96c635153b4a284960a45495259fdff455b3ff
7
+ data.tar.gz: 00f6bf0aea58828100e87bafa8fffee4c0ee47782390f27ccfe5a1fdb634b7ccfba4f6e1deb099c42169ff09716ca4e3986f01330d50a87a9b76054e29e0f760
@@ -1,4 +1,11 @@
1
1
  # Changelog
2
+ ## Version 2
3
+ ### Version 2.0.0
4
+ * The `services` array is now a constant as `Fishbans::SERVICES`.
5
+ * Error strings are no longer returned from methods, but thrown as RuntimeErrors.
6
+ * `parse_generic_ban_result` no longer returns a hash of arrays, but a hash of hashes. See the docs for more details.
7
+ * Update to Ruby 2.4.0: `Fixnum` -> `Integer` in documentation.
8
+
2
9
  ## Version 1
3
10
  ### Version 1.1.4
4
11
  * Remove a couple unnecessary things from the PlayerSkins and BlockEngine (is_a? check and downcase).
@@ -6,10 +6,11 @@ module Fishbans
6
6
  # Gets a block image by its ID and Metadata. Unfortunately it uses the old
7
7
  # block IDs rather than the new ones, so you have to memorize those
8
8
  # pesky integers.
9
- # @param id [Fixnum] The (outdated) block ID number.
10
- # @param metadata [Fixnum] The metadata, if any, for the block.
9
+ # @param id [Integer] The (outdated) block ID number.
10
+ # @param metadata [Integer] The metadata, if any, for the block.
11
11
  # @param size [Fixnum] The size of the image to get.
12
12
  # @return [ChunkyPNG::Image] The ChunkyPNG instance of that block image.
13
+ # @raise see #get
13
14
  def get_block(id, metadata = nil, size = 42)
14
15
  url = "http://blocks.fishbans.com/#{id}"
15
16
  url += "-#{metadata}" unless metadata.nil?
@@ -25,9 +26,10 @@ module Fishbans
25
26
  # @param three [Boolean] Whether to get a three-dimensional monster image.
26
27
  # The three-dimensional image is of the full monster, while the
27
28
  # two-dimensional image is just its head.
28
- # @param size [Fixnum] The size of the image (width) to get. For 3D images
29
+ # @param size [Integer] The size of the image (width) to get. For 3D images
29
30
  # this will not be perfect just by nature of the API.
30
31
  # @return [ChunkyPNG::Image] The ChunkyPNG instance of that monster image.
32
+ # @raise see #get
31
33
  def get_monster(id, three = false, size = 42)
32
34
  id = id.to_s
33
35
  url = 'http://blocks.fishbans.com'
@@ -9,7 +9,7 @@ module Fishbans
9
9
 
10
10
  extend self
11
11
  @client = HTTPClient.new
12
- @services = [
12
+ SERVICES = [
13
13
  'mcbouncer',
14
14
  'minebans',
15
15
  'glizer',
@@ -19,136 +19,109 @@ module Fishbans
19
19
 
20
20
  # Gets all bans on a user.
21
21
  # @param username [String] The username to check.
22
- # @return [Hash/Nil/String] Either a hash of arrays containing information on
23
- # the user's bans, or nil if they aren't banned. An error string if the
24
- # request failed.
22
+ # @return see #parse_generic_ban_result
23
+ # @raise see #get
25
24
  def get_all_bans(username)
26
25
  response = get("http://api.fishbans.com/bans/#{username}")
27
- if response.is_a?(String)
28
- return response
29
- else
30
- return parse_generic_ban_result(response)
31
- end
26
+ parse_generic_ban_result(response)
32
27
  end
33
28
 
34
29
  # Gets all bans for a given service for a user.
35
30
  # @param username [String] The username to check.
36
- # @param service [String] The service to check. Can be any of the values in
37
- # the @services array.
38
- # @return [Hash/Nil/Boolean/String] False if the service is not an accepted
39
- # value. A hash of arrays containing information on the user's bans, or nil
40
- # if they aren't banned. An error string if the request failed.
31
+ # @param service [String] The service to check. Can be any of the values in the SERVICES array.
32
+ # @return [Boolean] False if the service is not an accepted value.
33
+ # @return [Hash<String, String>] Key: Minecraft server; value: reason
34
+ # @raise see #get
41
35
  def get_ban_service(username, service)
42
- service = service.downcase
36
+ service.downcase!
43
37
 
44
- if @services.include? service
38
+ if SERVICES.include? service
45
39
  response = get("http://api.fishbans.com/bans/#{username}/#{service}")
46
- if response.is_a?(String)
47
- return response
48
- else
49
- return parse_generic_ban_result(response)
50
- end
40
+ parse_generic_ban_result(response)[service]
51
41
  else
52
- return false
42
+ false
53
43
  end
54
44
  end
55
45
 
56
46
  # Gets the total number of bans that the user has.
57
47
  # @param username [String] The username to check.
58
- # @return [Int/String] The number of bans the user has. An error string if the
59
- # request failed.
48
+ # @return [Integer] The number of bans the user has.
49
+ # @raise see #get
60
50
  def get_total_bans(username)
61
51
  response = get("http://api.fishbans.com/stats/#{username}")
62
- if response.is_a?(String)
63
- return response
64
- else
65
- return response['stats']['totalbans']
66
- end
52
+ response['stats']['totalbans']
67
53
  end
68
54
 
69
55
  # Gets the total number of bans by service that the user has.
70
56
  # @param username [String] The username to check.
71
57
  # @param service [String] The service to check. Can be any of the values in
72
- # the @services array.
73
- # @return [Int/Boolean/String] False if the service is not an accepted value.
74
- # An int containing the number of bans the user has in the given service. An
75
- # error string if the request failed.
58
+ # the SERVICES array.
59
+ # @return [Boolean] False if the service is not an accepted value.
60
+ # @return [Integer] The number of bans the user has in the given service. See SERVICES for valid services.
61
+ # @raise see #get
76
62
  def get_total_bans_service(username, service)
77
- if @services.include?(service)
63
+ service.downcase!
64
+
65
+ if SERVICES.include?(service)
78
66
  # Note that the /service part is not necessary, but it slightly improves
79
67
  # performance of the API.
80
68
  response = get("http://api.fishbans.com/stats/#{username}/#{service}")
81
- if response.is_a?(String)
82
- return response
83
- else
84
- return response['stats']['service'][service]
85
- end
69
+ response['stats']['service'][service]
86
70
  else
87
- return false
71
+ false
88
72
  end
89
73
  end
90
74
 
91
75
  # Gets the Minecraft UUID for the user.
92
76
  # @param username [String] The username to get the ID for.
93
- # @return [String] The user's UUID. An error string if the request failed.
77
+ # @return [String] The user's UUID.
78
+ # @raise see #get
94
79
  def get_userid(username)
95
80
  response = get("http://api.fishbans.com/uuid/#{username}")
96
- if response.is_a?(String)
97
- return response
98
- else
99
- return response['uuid']
100
- end
81
+ response['uuid']
101
82
  end
102
83
 
103
84
  # Gets username history for the user.
104
85
  # @param username [String] The username to get history for.
105
- # @return [Array/String] Array of strings containing old usernames. An error
106
- # string if the request failed.
86
+ # @return [Array<String>] Array of strings containing old usernames.
87
+ # @raise see #get
107
88
  def get_username_history(username)
108
89
  response = get("http://api.fishbans.com/history/#{username}")
109
- if response.is_a?(String)
110
- return response
111
- else
112
- return response['data']['history']
113
- end
90
+ response['data']['history']
114
91
  end
115
92
 
116
93
  private
117
94
 
118
95
  # Performs a basic GET request.
119
96
  # @param url [String] The URL to get.
120
- # @param do_json [Boolean] Whether to parse the JSON.
121
- # @return [JSON/String] The parsed JSON of the response, or the error string.
97
+ # @param do_json [Boolean] Whether to parse the JSON before returning.
98
+ # @return [Hash] The parsed JSON of the response, if do_json is true.
99
+ # @return [HTTP::Message] Unparsed response, if do_json is false.
100
+ # @raise [RuntimeError] An error if the request is not successful.
122
101
  def get(url, do_json = true)
123
102
  url = URI.encode(url)
124
103
  uri = URI.parse(url)
125
104
  response = @client.get(uri)
126
- return response if do_json == false
105
+ return response unless do_json
127
106
  json = JSON.parse(response.body)
128
- if json['success']
129
- return json
130
- else
131
- return json['error']
132
- end
107
+ return json if json['success']
108
+ fail json['error']
133
109
  end
134
110
 
135
- # Parses a basic ban result into a formatted hash.
111
+ # Parses a basic ban result into a formatted hash. This assumes it is not an errored response.
136
112
  # @param response [JSON] The response to parse.
137
- # @return [Hash/Nil] Nil if there are no bans in the response, or a hash of
138
- # arrays containing the user's bans.
113
+ # @return [Hash<String, Hash<String, String>>] Service (see SERVICES) is the key; value is a hash with
114
+ # server as the key, and the reason as the value. Empty hash if there are no bans.
139
115
  def parse_generic_ban_result(response)
140
116
  ret = {}
141
- response['bans']['service'].each do |b, i|
142
- next if i['bans'] == 0
143
- i['ban_info'].each do |s, r|
144
- ret[b] = [
145
- i['bans'],
146
- { s => r }
147
- ]
117
+ response['bans']['service'].each do |service, info|
118
+ next if info['bans'] == 0
119
+ ret[service] = {}
120
+ info['ban_info'].each do |server, reason|
121
+ ret[service][server] = reason
148
122
  end
149
123
  end
150
124
 
151
- return nil if ret.empty?
152
125
  ret
153
126
  end
154
127
  end
@@ -5,24 +5,27 @@ module Fishbans
5
5
  module PlayerSkins
6
6
  # Gets the image for the front face of the player head.
7
7
  # @param username [String] The username to get the head of.
8
- # @param size [Fixnum] The width of the image to get.
8
+ # @param size [Integer] The width of the image to get.
9
9
  # @return [ChunkyPNG::Image] The ChunkyPNG::Image instance of that head.
10
+ # @raise see #get
10
11
  def get_player_head(username, size = 100)
11
12
  get_player_image(username, 'helm', size)
12
13
  end
13
14
 
14
15
  # Gets the image for the entire front of the player.
15
16
  # @param username [String] See #get_player_head.
16
- # @param size [Fixnum] See #get_player_head.
17
+ # @param size [Integer] See #get_player_head.
17
18
  # @return [ChunkyPNG::Image] The ChunkyPNG::Image instance of that front.
19
+ # @raise see #get
18
20
  def get_player_front(username, size = 100)
19
21
  get_player_image(username, 'player', size)
20
22
  end
21
23
 
22
24
  # Gets the image for the player's raw skin.
23
25
  # @param username [String] See #get_player_head.
24
- # @param size [Fixnum] See #get_player_head.
26
+ # @param size [Integer] See #get_player_head.
25
27
  # @return [ChunkyPNG::Image] The ChunkyPNG::Image instance of that skin.
28
+ # @raise see #get
26
29
  def get_player_skin(username, size = 64)
27
30
  get_player_image(username, 'skin', size)
28
31
  end
@@ -33,8 +36,9 @@ module Fishbans
33
36
  # @param username [String] See #get_player_head.
34
37
  # @param type [String] The type of image to get. Can be 'helm', 'player', or
35
38
  # 'skin' as defined by the Fishbans Player Skins API.
36
- # @param size [Fixnum] See #get_player_head.
39
+ # @param size [Integer] See #get_player_head.
37
40
  # @return [ChunkyPNG::Image] The ChunkyPNG::Image instance for the params.
41
+ # @raise see #get
38
42
  def get_player_image(username, type, size)
39
43
  url = "http://i.fishbans.com/#{type}/#{username}/#{size}"
40
44
  response = get(url, false)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fishbans
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
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: 2017-02-02 00:00:00.000000000 Z
11
+ date: 2017-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -71,9 +71,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  version: '0'
72
72
  requirements: []
73
73
  rubyforge_project:
74
- rubygems_version: 2.6.4
74
+ rubygems_version: 2.6.8
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: A Ruby gem for accessing the Fishbans Minecraft API.
78
78
  test_files: []
79
- has_rdoc: