Class: HypixelAPI
- Inherits:
-
Object
- Object
- HypixelAPI
- Defined in:
- lib/hypixel-ruby.rb
Overview
Base object for the api. Only create one for the entire build as it keeps track of your request limits. All methods are avaible at https://github.com/HypixelDev/PublicAPI/tree/master/Documentation/methods, use arguments are parms.
Instance Method Summary collapse
-
#boosters(args = {}) ⇒ Object
Fetches boosters and their active times.
-
#fetch(url) ⇒ Object
Parses url to Rubyfiy the request, internal so you won’t need to use it for much.
-
#findguild(args = {}) ⇒ Object
Finds a guild by name or player.
-
#friends(args = {}) ⇒ Object
Refer to PublicAPI docs on this one.
-
#guild(args = {}) ⇒ Object
Fetches guild data by id.
-
#initialize(api_key) ⇒ HypixelAPI
constructor
Creates a new object with your API key.
-
#key(args = {}) ⇒ Object
Fetches info about current status of API key.
-
#leaderboards(args = {}) ⇒ Object
Gets top players in each game.
-
#player(args = {}) ⇒ Object
Fetches player, recommended that you webscrape for uuid before finding them.
- #session(args = {}) ⇒ Object
-
#url(type, hash) ⇒ Object
Builds a url from the request type and parameters.
-
#watchdogstats(args = {}) ⇒ Object
Gets info on bans/watchdog.
Constructor Details
#initialize(api_key) ⇒ HypixelAPI
Creates a new object with your API key. If requests are failing for you, remember to check your key.
24 25 26 |
# File 'lib/hypixel-ruby.rb', line 24 def initialize(api_key) @key = api_key end |
Instance Method Details
#boosters(args = {}) ⇒ Object
Fetches boosters and their active times.
48 49 50 |
# File 'lib/hypixel-ruby.rb', line 48 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.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/hypixel-ruby.rb', line 11 def fetch(url) if @min != Time.now.min @min = Time.now.min @requests = 0 end if @requests < 120 @requests += 1 source = (open URI(url)).read return JSON.parse(source, :symbolize_names => true) end end |
#findguild(args = {}) ⇒ Object
Finds a guild by name or player.
53 54 55 |
# File 'lib/hypixel-ruby.rb', line 53 def findguild(args={}) fetch(url(:"findguild", args)) end |
#friends(args = {}) ⇒ Object
Refer to PublicAPI docs on this one.
58 59 60 |
# File 'lib/hypixel-ruby.rb', line 58 def friends(args={}) fetch(url(:"friends", args)) end |
#guild(args = {}) ⇒ Object
Fetches guild data by id.
63 64 65 |
# File 'lib/hypixel-ruby.rb', line 63 def guild(args={}) fetch(url(:"guild", args)) end |
#key(args = {}) ⇒ Object
Fetches info about current status of API key.
68 69 70 |
# File 'lib/hypixel-ruby.rb', line 68 def key(args={}) fetch(url(:"key", args)) end |
#leaderboards(args = {}) ⇒ Object
Gets top players in each game.
73 74 75 |
# File 'lib/hypixel-ruby.rb', line 73 def leaderboards(args={}) fetch(url(:"leaderboards", args)) end |
#player(args = {}) ⇒ Object
Fetches player, recommended that you webscrape for uuid before finding them.
78 79 80 |
# File 'lib/hypixel-ruby.rb', line 78 def player(args={}) fetch(url(:"player", args)) end |
#session(args = {}) ⇒ Object
82 83 84 |
# File 'lib/hypixel-ruby.rb', line 82 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.
29 30 31 32 33 34 35 36 37 |
# File 'lib/hypixel-ruby.rb', line 29 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.
87 88 89 |
# File 'lib/hypixel-ruby.rb', line 87 def watchdogstats(args={}) fetch(url(:"watchdogstats", args)) end |