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.
27 28 29 |
# File 'lib/hypixel-ruby.rb', line 27 def initialize(api_key) @key = api_key end |
Instance Method Details
#boosters(args = {}) ⇒ Object
Fetches boosters and their active times.
51 52 53 |
# File 'lib/hypixel-ruby.rb', line 51 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.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hypixel-ruby.rb', line 12 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 x = JSON.parse(source, :symbolize_names => true) x.extend Hashie::Extensions::DeepFind return x end end |
#findguild(args = {}) ⇒ Object
Finds a guild by name or player.
56 57 58 |
# File 'lib/hypixel-ruby.rb', line 56 def findguild(args={}) fetch(url(:"findguild", args)) end |
#friends(args = {}) ⇒ Object
Refer to PublicAPI docs on this one.
61 62 63 |
# File 'lib/hypixel-ruby.rb', line 61 def friends(args={}) fetch(url(:"friends", args)) end |
#guild(args = {}) ⇒ Object
Fetches guild data by id.
66 67 68 |
# File 'lib/hypixel-ruby.rb', line 66 def guild(args={}) fetch(url(:"guild", args)) end |
#key(args = {}) ⇒ Object
Fetches info about current status of API key.
71 72 73 |
# File 'lib/hypixel-ruby.rb', line 71 def key(args={}) fetch(url(:"key", args)) end |
#leaderboards(args = {}) ⇒ Object
Gets top players in each game.
76 77 78 |
# File 'lib/hypixel-ruby.rb', line 76 def leaderboards(args={}) fetch(url(:"leaderboards", args)) end |
#player(args = {}) ⇒ Object
Fetches player, recommended that you webscrape for uuid before finding them.
81 82 83 |
# File 'lib/hypixel-ruby.rb', line 81 def player(args={}) fetch(url(:"player", args)) end |
#session(args = {}) ⇒ Object
85 86 87 |
# File 'lib/hypixel-ruby.rb', line 85 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.
32 33 34 35 36 37 38 39 40 |
# File 'lib/hypixel-ruby.rb', line 32 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.
90 91 92 |
# File 'lib/hypixel-ruby.rb', line 90 def watchdogstats(args={}) fetch(url(:"watchdogstats", args)) end |