Module: SRL
- Defined in:
- lib/srl.rb,
lib/srl/api.rb,
lib/srl/utils.rb,
lib/srl/typedefs.rb,
lib/srl/unmarshalable.rb
Defined Under Namespace
Modules: Unmarshalable, Utils Classes: Game, NetworkError, PastRace, Player, Race, ResultSet, Statistics
Constant Summary collapse
- RELEASE =
The current version of srl-api.
'0.3.0'.freeze
Class Method Summary collapse
-
.completed_races(args = {}) ⇒ Object
(also: past_races)
Return an array of PastRace objects for completed races.
-
.current_races ⇒ Object
Return an array of Race objects for races currently being run or set up.
-
.game(abbrev) ⇒ Object
Fetch usage data about a specific game, identified by its abbreviation.
-
.leaderboard(abbrev) ⇒ Object
Fetch the leaderboard for a specific game, identified by its abbreviation.
-
.player(name) ⇒ Object
Fetch a player’s public profile, by name.
-
.release ⇒ Object
Return the current release version as a dotted string.
Class Method Details
.completed_races(args = {}) ⇒ Object Also known as: past_races
Return an array of PastRace objects for completed races. call-seq: current_races -> array
54 55 56 57 58 59 60 61 62 |
# File 'lib/srl/api.rb', line 54 def completed_races(args = {}) res = query('pastraces', args) ResultSet.new( SRL::Utils.collection(res.fetch('pastraces'), PastRace), count: res.fetch('count'), page: args.fetch(:page, 1), page_size: args.fetch(:page_size, 25) ) end |
.current_races ⇒ Object
Return an array of Race objects for races currently being run or set up.
call-seq: current_races -> array
48 49 50 |
# File 'lib/srl/api.rb', line 48 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
13 14 15 16 17 18 19 |
# File 'lib/srl/api.rb', line 13 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
37 38 39 40 41 42 |
# File 'lib/srl/api.rb', line 37 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
25 26 27 28 29 30 31 |
# File 'lib/srl/api.rb', line 25 def player(name) player = Player.from_hash(query("players/#{name}")) raise NameError, "Player '#{name}' not found." unless player.exists? player end |
.release ⇒ Object
Return the current release version as a dotted string.
8 9 10 |
# File 'lib/srl.rb', line 8 def self.release RELEASE end |