Class: HypixelAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/hypixel-ruby.rb

Overview

Base object for the api. Only create one for the entire build as it will one day keep track of your request limits. *All methods are avaible at github.com/HypixelDev/PublicAPI/tree/master/Documentation/methods, use arguments are parms.*

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ HypixelAPI

Creates a new object with your API key. *If request are failing for you, remember to check your key.*



14
15
16
# File 'lib/hypixel-ruby.rb', line 14

def initialize(key)
  @key = key
end

Instance Method Details

#boosters(args = {}) ⇒ Object

Fetches boosters and their active times.



38
39
40
# File 'lib/hypixel-ruby.rb', line 38

def boosters(args={})
  fetch(url(:"boosters", args))
end

#fetch(url) ⇒ Object

Parses url to Rubyfiy the request, internal so you won’t need to use it for much.



8
9
10
11
# File 'lib/hypixel-ruby.rb', line 8

def fetch(url)
  source = (open URI(url)).read
  return JSON.parse(source, :symbolize_names => true)
end

#findguild(args = {}) ⇒ Object

Finds a guild by name or player.



43
44
45
# File 'lib/hypixel-ruby.rb', line 43

def findguild(args={})
  fetch(url(:"findguild", args))
end

#friends(args = {}) ⇒ Object

Refer to PublicAPI docs on this one.



48
49
50
# File 'lib/hypixel-ruby.rb', line 48

def friends(args={})
  fetch(url(:"friends", args))
end

#guild(args = {}) ⇒ Object

Fetches guild data by id.



53
54
55
# File 'lib/hypixel-ruby.rb', line 53

def guild(args={})
  fetch(url(:"guild", args))
end

#key(args = {}) ⇒ Object

Fetches info about current status of API key.



58
59
60
# File 'lib/hypixel-ruby.rb', line 58

def key(args={})
  fetch(url(:"key", args))
end

#leaderboards(args = {}) ⇒ Object

Gets top players in each game.



63
64
65
# File 'lib/hypixel-ruby.rb', line 63

def leaderboards(args={})
  fetch(url(:"leaderboards", args))
end

#player(args = {}) ⇒ Object

Fetches player, recommended that you webscrape for uuid before finding them.



68
69
70
# File 'lib/hypixel-ruby.rb', line 68

def player(args={})
  fetch(url(:"player", args))
end

#session(args = {}) ⇒ Object



72
73
74
# File 'lib/hypixel-ruby.rb', line 72

def session(args={})
  fetch(url(:"session", args))
end

#url(type, hash) ⇒ Object

Builds a url from the request type and parameters. *Do not specify your key in the parameters.*



19
20
21
22
23
24
25
26
27
# File 'lib/hypixel-ruby.rb', line 19

def url(type, hash)
  url = "https://api.hypixel.net/"
  url << type.to_s
  url << "?key=" + @key
  hash.each do |a1, a2|
    url << "&" + a1.to_s + "=" + a2.to_s
  end
  return url
end

#watchdogstats(args = {}) ⇒ Object

Gets info on bans/watchdog.



77
78
79
# File 'lib/hypixel-ruby.rb', line 77

def watchdogstats(args={})
  fetch(url(:"watchdogstats", args))
end