Class: Brawlstars::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/brawlstars.rb

Instance Method Summary collapse

Constructor Details

#initialize(token: false) ⇒ Client

Returns a new instance of Client


43
44
45
46
# File 'lib/brawlstars.rb', line 43

def initialize(token: false)
  raise "No authorization token was given!" if !token
  @token = token
end

Instance Method Details

#aboutHash

Get info about the API

Returns:

  • (Hash)

    info about the API


52
53
54
# File 'lib/brawlstars.rb', line 52

def about
  get("/about")
end

#clubSearch(name) ⇒ Hash

Search for clubs by their name

Parameters:

  • name (String)

    name to search for.

Returns:

  • (Hash)

    clubs returned by the search.


100
101
102
# File 'lib/brawlstars.rb', line 100

def clubSearch(name)
  get("/club/search?name=#{name.gsub(' ', '%20')}")
end

#getBattleLog(tag) ⇒ Hash

Get a player's battle log by their tag

Parameters:

  • tag (String)

    tag of the player to get.

Returns:

  • (Hash)

    data of the player's battle log that was searched.


80
81
82
83
# File 'lib/brawlstars.rb', line 80

def getBattleLog(tag)
  tag = validateTag(tag)
  get("/player/battlelog?tag=#{tag}")
end

#getClub(tag) ⇒ Hash

Get a club by its tag

Parameters:

  • tag (String)

    tag of the club to get.

Returns:

  • (Hash)

    data of the club that was searched.


90
91
92
93
# File 'lib/brawlstars.rb', line 90

def getClub(tag)
  tag = validateTag(tag)
  get("/club?tag=#{tag}")
end

#getCurrentEventsHash

Get current events

Returns:

  • (Hash)

    current events


116
117
118
# File 'lib/brawlstars.rb', line 116

def getCurrentEvents
  get("/events?type=current")
end

#getMiscHash

Get miscellaneous data, like shop/season reset

Returns:

  • (Hash)

    miscellaneous data


124
125
126
# File 'lib/brawlstars.rb', line 124

def getMisc
  get("/misc")
end

#getPlayer(tag) ⇒ Brawlstars::Player

Get a player by their tag

Parameters:

  • tag (String)

    tag of the player to get.

Returns:


61
62
63
64
# File 'lib/brawlstars.rb', line 61

def getPlayer(tag)
  tag = validateTag(tag)
  Player.new(self, get("/player?tag=#{tag}"))
end

#getTopClubs(count = 200, region = "global") ⇒ Hash

Get top global clubs

Parameters:

  • count (Integer) (defaults to: 200)

    number of clubs to return.

  • region (String) (defaults to: "global")

    2 character country code for the region of leaderboard to return.

Returns:

  • (Hash)

    clubs in order from 1st rank down.


134
135
136
137
138
139
# File 'lib/brawlstars.rb', line 134

def getTopClubs(count=200, region="global")
  raise 'Count must be a number.' if !count.is_a? Integer
  raise 'Count must be between 1 and 200.' if !count.between?(1,200)
  validateRegion(region)
  get("/leaderboards/clubs?count=#{count}&region=#{region}")
end

#getTopPlayers(count = 200, brawler = "", region = "global") ⇒ Hash

Get top global players

Parameters:

  • count (Integer) (defaults to: 200)

    number of players to return.

  • brawler (String) (defaults to: "")

    brawler leaderboard to return.

  • region (String) (defaults to: "global")

    2 character country code for the region of leaderboard to return.

Returns:

  • (Hash)

    players in order from 1st rank down.


148
149
150
151
152
153
# File 'lib/brawlstars.rb', line 148

def getTopPlayers(count=200, brawler="", region="global")
  raise 'Count must be a number.' if !count.is_a? Integer
  raise 'Count must be between 1 and 200.' if !count.between?(1,200)
  validateRegion(region)
  get("/leaderboards/players?count=#{count}&brawler=#{brawler}&region=#{region}")
end

#getUpcomingEventsHash

Get upcoming events

Returns:

  • (Hash)

    upcoming events


108
109
110
# File 'lib/brawlstars.rb', line 108

def getUpcomingEvents
  get("/events?type=upcoming")
end

#playerSearch(name) ⇒ Hash

Search for players by their name

Parameters:

  • name (String)

    name to search for.

Returns:

  • (Hash)

    players returned by the search.


71
72
73
# File 'lib/brawlstars.rb', line 71

def playerSearch(name)
  get("/player/search?name=#{name.gsub(' ', '%20')}")
end