Module: Fishbans
- Extended by:
- Fishbans
- Includes:
- BlockEngine, PlayerSkins
- Included in:
- Fishbans
- Defined in:
- lib/fishbans.rb,
 lib/block_engine.rb,
 lib/player_skins.rb
Defined Under Namespace
Modules: BlockEngine, PlayerSkins
Constant Summary collapse
- SERVICES =
- [ 'mcbouncer', 'minebans', 'glizer', 'mcblockit', 'mcbans' ] 
Instance Method Summary collapse
- 
  
    
      #get(url, do_json = true)  ⇒ Hash, HTTP::Message 
    
    
  
  
  
  
  private
  
  
  
  
    Performs a basic GET request. 
- 
  
    
      #get_all_bans(username)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Gets all bans on a user. 
- 
  
    
      #get_ban_service(username, service)  ⇒ Boolean, Hash<String, String> 
    
    
  
  
  
  
  
  
  
  
  
    Gets all bans for a given service for a user. 
- 
  
    
      #get_total_bans(username)  ⇒ Integer 
    
    
  
  
  
  
  
  
  
  
  
    Gets the total number of bans that the user has. 
- 
  
    
      #get_total_bans_service(username, service)  ⇒ Boolean, Integer 
    
    
  
  
  
  
  
  
  
  
  
    Gets the total number of bans by service that the user has. 
- 
  
    
      #get_userid(username)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Gets the Minecraft UUID for the user. 
- 
  
    
      #get_username_history(username)  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    Gets username history for the user. 
- 
  
    
      #parse_generic_ban_result(response)  ⇒ Hash<String, Hash<String, String>> 
    
    
  
  
  
  
  private
  
  
  
  
    Parses a basic ban result into a formatted hash. 
Methods included from PlayerSkins
#get_player_front, #get_player_head, #get_player_image, #get_player_skin
Methods included from BlockEngine
Instance Method Details
#get(url, do_json = true) ⇒ Hash, HTTP::Message (private)
Performs a basic GET request.
| 101 102 103 104 105 106 107 108 109 | # File 'lib/fishbans.rb', line 101 def get(url, do_json = true) url = URI.encode(url) uri = URI.parse(url) response = @client.get(uri) return response unless do_json json = JSON.parse(response.body) return json if json['success'] fail json['error'] end | 
#get_all_bans(username) ⇒ Object
Gets all bans on a user.
| 24 25 26 27 | # File 'lib/fishbans.rb', line 24 def get_all_bans(username) response = get("http://api.fishbans.com/bans/#{username}") parse_generic_ban_result(response) end | 
#get_ban_service(username, service) ⇒ Boolean, Hash<String, String>
Gets all bans for a given service for a user.
| 35 36 37 38 39 40 41 42 43 44 | # File 'lib/fishbans.rb', line 35 def get_ban_service(username, service) service.downcase! if SERVICES.include? service response = get("http://api.fishbans.com/bans/#{username}/#{service}") parse_generic_ban_result(response)[service] else false end end | 
#get_total_bans(username) ⇒ Integer
Gets the total number of bans that the user has.
| 50 51 52 53 | # File 'lib/fishbans.rb', line 50 def get_total_bans(username) response = get("http://api.fishbans.com/stats/#{username}") response['stats']['totalbans'] end | 
#get_total_bans_service(username, service) ⇒ Boolean, Integer
Gets the total number of bans by service that the user has.
| 62 63 64 65 66 67 68 69 70 71 72 73 | # File 'lib/fishbans.rb', line 62 def get_total_bans_service(username, service) service.downcase! if SERVICES.include?(service) # Note that the /service part is not necessary, but it slightly improves # performance of the API. response = get("http://api.fishbans.com/stats/#{username}/#{service}") response['stats']['service'][service] else false end end | 
#get_userid(username) ⇒ String
Gets the Minecraft UUID for the user.
| 79 80 81 82 | # File 'lib/fishbans.rb', line 79 def get_userid(username) response = get("http://api.fishbans.com/uuid/#{username}") response['uuid'] end | 
#get_username_history(username) ⇒ Array<String>
Gets username history for the user.
| 88 89 90 91 | # File 'lib/fishbans.rb', line 88 def get_username_history(username) response = get("http://api.fishbans.com/history/#{username}") response['data']['history'] end | 
#parse_generic_ban_result(response) ⇒ Hash<String, Hash<String, String>> (private)
Parses a basic ban result into a formatted hash. This assumes it is not an errored response.
| 115 116 117 118 119 120 121 122 123 124 125 126 | # File 'lib/fishbans.rb', line 115 def parse_generic_ban_result(response) ret = {} response['bans']['service'].each do |service, info| next if info['bans'] == 0 ret[service] = {} info['ban_info'].each do |server, reason| ret[service][server] = reason end end ret end |