chgk_rating 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +8 -499
- data/chgk_rating.gemspec +7 -6
- data/lib/chgk_rating/attribute_mappings.rb +20 -4
- data/lib/chgk_rating/chgk_object.rb +1 -0
- data/lib/chgk_rating/client.rb +40 -9
- data/lib/chgk_rating/collections/ratings/player_ratings.rb +22 -0
- data/lib/chgk_rating/collections/{ratings.rb → ratings/team_ratings.rb} +2 -3
- data/lib/chgk_rating/collections/tournaments/player_tournaments.rb +44 -0
- data/lib/chgk_rating/collections/{tournament_players.rb → tournaments/tournament_team_players.rb} +2 -2
- data/lib/chgk_rating/collections/{tournament_team_results.rb → tournaments/tournament_team_results.rb} +0 -0
- data/lib/chgk_rating/collections/{tournament_teams.rb → tournaments/tournament_teams.rb} +0 -0
- data/lib/chgk_rating/collections/{tournaments.rb → tournaments/tournaments.rb} +2 -1
- data/lib/chgk_rating/connection.rb +4 -1
- data/lib/chgk_rating/models/base.rb +17 -5
- data/lib/chgk_rating/models/player.rb +25 -0
- data/lib/chgk_rating/models/rating/player_rating.rb +16 -0
- data/lib/chgk_rating/models/{tournament_player.rb → rating/rating.rb} +1 -1
- data/lib/chgk_rating/models/{rating.rb → rating/team_rating.rb} +1 -4
- data/lib/chgk_rating/models/team.rb +6 -6
- data/lib/chgk_rating/models/tournament/player_tournament.rb +8 -0
- data/lib/chgk_rating/models/{tournament.rb → tournament/tournament.rb} +4 -4
- data/lib/chgk_rating/models/{tournament_team.rb → tournament/tournament_team.rb} +3 -3
- data/lib/chgk_rating/models/tournament/tournament_team_player.rb +8 -0
- data/lib/chgk_rating/models/{tournament_team_result.rb → tournament/tournament_team_result.rb} +0 -0
- data/lib/chgk_rating/utils/transformations.rb +1 -0
- data/lib/chgk_rating/version.rb +1 -1
- data/lib/chgk_rating.rb +15 -10
- data/spec/lib/chgk_rating/client_spec.rb +46 -7
- data/spec/lib/chgk_rating/collections/player_ratings_spec.rb +15 -0
- data/spec/lib/chgk_rating/collections/{ratings_spec.rb → team_ratings_spec.rb} +1 -1
- data/spec/lib/chgk_rating/collections/tournaments/player_tournaments_spec.rb +38 -0
- data/spec/lib/chgk_rating/collections/{tournament_players_spec.rb → tournaments/tournament_team_players_spec.rb} +1 -1
- data/spec/lib/chgk_rating/collections/{tournament_team_results_spec.rb → tournaments/tournament_team_results_spec.rb} +0 -0
- data/spec/lib/chgk_rating/collections/{tournament_teams_spec.rb → tournaments/tournament_teams_spec.rb} +0 -0
- data/spec/lib/chgk_rating/collections/{tournaments_spec.rb → tournaments/tournaments_spec.rb} +0 -0
- data/spec/lib/chgk_rating/models/player_rating_spec.rb +22 -0
- data/spec/lib/chgk_rating/models/player_spec.rb +27 -0
- data/spec/lib/chgk_rating/models/{rating_spec.rb → team_rating_spec.rb} +1 -1
- data/spec/lib/chgk_rating/models/team_spec.rb +2 -2
- data/spec/lib/chgk_rating/models/{tournament_spec.rb → tournament/tournament_spec.rb} +3 -3
- data/spec/lib/chgk_rating/models/{tournament_player_spec.rb → tournament/tournament_team_player_spec.rb} +1 -1
- data/spec/lib/chgk_rating/models/{tournament_team_result_spec.rb → tournament/tournament_team_result_spec.rb} +0 -0
- data/spec/lib/chgk_rating/models/{tournament_team_spec.rb → tournament/tournament_team_spec.rb} +1 -1
- data/spec/spec_helper.rb +2 -0
- metadata +70 -46
data/lib/chgk_rating/client.rb
CHANGED
@@ -47,19 +47,29 @@ module ChgkRating
|
|
47
47
|
# @param tournament_or_id [String, Integer or Tournament] Tournament to load team for.
|
48
48
|
# @param team_or_id [String, Integer or Team] Team to search for.
|
49
49
|
def team_at_tournament(tournament_or_id, team_or_id)
|
50
|
-
tournament(tournament_or_id, true).
|
50
|
+
tournament(tournament_or_id, true).team_by(team_or_id)
|
51
51
|
end
|
52
52
|
|
53
|
-
# Returns
|
53
|
+
# Returns rating for a given Team in a given release
|
54
54
|
#
|
55
55
|
# @raise [ChgkRating::Error::NotFound] Error raised when the requested release or Team cannot be found.
|
56
|
-
# @return [ChgkRating::Models::
|
56
|
+
# @return [ChgkRating::Models::TeamRating] The requested rating.
|
57
57
|
# @param team_or_id [String, Integer or ChgkRating::Models::Team] Team to load rating for.
|
58
58
|
# @param release_id [String or Integer] Release to load rating for.
|
59
|
-
def
|
59
|
+
def team_rating(team_or_id, release_id)
|
60
60
|
team(team_or_id, true).rating(release_id)
|
61
61
|
end
|
62
62
|
|
63
|
+
# Returns rating for a given Player in a given release
|
64
|
+
#
|
65
|
+
# @raise [ChgkRating::Error::NotFound] Error raised when the requested release or Player cannot be found.
|
66
|
+
# @return [ChgkRating::Models::PlayerRating] The requested rating.
|
67
|
+
# @param player_or_id [String, Integer or ChgkRating::Models::Team] Player to load rating for.
|
68
|
+
# @param release_id [String or Integer] Release to load rating for.
|
69
|
+
def player_rating(player_or_id, release_id)
|
70
|
+
player(player_or_id, true).rating(release_id)
|
71
|
+
end
|
72
|
+
|
63
73
|
# Search
|
64
74
|
|
65
75
|
# Returns a Players collection based on the search criteria.
|
@@ -127,18 +137,39 @@ module ChgkRating
|
|
127
137
|
# @param season_id [String or Integer] Season to load tournaments for
|
128
138
|
# @option params [String or Integer] :page The requested page. Default is 1
|
129
139
|
def tournaments(team_or_id: nil, season_id: nil, params: {})
|
130
|
-
ChgkRating::Collections::Tournaments.new params.merge(
|
140
|
+
ChgkRating::Collections::Tournaments.new params.merge(
|
141
|
+
team: team_or_id, season_id: season_id
|
142
|
+
)
|
143
|
+
end
|
144
|
+
|
145
|
+
# Returns a collection of Tournaments that the Player has participated in
|
146
|
+
#
|
147
|
+
# @return [ChgkRating::Collection::PlayerTournaments] The collection of tournaments.
|
148
|
+
# @param player_or_id [String, Integer or ChgkRating::Models::Player] Player to load tournaments for.
|
149
|
+
# @param season_id [String or Integer] Season to load tournaments for
|
150
|
+
def player_tournaments(player_or_id, season_id = nil)
|
151
|
+
ChgkRating::Collections::PlayerTournaments.new player: player_or_id,
|
152
|
+
season_id: season_id
|
131
153
|
end
|
132
154
|
|
133
|
-
# Returns an array-like Ratings collection for a given
|
155
|
+
# Returns an array-like Ratings collection for a given Team.
|
134
156
|
#
|
135
157
|
# @raise [ChgkRating::Error::NotFound] Error raised when the requested Team cannot be found.
|
136
158
|
# @return [ChgkRating::Collection::Ratings] The collection of ratings.
|
137
159
|
# @param team_or_id [String, Integer or ChgkRating::Models::Team] Team to load ratings for.
|
138
|
-
def
|
160
|
+
def team_ratings(team_or_id)
|
139
161
|
team(team_or_id, true).ratings
|
140
162
|
end
|
141
163
|
|
164
|
+
# Returns an array-like Ratings collection for a given Player.
|
165
|
+
#
|
166
|
+
# @raise [ChgkRating::Error::NotFound] Error raised when the requested Player cannot be found.
|
167
|
+
# @return [ChgkRating::Collection::Ratings] The collection of ratings.
|
168
|
+
# @param player_or_id [String, Integer or ChgkRating::Models::Team] Player to load ratings for.
|
169
|
+
def player_ratings(player_or_id)
|
170
|
+
player(player_or_id, true).ratings
|
171
|
+
end
|
172
|
+
|
142
173
|
# Returns an array-like TournamentTeams collection specifying which teams participated in a given tournament
|
143
174
|
#
|
144
175
|
# @raise [ChgkRating::Error::NotFound] Error raised when the requested Tournament cannot be found.
|
@@ -159,11 +190,11 @@ module ChgkRating
|
|
159
190
|
team_at_tournament(tournament_or_id, team_or_id).results
|
160
191
|
end
|
161
192
|
|
162
|
-
# Returns an array-like
|
193
|
+
# Returns an array-like TournamentTeamPlayers collection containing roster for a
|
163
194
|
# given team at a given tournament.
|
164
195
|
#
|
165
196
|
# @raise [ChgkRating::Error::NotFound] Error raised when the requested Tournament or Team cannot be found.
|
166
|
-
# @return [ChgkRating::Collection::
|
197
|
+
# @return [ChgkRating::Collection::TournamentTeamPlayers] The collection of results.
|
167
198
|
# @param tournament_or_id [String, Integer or ChgkRating::Models::Tournament] Tournament to load players for.
|
168
199
|
# @param team_or_id [String, Integer or ChgkRating::Models::Team] Team to load players for.
|
169
200
|
def team_players_at_tournament(tournament_or_id, team_or_id)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ChgkRating
|
2
|
+
module Collections
|
3
|
+
class PlayerRatings < Base
|
4
|
+
attr_reader :player
|
5
|
+
|
6
|
+
def initialize(params = {})
|
7
|
+
@player = build_model params[:player], ChgkRating::Models::Player
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def process(*_args)
|
14
|
+
super { |result| ChgkRating::Models::PlayerRating.new result }
|
15
|
+
end
|
16
|
+
|
17
|
+
def api_path
|
18
|
+
"players/#{@player.id}/rating"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,18 +1,17 @@
|
|
1
1
|
module ChgkRating
|
2
2
|
module Collections
|
3
|
-
class
|
3
|
+
class TeamRatings < Base
|
4
4
|
attr_reader :team
|
5
5
|
|
6
6
|
def initialize(params = {})
|
7
7
|
@team = build_model params[:team]
|
8
|
-
|
9
8
|
super
|
10
9
|
end
|
11
10
|
|
12
11
|
private
|
13
12
|
|
14
13
|
def process(*_args)
|
15
|
-
super { |result| ChgkRating::Models::
|
14
|
+
super { |result| ChgkRating::Models::TeamRating.new result }
|
16
15
|
end
|
17
16
|
|
18
17
|
def api_path
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ChgkRating
|
2
|
+
module Collections
|
3
|
+
class PlayerTournaments < Base
|
4
|
+
attr_reader :season_id, :player
|
5
|
+
|
6
|
+
def initialize(params = {})
|
7
|
+
@player = build_model params[:player], ChgkRating::Models::Player
|
8
|
+
|
9
|
+
@season_id = params[:season_id]
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def revert_to_hash(key, values)
|
14
|
+
[
|
15
|
+
key,
|
16
|
+
{
|
17
|
+
'idplayer' => @player.id.to_s,
|
18
|
+
'idseason' => key,
|
19
|
+
'tournaments' => values.map(&:to_h)
|
20
|
+
}
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def process(_results, params = {})
|
27
|
+
super do |result|
|
28
|
+
if @player && @season_id.nil?
|
29
|
+
ChgkRating::Collections::PlayerTournaments.new(collection: result['tournaments']).items
|
30
|
+
else
|
31
|
+
ChgkRating::Models::PlayerTournament.new result
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [String] Either `tournaments`, `teams/ID/tournaments`, `players/ID/tournaments`, `teams/ID/tournaments/SEASON_ID`, `players/ID/tournaments/SEASON_ID`
|
37
|
+
def api_path
|
38
|
+
path = "players/#{@player.id}/tournaments"
|
39
|
+
return path unless @season_id
|
40
|
+
path + "/#{@season_id}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/chgk_rating/collections/{tournament_players.rb → tournaments/tournament_team_players.rb}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
module ChgkRating
|
2
2
|
module Collections
|
3
|
-
class
|
3
|
+
class TournamentTeamPlayers < Base
|
4
4
|
attr_reader :team, :tournament
|
5
5
|
|
6
6
|
def initialize(params = {})
|
@@ -13,7 +13,7 @@ module ChgkRating
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def process(*_args)
|
16
|
-
super { |result| ChgkRating::Models::
|
16
|
+
super { |result| ChgkRating::Models::TournamentTeamPlayer.new result }
|
17
17
|
end
|
18
18
|
|
19
19
|
def api_path
|
File without changes
|
File without changes
|
@@ -15,7 +15,7 @@ module ChgkRating
|
|
15
15
|
[
|
16
16
|
key,
|
17
17
|
{
|
18
|
-
'idteam' => @team
|
18
|
+
'idteam' => @team&.id.to_s,
|
19
19
|
'idseason' => key,
|
20
20
|
'tournaments' => values.map(&:to_h)
|
21
21
|
}
|
@@ -35,6 +35,7 @@ module ChgkRating
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
# @return [String] Either `tournaments`, `teams/ID/tournaments`, or `teams/ID/tournaments/SEASON_ID`
|
38
39
|
def api_path
|
39
40
|
path = 'tournaments'
|
40
41
|
return path unless @team
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
|
1
3
|
module ChgkRating
|
2
4
|
module Connection
|
3
5
|
BASE_URL = 'http://rating.chgk.info/api'.freeze
|
@@ -12,8 +14,9 @@ module ChgkRating
|
|
12
14
|
}
|
13
15
|
|
14
16
|
Faraday.new options do |faraday|
|
17
|
+
faraday.use FaradayMiddleware::FollowRedirects
|
15
18
|
faraday.adapter Faraday.default_adapter
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
19
|
-
end
|
22
|
+
end
|
@@ -51,9 +51,12 @@ module ChgkRating
|
|
51
51
|
|
52
52
|
private
|
53
53
|
|
54
|
+
# Grab the attribute mapping for the class and its superclass
|
55
|
+
# (as superclass may present common mappings for multiple classes)
|
54
56
|
def self.attribute_mapping
|
55
57
|
return nil unless self.name
|
56
|
-
ChgkRating::AttributeMappings.find
|
58
|
+
ChgkRating::AttributeMappings.find(self.name).
|
59
|
+
merge(ChgkRating::AttributeMappings.find(self.superclass.name))
|
57
60
|
end
|
58
61
|
|
59
62
|
def lazy_load?(params)
|
@@ -80,11 +83,20 @@ module ChgkRating
|
|
80
83
|
|
81
84
|
def extract_from(raw_data)
|
82
85
|
self.class.attribute_mapping.each do |attr, mapping|
|
83
|
-
data = raw_data
|
84
|
-
|
85
|
-
instance_variable_set "@#{attr}", data
|
86
|
+
data = get_data_from raw_data, attr, mapping
|
87
|
+
next unless data
|
88
|
+
instance_variable_set "@#{attr}", transform_up(data, mapping)
|
86
89
|
end
|
87
90
|
end
|
91
|
+
|
92
|
+
def get_data_from(raw, attr, mapping)
|
93
|
+
raw.is_a?(self.class) ? raw.send(attr) : raw[ mapping[:raw_name] ]
|
94
|
+
end
|
95
|
+
|
96
|
+
def transform_up(data, mapping)
|
97
|
+
return data unless mapping.has_key?(:transform_up)
|
98
|
+
mapping[:transform_up].call(data)
|
99
|
+
end
|
88
100
|
end
|
89
101
|
end
|
90
|
-
end
|
102
|
+
end
|
@@ -1,6 +1,31 @@
|
|
1
1
|
module ChgkRating
|
2
2
|
module Models
|
3
3
|
class Player < Base
|
4
|
+
# Returns rating for the current Player in a given release
|
5
|
+
#
|
6
|
+
# @return [ChgkRating::Models::PlayerRating] The requested rating.
|
7
|
+
# @param release_id [String or Integer] Release to load rating for.
|
8
|
+
def rating(release_id)
|
9
|
+
ChgkRating::Models::PlayerRating.new release_id, player: self
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns an array-like ratings collection for the current Player.
|
13
|
+
#
|
14
|
+
# @return [ChgkRating::Collection::PlayerRatings] The collection of ratings.
|
15
|
+
def ratings
|
16
|
+
ChgkRating::Collections::PlayerRatings.new player: self
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns a collection of Tournaments that the current player participated at based on the given criteria
|
20
|
+
#
|
21
|
+
# @raise [ChgkRating::Error::NotFound] Error raised when nothing can be found based on the given criteria.
|
22
|
+
# @return [ChgkRating::Collection::PlayerTournaments] The collection of tournaments.
|
23
|
+
# @param season_id [String or Integer] Season to load tournaments for
|
24
|
+
# @option params [String or Integer] :page The requested page. Default is 1
|
25
|
+
def tournaments(season_id = nil)
|
26
|
+
ChgkRating::Collections::PlayerTournaments.new player: self, season_id: season_id
|
27
|
+
end
|
28
|
+
|
4
29
|
private
|
5
30
|
|
6
31
|
def api_path
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ChgkRating
|
2
|
+
module Models
|
3
|
+
class PlayerRating < Rating
|
4
|
+
def initialize(release_id_or_hash, params = {})
|
5
|
+
@player_id = extract_id_from params[:player], ChgkRating::Models::Player
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def api_path
|
12
|
+
"players/#{@player_id}/rating"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -19,19 +19,19 @@ module ChgkRating
|
|
19
19
|
ChgkRating::Models::TournamentTeam.new self, tournament: tournament_or_id, lazy: true
|
20
20
|
end
|
21
21
|
|
22
|
-
# Returns
|
22
|
+
# Returns rating for the current Team in a given release
|
23
23
|
#
|
24
|
-
# @return [ChgkRating::Models::
|
24
|
+
# @return [ChgkRating::Models::TeamRating] The requested rating.
|
25
25
|
# @param release_id [String or Integer] Release to load rating for.
|
26
26
|
def rating(release_id)
|
27
|
-
ChgkRating::Models::
|
27
|
+
ChgkRating::Models::TeamRating.new release_id, team: self
|
28
28
|
end
|
29
29
|
|
30
|
-
# Returns an array-like
|
30
|
+
# Returns an array-like ratings collection for the current Team.
|
31
31
|
#
|
32
|
-
# @return [ChgkRating::Collection::
|
32
|
+
# @return [ChgkRating::Collection::TeamRatings] The collection of ratings.
|
33
33
|
def ratings
|
34
|
-
ChgkRating::Collections::
|
34
|
+
ChgkRating::Collections::TeamRatings.new team: self
|
35
35
|
end
|
36
36
|
|
37
37
|
# Returns an hash-like Recaps collection for the current team, grouped by seasons. Seasons act
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module ChgkRating
|
2
2
|
module Models
|
3
3
|
class Tournament < Base
|
4
|
-
# Returns an array-like
|
4
|
+
# Returns an array-like TournamentTeamPlayers collection containing roster for a team at the current tournament.
|
5
5
|
#
|
6
6
|
# @raise [ChgkRating::Error::NotFound] Error raised when the requested Team cannot be found.
|
7
|
-
# @return [ChgkRating::Collection::
|
7
|
+
# @return [ChgkRating::Collection::TournamentTeamPlayers] The collection of results.
|
8
8
|
# @param team_or_id [String, Integer or ChgkRating::Models::Team] Team to load players for.
|
9
9
|
def team_players(team_or_id)
|
10
|
-
ChgkRating::Collections::
|
10
|
+
ChgkRating::Collections::TournamentTeamPlayers.new tournament: self, team: team_or_id
|
11
11
|
end
|
12
12
|
|
13
13
|
# Returns an array-like TournamentTeamResults collection with results for a given team in the current
|
@@ -32,7 +32,7 @@ module ChgkRating
|
|
32
32
|
# @raise [ChgkRating::Error::NotFound] Error raised when the requested Team cannot be found.
|
33
33
|
# @return [ChgkRating::Models::TournamentTeam] The requested TournamentTeam.
|
34
34
|
# @param team_or_id [String, Integer or Team] Team to search for.
|
35
|
-
def
|
35
|
+
def team_by(team_or_id)
|
36
36
|
ChgkRating::Models::TournamentTeam.new team_or_id, tournament: self, lazy: true
|
37
37
|
end
|
38
38
|
|
@@ -11,11 +11,11 @@ module ChgkRating
|
|
11
11
|
super extract_id_from(team_or_hash), params
|
12
12
|
end
|
13
13
|
|
14
|
-
# Returns an array-like
|
14
|
+
# Returns an array-like TournamentTeamPlayers collection containing roster for the current TournamentTeam
|
15
15
|
#
|
16
|
-
# @return [ChgkRating::Collection::
|
16
|
+
# @return [ChgkRating::Collection::TournamentTeamPlayers] The collection of results.
|
17
17
|
def players
|
18
|
-
ChgkRating::Collections::
|
18
|
+
ChgkRating::Collections::TournamentTeamPlayers.new tournament: @tournament, team: @team
|
19
19
|
end
|
20
20
|
|
21
21
|
# Returns an array-like TournamentTeamResults collection containing results for the current TournamentTeam
|
data/lib/chgk_rating/models/{tournament_team_result.rb → tournament/tournament_team_result.rb}
RENAMED
File without changes
|
data/lib/chgk_rating/version.rb
CHANGED
data/lib/chgk_rating.rb
CHANGED
@@ -21,21 +21,26 @@ require 'chgk_rating/concerns/searching'
|
|
21
21
|
require 'chgk_rating/chgk_object'
|
22
22
|
|
23
23
|
require 'chgk_rating/models/base'
|
24
|
-
require 'chgk_rating/models/tournament_team_result'
|
25
|
-
require 'chgk_rating/models/
|
26
|
-
require 'chgk_rating/models/tournament_team'
|
27
|
-
require 'chgk_rating/models/
|
28
|
-
require 'chgk_rating/models/tournament'
|
24
|
+
require 'chgk_rating/models/tournament/tournament_team_result'
|
25
|
+
require 'chgk_rating/models/tournament/tournament_team_player'
|
26
|
+
require 'chgk_rating/models/tournament/tournament_team'
|
27
|
+
require 'chgk_rating/models/tournament/player_tournament'
|
28
|
+
require 'chgk_rating/models/tournament/tournament'
|
29
|
+
require 'chgk_rating/models/rating/rating'
|
30
|
+
require 'chgk_rating/models/rating/player_rating'
|
31
|
+
require 'chgk_rating/models/rating/team_rating'
|
29
32
|
require 'chgk_rating/models/player'
|
30
33
|
require 'chgk_rating/models/team'
|
31
34
|
require 'chgk_rating/models/recap'
|
32
35
|
|
33
36
|
require 'chgk_rating/collections/base'
|
34
|
-
require 'chgk_rating/collections/tournament_team_results'
|
35
|
-
require 'chgk_rating/collections/
|
36
|
-
require 'chgk_rating/collections/tournament_teams'
|
37
|
-
require 'chgk_rating/collections/
|
38
|
-
require 'chgk_rating/collections/tournaments'
|
37
|
+
require 'chgk_rating/collections/tournaments/tournament_team_results'
|
38
|
+
require 'chgk_rating/collections/tournaments/tournament_team_players'
|
39
|
+
require 'chgk_rating/collections/tournaments/tournament_teams'
|
40
|
+
require 'chgk_rating/collections/tournaments/player_tournaments'
|
41
|
+
require 'chgk_rating/collections/tournaments/tournaments'
|
42
|
+
require 'chgk_rating/collections/ratings/player_ratings'
|
43
|
+
require 'chgk_rating/collections/ratings/team_ratings'
|
39
44
|
require 'chgk_rating/collections/players'
|
40
45
|
require 'chgk_rating/collections/teams'
|
41
46
|
require 'chgk_rating/collections/recaps'
|
@@ -47,12 +47,20 @@ RSpec.describe ChgkRating::Client do
|
|
47
47
|
it { is_expected.to be_an_instance_of ChgkRating::Models::Tournament }
|
48
48
|
end
|
49
49
|
|
50
|
-
describe '#
|
50
|
+
describe '#team_rating' do
|
51
51
|
subject do
|
52
|
-
VCR.use_cassette('rating_release') { test_client.
|
52
|
+
VCR.use_cassette('rating_release') { test_client.team_rating team_1, 24 }
|
53
53
|
end
|
54
54
|
|
55
|
-
it { is_expected.to be_an_instance_of ChgkRating::Models::
|
55
|
+
it { is_expected.to be_an_instance_of ChgkRating::Models::TeamRating }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#player_rating' do
|
59
|
+
subject do
|
60
|
+
VCR.use_cassette('player_rating_release') { test_client.player_rating 42511, 1000 }
|
61
|
+
end
|
62
|
+
|
63
|
+
it { is_expected.to be_an_instance_of ChgkRating::Models::PlayerRating }
|
56
64
|
end
|
57
65
|
|
58
66
|
describe '#recap' do
|
@@ -85,13 +93,22 @@ RSpec.describe ChgkRating::Client do
|
|
85
93
|
end
|
86
94
|
end
|
87
95
|
|
88
|
-
describe '#
|
96
|
+
describe '#team_ratings' do
|
89
97
|
subject do
|
90
98
|
VCR.use_cassette 'team_ratings' do
|
91
|
-
test_client.
|
99
|
+
test_client.team_ratings team_1
|
100
|
+
end
|
101
|
+
end
|
102
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::TeamRatings }
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#player_ratings' do
|
106
|
+
subject do
|
107
|
+
VCR.use_cassette 'player_ratings_all_releases' do
|
108
|
+
test_client.player_ratings 42511
|
92
109
|
end
|
93
110
|
end
|
94
|
-
it { is_expected.to be_an_instance_of ChgkRating::Collections::
|
111
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::PlayerRatings }
|
95
112
|
end
|
96
113
|
|
97
114
|
describe '#team_players_at_tournament' do
|
@@ -101,7 +118,7 @@ RSpec.describe ChgkRating::Client do
|
|
101
118
|
end
|
102
119
|
end
|
103
120
|
|
104
|
-
it { is_expected.to be_an_instance_of ChgkRating::Collections::
|
121
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::TournamentTeamPlayers }
|
105
122
|
end
|
106
123
|
|
107
124
|
describe '#team_results_at_tournament' do
|
@@ -124,6 +141,28 @@ RSpec.describe ChgkRating::Client do
|
|
124
141
|
it { is_expected.to be_an_instance_of ChgkRating::Collections::TournamentTeams }
|
125
142
|
end
|
126
143
|
|
144
|
+
describe '#player_tournaments' do
|
145
|
+
context 'all tournaments for a player by season' do
|
146
|
+
subject do
|
147
|
+
VCR.use_cassette 'player_tournaments_season' do
|
148
|
+
test_client.player_tournaments 1000, 51
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::PlayerTournaments }
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'tournaments for a player' do
|
156
|
+
subject do
|
157
|
+
VCR.use_cassette 'player_tournaments' do
|
158
|
+
test_client.player_tournaments 1000
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::PlayerTournaments }
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
127
166
|
describe '#tournaments' do
|
128
167
|
context 'all tournaments for a team by season' do
|
129
168
|
subject do
|
@@ -0,0 +1,15 @@
|
|
1
|
+
RSpec.describe ChgkRating::Collections::PlayerRatings do
|
2
|
+
subject do
|
3
|
+
VCR.use_cassette 'player_ratings' do
|
4
|
+
described_class.new(player: 1000)[-1]
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
specify('#player') { expect(subject.player.id).to eq '1000' }
|
9
|
+
specify('#release_id') { expect(subject.release_id).to eq '1336' }
|
10
|
+
specify('#rating') { expect(subject.rating).to eq 7674 }
|
11
|
+
specify('#rating_position') { expect(subject.rating_position).to eq 1417 }
|
12
|
+
specify('#date') { expect(subject.date).to eq Date.new(2018, 04, 12) }
|
13
|
+
specify('#tournaments_in_year') { expect(subject.tournaments_in_year).to eq 15 }
|
14
|
+
specify('#tournament_count_total') { expect(subject.tournament_count_total).to eq 284 }
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
RSpec.describe ChgkRating::Collections::PlayerTournaments do
|
2
|
+
context 'all tournaments for a player' do
|
3
|
+
subject do
|
4
|
+
VCR.use_cassette 'player_tournaments' do
|
5
|
+
described_class.new(player: 1000)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
let(:player_tournament) { subject['3'][0] }
|
9
|
+
|
10
|
+
specify '#to_h' do
|
11
|
+
subject_h = subject.to_h['6']
|
12
|
+
expect(subject_h['tournaments'][0]['idtournament']).to eq '220'
|
13
|
+
expect(subject_h['tournaments'][0]['in_base_team']).to eq '1'
|
14
|
+
expect(subject_h['tournaments'][0]['idteam']).to eq '233'
|
15
|
+
expect(subject_h['idplayer']).to eq '1000'
|
16
|
+
end
|
17
|
+
specify('#tournament') { expect(player_tournament.tournament.id).to eq '91' }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'all tournaments for a player by season' do
|
21
|
+
subject do
|
22
|
+
VCR.use_cassette 'player_tournaments_season' do
|
23
|
+
described_class.new(player: 1000, season_id: 51)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
let(:player_tournament) { subject[0] }
|
27
|
+
|
28
|
+
specify '#to_a' do
|
29
|
+
tournaments_arr = subject.to_a
|
30
|
+
expect(tournaments_arr[2]['idtournament']).to eq '4782'
|
31
|
+
end
|
32
|
+
specify('#tournament') { expect(player_tournament.tournament.id).to eq '4712' }
|
33
|
+
specify('#team') { expect(player_tournament.team.id).to eq '51284' }
|
34
|
+
specify('#in_base_team') { expect(player_tournament.in_base_team).to eq false }
|
35
|
+
specify('#player') { expect(subject.player.id).to eq 1000 }
|
36
|
+
specify('#season_id') { expect(subject.season_id).to eq 51 }
|
37
|
+
end
|
38
|
+
end
|
File without changes
|
File without changes
|
data/spec/lib/chgk_rating/collections/{tournaments_spec.rb → tournaments/tournaments_spec.rb}
RENAMED
File without changes
|