Class: Brawlstars::Client
- Inherits:
-
Object
- Object
- Brawlstars::Client
- Defined in:
- lib/brawlstars.rb
Class Method Summary collapse
-
.get(ep) ⇒ Hash
The method to send GET requests to the API.
Instance Method Summary collapse
-
#about ⇒ Hash
Get info about the API.
-
#clubSearch(name) ⇒ Hash
Search for clubs by their name.
-
#getClub(tag) ⇒ Hash
Get a club by its tag.
-
#getCurrentEvents ⇒ Hash
Get current events.
-
#getMisc ⇒ Hash
Get miscellaneous data, like shop/season reset.
-
#getPlayer(tag) ⇒ Hash
Get a player by their tag.
-
#getTopClubs(count = 200) ⇒ Hash
Get top global clubs.
-
#getTopPlayers(count = 200, brawler = "") ⇒ Hash
Get top global clubs.
-
#getUpcomingEvents ⇒ Hash
Get upcoming events.
-
#initialize(token: false) ⇒ Client
constructor
A new instance of Client.
-
#playerSearch(name) ⇒ Hash
Search for players by their name.
Constructor Details
#initialize(token: false) ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/brawlstars.rb', line 7 def initialize(token: false) raise "No authorization token was given!" if !token @@token = token end |
Class Method Details
.get(ep) ⇒ Hash
The method to send GET requests to the API
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/brawlstars.rb', line 15 def self.get(ep) url = "https://api.brawlapi.cf/v1#{ep}" begin res = HTTParty.get(url, {headers: {"Authorization" => @@token}}) rescue HTTParty::Error => e puts e end case res.code when 200 res when 400...600 raise "Error on request; Status code: #{res.code}; Message: #{res["message"]}" end end |
Instance Method Details
#about ⇒ Hash
Get info about the API
34 35 36 |
# File 'lib/brawlstars.rb', line 34 def about Client.get("/about") end |
#clubSearch(name) ⇒ Hash
Search for clubs by their name
72 73 74 |
# File 'lib/brawlstars.rb', line 72 def clubSearch(name) Client.get("/club/search?name=#{name.gsub(' ', '%20')}") end |
#getClub(tag) ⇒ Hash
Get a club by its tag
62 63 64 65 |
# File 'lib/brawlstars.rb', line 62 def getClub(tag) tag = validateTag(tag) Client.get("/club?tag=#{tag}") end |
#getCurrentEvents ⇒ Hash
Get current events
88 89 90 |
# File 'lib/brawlstars.rb', line 88 def getCurrentEvents Client.get("/events?type=current") end |
#getMisc ⇒ Hash
Get miscellaneous data, like shop/season reset
96 97 98 |
# File 'lib/brawlstars.rb', line 96 def getMisc Client.get("/misc") end |
#getPlayer(tag) ⇒ Hash
Get a player by their tag
43 44 45 46 |
# File 'lib/brawlstars.rb', line 43 def getPlayer(tag) tag = validateTag(tag) Client.get("/player?tag=#{tag}") end |
#getTopClubs(count = 200) ⇒ Hash
Get top global clubs
105 106 107 108 109 |
# File 'lib/brawlstars.rb', line 105 def getTopClubs(count=200) raise 'Count must be a number.' if !count.is_a? Integer raise 'Count must be between 1 and 200.' if !count.between?(1,200) Client.get("/leaderboards/clubs?count=#{count}") end |
#getTopPlayers(count = 200, brawler = "") ⇒ Hash
Get top global clubs
117 118 119 120 121 |
# File 'lib/brawlstars.rb', line 117 def getTopPlayers(count=200, brawler="") raise 'Count must be a number.' if !count.is_a? Integer raise 'Count must be between 1 and 200.' if !count.between?(1,200) Client.get("/leaderboards/players?count=#{count}&brawler=#{brawler}") end |