hypixel-ruby-dev 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/hypixel-ruby.rb +96 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 388ad61a092445b03ed8b12f38cc14d1a8d225fe
4
+ data.tar.gz: 3da39656afb69f6b8eaaefd8d38be98fe5871a01
5
+ SHA512:
6
+ metadata.gz: fa6fd0e3d6c7232a460fe1885ed16f76c149fa90c86849032926062e38f469a424c5e5b14ccb08ec7ad5c3dc52137ae16e1ef2d74386aafd7b7d56f82eaeefea
7
+ data.tar.gz: 444e2596d76326de1fef31e2b6118ac91f216587dffcc18e0db54eae0bcae8b7aa1956e059db426cc5dd48173829a9993b34281243c730e2b0575ca690df724e
@@ -0,0 +1,96 @@
1
+ require 'open-uri'
2
+ require 'json'
3
+
4
+ # Base object for the api. Only create one for the entire build as it keeps track of your request limits. <b>All methods are avaible at https://github.com/HypixelDev/PublicAPI/tree/master/Documentation/methods, use arguments are parms.</b>
5
+ class HypixelAPI
6
+
7
+ @min = 60
8
+ @requests = 0
9
+
10
+ # Parses url to Rubyfiy the request, internal so you won't need to use it for much.
11
+ def fetch(url)
12
+ if @min != Time.now.min
13
+ @min = Time.now.min
14
+ @requests = 0
15
+ end
16
+ if @requests < 120
17
+ @requests += 1
18
+ source = (open URI(url)).read
19
+ return JSON.parse(source, :symbolize_names => true)
20
+ end
21
+ end
22
+
23
+ # Creates a new object with your API key. <b>If requests are failing for you, remember to check your key.</b>
24
+ def initialize(api_key)
25
+ @key = api_key
26
+ end
27
+
28
+ # Builds a url from the request type and parameters. <b>Do not specify your key in the parameters.</b>
29
+ def url(type, hash)
30
+ url = "https://api.hypixel.net/"
31
+ url << type.to_s
32
+ url << "?key=" + @key
33
+ hash.each do |a1, a2|
34
+ url << "&" + a1.to_s + "=" + a2.to_s
35
+ end
36
+ return url
37
+ end
38
+
39
+ # ========================================
40
+ # Main Methods
41
+ # ========================================
42
+ #
43
+ # Refer to hypixel PublicAPI for parms
44
+ # ex: api.player( :uuid => "<uuid here>" )
45
+ #
46
+
47
+ # Fetches boosters and their active times.
48
+ def boosters(args={})
49
+ fetch(url(:"boosters", args))
50
+ end
51
+
52
+ # Finds a guild by name or player.
53
+ def findguild(args={})
54
+ fetch(url(:"findguild", args))
55
+ end
56
+
57
+ # Refer to PublicAPI docs on this one.
58
+ def friends(args={})
59
+ fetch(url(:"friends", args))
60
+ end
61
+
62
+ # Fetches guild data by id.
63
+ def guild(args={})
64
+ fetch(url(:"guild", args))
65
+ end
66
+
67
+ # Fetches info about current status of API key.
68
+ def key(args={})
69
+ fetch(url(:"key", args))
70
+ end
71
+
72
+ # Gets top players in each game.
73
+ def leaderboards(args={})
74
+ fetch(url(:"leaderboards", args))
75
+ end
76
+
77
+ # Fetches player, recommended that you webscrape for uuid before finding them.
78
+ def player(args={})
79
+ fetch(url(:"player", args))
80
+ end
81
+
82
+ def session(args={})
83
+ fetch(url(:"session", args))
84
+ end
85
+
86
+ # Gets info on bans/watchdog.
87
+ def watchdogstats(args={})
88
+ fetch(url(:"watchdogstats", args))
89
+ end
90
+
91
+ end
92
+
93
+ if ENV['TRAVIS']
94
+ api = HypixelAPI.new ENV['HYPIXEL_KEY']
95
+ puts api.player( :uuid => ENV['UUID'] )[:player][:achivements][:bedwars_level]
96
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hypixel-ruby-dev
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - PenguinOwl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Robust, but powerful. Source avaible at https://github.com/PenguinOwl/hypixel-rubyed/
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/hypixel-ruby.rb
20
+ homepage: https://github.com/PenguinOwl/hypixel-rubyed/
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.6.14
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Barebones wrapper for Hypixel stats
44
+ test_files: []