Module: SRL

Defined in:
lib/srl.rb,
lib/srl/api.rb,
lib/srl/game.rb,
lib/srl/race.rb,
lib/srl/query.rb,
lib/srl/utils.rb,
lib/srl/player.rb,
lib/srl/past_race.rb,
lib/srl/result_set.rb,
lib/srl/unmarshalable.rb

Defined Under Namespace

Modules: Unmarshalable, Utils Classes: Game, NetworkError, PastRace, Player, Query, Race, ResultSet

Constant Summary collapse

RELEASE =

The current version of srl-api.

'0.5.0'.freeze

Class Method Summary collapse

Class Method Details

.completed_races(args = {}) {|query| ... } ⇒ Object Also known as: past_races

Return an array of PastRace objects for completed races.

You may filter the results by providing a ‘player` or `game` argument, to limit results to a specific player or game abbreviation.

# To fetch only the six million LTTP Rando races.
completed_races(game: 'alttphacks') 

# To only retrieve Edgeworth's FF Randomizer races.
completed_races(player: 'Edgeworth', game: 'ffhacks')

Results are paginated at ‘page_size` records per page, starting at 1. An upper limit to this number has not been tested, though I’d recommend that you not be a twat and limit your requests to something that will not murder the server.

call-seq: current_races -> obj

Yields:

  • (query)


82
83
84
85
86
87
88
89
# File 'lib/srl/api.rb', line 82

def completed_races(args = {})
  query =
    Query.new('pastraces', PastRace, args.merge({ pkey: 'pastraces' })) 

  return query.page unless block_given?

  yield query
end

.current_racesObject

Return an array of Race objects for races currently being run or set up.

call-seq: current_races -> array



59
60
61
# File 'lib/srl/api.rb', line 59

def current_races
  SRL::Utils.collection(query('races').fetch('races'), Race)
end

.game(abbrev) ⇒ Object

Fetch usage data about a specific game, identified by its abbreviation.

call-seq: game(abbreviation) -> obj



24
25
26
27
28
29
30
# File 'lib/srl/api.rb', line 24

def game(abbrev)
  res = query("stat", game: abbrev)
  game = Game.from_hash(res.fetch('game'))
  game.stats = res.fetch('stats')

  game
end

.leaderboard(abbrev) ⇒ Object

Fetch the leaderboard for a specific game, identified by its abbreviation.

call-seq: leaderboard(abbrev) -> obj



48
49
50
51
52
53
# File 'lib/srl/api.rb', line 48

def leaderboard(abbrev)
  SRL::Utils.collection(
    query("leaderboard/#{abbrev}").fetch('leaders'),
    Player
  )
end

.player(name) ⇒ Object

Fetch a player’s public profile, by name. Raises a NameError if the given name does not exist.

call-seq: player(name) -> obj

Raises:

  • (NameError)


36
37
38
39
40
41
42
# File 'lib/srl/api.rb', line 36

def player(name)
  player = Player.from_hash(query("players/#{name}"))

  raise NameError, "Player '#{name}' not found." unless player.exists?

  player
end

.releaseObject

Return the current release version as a dotted string.



8
9
10
# File 'lib/srl.rb', line 8

def self.release
  RELEASE
end