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 players.
-
#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.
38 39 40 41 |
# File 'lib/brawlstars.rb', line 38 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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/brawlstars.rb', line 48 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 401 raise Error::Unauthorized when 404 raise Error::NotFoundError when 429 raise Error::RateLimitError when 503 raise Error::MaintainanceError when 500...600 raise Error::ServerError end end |
Instance Method Details
#about ⇒ Hash
Get info about the API
75 76 77 |
# File 'lib/brawlstars.rb', line 75 def about Client.get("/about") end |
#clubSearch(name) ⇒ Hash
Search for clubs by their name
113 114 115 |
# File 'lib/brawlstars.rb', line 113 def clubSearch(name) Client.get("/club/search?name=#{name.gsub(' ', '%20')}") end |
#getClub(tag) ⇒ Hash
Get a club by its tag
103 104 105 106 |
# File 'lib/brawlstars.rb', line 103 def getClub(tag) tag = validateTag(tag) Client.get("/club?tag=#{tag}") end |
#getCurrentEvents ⇒ Hash
Get current events
129 130 131 |
# File 'lib/brawlstars.rb', line 129 def getCurrentEvents Client.get("/events?type=current") end |
#getMisc ⇒ Hash
Get miscellaneous data, like shop/season reset
137 138 139 |
# File 'lib/brawlstars.rb', line 137 def getMisc Client.get("/misc") end |
#getPlayer(tag) ⇒ Hash
Get a player by their tag
84 85 86 87 |
# File 'lib/brawlstars.rb', line 84 def getPlayer(tag) tag = validateTag(tag) Client.get("/player?tag=#{tag}") end |
#getTopClubs(count = 200) ⇒ Hash
Get top global clubs
146 147 148 149 150 |
# File 'lib/brawlstars.rb', line 146 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 players
158 159 160 161 162 |
# File 'lib/brawlstars.rb', line 158 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 |