Skip to content
This repository has been archived by the owner on Sep 19, 2018. It is now read-only.

Commit

Permalink
implement Player#ranked_seasons
Browse files Browse the repository at this point in the history
  • Loading branch information
z64 committed Jul 20, 2017
1 parent e4cff63 commit b5c8cf5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rls/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
require 'rest-client'
require 'json'
require 'rls/objects/platform'
require 'rls/objects/player'
require 'rls/objects/season'
require 'rls/objects/search_results'
require 'rls/objects/tier'
require 'rls/objects/playlist'
require 'rls/objects/player'

module RLS
# Mixin binding to RocketLeagueStats' REST API
Expand Down
13 changes: 13 additions & 0 deletions lib/rls/objects/player.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'rls/objects/stats'
require 'rls/objects/ranked_history'

module RLS
# A Rocket League player, as tracked by RLS
Expand Down Expand Up @@ -38,6 +39,9 @@ class Player
# @return [Time]
attr_reader :next_update

# @return [Hash<Integer, RankedHistory>] ranked history by season
attr_reader :ranked_seasons

def initialize(data)
@id = data['uniqueId']
@display_name = data['displayName']
Expand All @@ -51,6 +55,15 @@ def initialize(data)
@created_at = RLS::Utils.time(data['createdAt'])
@updated_at = RLS::Utils.time(data['updatedAt'])
@next_update = RLS::Utils.time(data['nextUpdateAt'])

ranked_seaons_data = data['rankedSeasons']

@ranked_seasons = {}
ranked_seaons_data.each do |season_id, ranked_data|
@ranked_seasons[season_id.to_i] = ranked_data.map do |k, v|
RankedHistory.new(k.to_i, v)
end
end
end
end
end
27 changes: 27 additions & 0 deletions lib/rls/objects/ranked_history.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module RLS
# An entry in a player's ranked history
class RankedHistory
# @return [Integer]
attr_reader :playlist_id

# @return [Integer]
attr_reader :rank_points

# @return [Integer, nil]
attr_reader :matches_played

# @return [Integer, nil]
attr_reader :tier_id

# @return [Integer, nil]
attr_reader :division

def initialize(playlist_id, data)
@playlist_id = playlist_id
@rank_points = data['rankPoints']
@matches_played = data['matchesPlayed']
@tier_id = data['tier']
@division = data['division']
end
end
end

0 comments on commit b5c8cf5

Please sign in to comment.