chgk_rating 1.0.0.rc1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +12 -12
- data/.github/PULL_REQUEST_TEMPLATE.md +10 -10
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -6
- data/LICENSE +21 -21
- data/README.md +2 -1
- data/Rakefile +12 -12
- data/chgk_rating.gemspec +28 -28
- data/lib/chgk_rating.rb +51 -52
- data/lib/chgk_rating/attribute_mappings.rb +138 -137
- data/lib/chgk_rating/chgk_object.rb +12 -12
- data/lib/chgk_rating/client.rb +172 -172
- data/lib/chgk_rating/collections/base.rb +78 -78
- data/lib/chgk_rating/collections/players.rb +16 -16
- data/lib/chgk_rating/collections/ratings.rb +22 -22
- data/lib/chgk_rating/collections/recaps.rb +24 -24
- data/lib/chgk_rating/collections/teams.rb +16 -16
- data/lib/chgk_rating/collections/tournament_players.rb +23 -23
- data/lib/chgk_rating/collections/tournament_team_results.rb +23 -23
- data/lib/chgk_rating/collections/tournament_teams.rb +21 -21
- data/lib/chgk_rating/collections/tournaments.rb +46 -46
- data/lib/chgk_rating/concerns/searching.rb +24 -20
- data/lib/chgk_rating/connection.rb +18 -18
- data/lib/chgk_rating/error.rb +45 -45
- data/lib/chgk_rating/models/base.rb +89 -89
- data/lib/chgk_rating/models/player.rb +10 -10
- data/lib/chgk_rating/models/rating.rb +18 -18
- data/lib/chgk_rating/models/recap.rb +18 -18
- data/lib/chgk_rating/models/team.rb +61 -61
- data/lib/chgk_rating/models/tournament.rb +45 -45
- data/lib/chgk_rating/models/tournament_player.rb +7 -7
- data/lib/chgk_rating/models/tournament_team.rb +28 -28
- data/lib/chgk_rating/models/tournament_team_result.rb +7 -7
- data/lib/chgk_rating/request.rb +31 -31
- data/lib/chgk_rating/utils/snakecase.rb +15 -15
- data/lib/chgk_rating/utils/transformations.rb +82 -82
- data/lib/chgk_rating/version.rb +2 -2
- data/lib/ext/date.rb +10 -10
- data/lib/ext/date_time.rb +4 -4
- data/lib/ext/uri.rb +8 -8
- data/spec/lib/chgk_rating/client_spec.rb +207 -197
- data/spec/lib/chgk_rating/collections/players_spec.rb +44 -44
- data/spec/lib/chgk_rating/collections/ratings_spec.rb +24 -24
- data/spec/lib/chgk_rating/collections/recaps_spec.rb +20 -20
- data/spec/lib/chgk_rating/collections/teams_spec.rb +41 -41
- data/spec/lib/chgk_rating/collections/tournament_players_spec.rb +17 -17
- data/spec/lib/chgk_rating/collections/tournament_team_results_spec.rb +16 -16
- data/spec/lib/chgk_rating/collections/tournament_teams_spec.rb +59 -57
- data/spec/lib/chgk_rating/collections/tournaments_spec.rb +61 -61
- data/spec/lib/chgk_rating/models/base_spec.rb +33 -33
- data/spec/lib/chgk_rating/models/player_spec.rb +34 -34
- data/spec/lib/chgk_rating/models/rating_spec.rb +26 -26
- data/spec/lib/chgk_rating/models/recap_spec.rb +34 -34
- data/spec/lib/chgk_rating/models/team_spec.rb +88 -88
- data/spec/lib/chgk_rating/models/tournament_player_spec.rb +20 -20
- data/spec/lib/chgk_rating/models/tournament_spec.rb +91 -91
- data/spec/lib/chgk_rating/models/tournament_team_result_spec.rb +18 -18
- data/spec/lib/chgk_rating/models/tournament_team_spec.rb +35 -35
- data/spec/lib/chgk_rating/utils/snakecase_spec.rb +11 -11
- data/spec/lib/chgk_rating/utils/transformations_spec.rb +15 -15
- data/spec/lib/chgk_rating_spec.rb +4 -4
- data/spec/lib/ext/date_spec.rb +6 -6
- data/spec/lib/ext/date_time_spec.rb +10 -10
- data/spec/lib/ext/uri_spec.rb +6 -6
- data/spec/spec_helper.rb +12 -12
- data/spec/support/shared_examples.rb +62 -62
- data/spec/support/test_client.rb +5 -5
- data/spec/support/vcr.rb +10 -9
- metadata +5 -5
data/lib/ext/date.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
class Date
|
2
|
-
def self.parse_safely(raw_date_time)
|
3
|
-
begin
|
4
|
-
self.parse raw_date_time
|
5
|
-
rescue ArgumentError
|
6
|
-
nil
|
7
|
-
rescue TypeError
|
8
|
-
nil
|
9
|
-
end
|
10
|
-
end
|
1
|
+
class Date
|
2
|
+
def self.parse_safely(raw_date_time)
|
3
|
+
begin
|
4
|
+
self.parse raw_date_time
|
5
|
+
rescue ArgumentError
|
6
|
+
nil
|
7
|
+
rescue TypeError
|
8
|
+
nil
|
9
|
+
end
|
10
|
+
end
|
11
11
|
end
|
data/lib/ext/date_time.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
class DateTime
|
2
|
-
def to_s_chgk
|
3
|
-
self.strftime('%Y-%m-%d %H:%M:%S')
|
4
|
-
end
|
1
|
+
class DateTime
|
2
|
+
def to_s_chgk
|
3
|
+
self.strftime('%Y-%m-%d %H:%M:%S')
|
4
|
+
end
|
5
5
|
end
|
data/lib/ext/uri.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
module URI
|
2
|
-
def self.parse_safely(raw_uri)
|
3
|
-
begin
|
4
|
-
URI.parse raw_uri
|
5
|
-
rescue URI::InvalidURIError
|
6
|
-
nil
|
7
|
-
end
|
8
|
-
end
|
1
|
+
module URI
|
2
|
+
def self.parse_safely(raw_uri)
|
3
|
+
begin
|
4
|
+
URI.parse raw_uri
|
5
|
+
rescue URI::InvalidURIError
|
6
|
+
nil
|
7
|
+
end
|
8
|
+
end
|
9
9
|
end
|
@@ -1,198 +1,208 @@
|
|
1
|
-
RSpec.shared_examples 'lazy loaded' do
|
2
|
-
it 'is lazy loaded' do
|
3
|
-
expect(object.lazy).to eq(true)
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
RSpec.describe ChgkRating::Client do
|
8
|
-
let(:team_1) { test_client.team(1, true) }
|
9
|
-
let(:team_52853) { test_client.team(52853, true) }
|
10
|
-
let(:tournament_3506) { test_client.tournament(3506, true) }
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '#
|
31
|
-
subject { test_client.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#
|
41
|
-
subject
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
it { is_expected.to be_an_instance_of ChgkRating::Models::
|
56
|
-
end
|
57
|
-
|
58
|
-
describe '#
|
59
|
-
subject
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
describe '#
|
69
|
-
subject { test_client.
|
70
|
-
|
71
|
-
it { is_expected.to be_an_instance_of ChgkRating::Models::
|
72
|
-
|
73
|
-
include_examples 'lazy loaded' do
|
74
|
-
let(:object) { subject }
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe '#
|
79
|
-
subject
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
it { is_expected.to be_an_instance_of ChgkRating::Collections::
|
95
|
-
end
|
96
|
-
|
97
|
-
describe '#
|
98
|
-
subject do
|
99
|
-
VCR.use_cassette '
|
100
|
-
test_client.
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
it { is_expected.to be_an_instance_of ChgkRating::Collections::
|
105
|
-
end
|
106
|
-
|
107
|
-
describe '#
|
108
|
-
subject do
|
109
|
-
VCR.use_cassette '
|
110
|
-
test_client.
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
it { is_expected.to be_an_instance_of ChgkRating::Collections::
|
115
|
-
end
|
116
|
-
|
117
|
-
describe '#
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
context 'tournaments for a team' do
|
129
|
-
subject do
|
130
|
-
VCR.use_cassette '
|
131
|
-
test_client.tournaments team_or_id: team_1
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
it { is_expected.to be_an_instance_of ChgkRating::Collections::Tournaments }
|
136
|
-
end
|
137
|
-
|
138
|
-
context '
|
139
|
-
subject do
|
140
|
-
VCR.use_cassette '
|
141
|
-
test_client.tournaments
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
it { is_expected.to be_an_instance_of ChgkRating::Collections::Tournaments }
|
146
|
-
end
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
describe '#
|
160
|
-
subject do
|
161
|
-
VCR.use_cassette '
|
162
|
-
test_client.
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
it { is_expected.to be_an_instance_of ChgkRating::Collections::
|
167
|
-
end
|
168
|
-
|
169
|
-
describe '#
|
170
|
-
subject do
|
171
|
-
VCR.use_cassette '
|
172
|
-
test_client.
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
it { is_expected.to be_an_instance_of ChgkRating::Collections::Teams }
|
177
|
-
end
|
178
|
-
|
179
|
-
describe '#
|
180
|
-
subject do
|
181
|
-
VCR.use_cassette '
|
182
|
-
test_client.
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
it { is_expected.to be_an_instance_of ChgkRating::Collections::
|
187
|
-
end
|
188
|
-
|
189
|
-
describe '#
|
190
|
-
subject do
|
191
|
-
VCR.use_cassette '
|
192
|
-
test_client.
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
it { is_expected.to be_an_instance_of ChgkRating::Collections::Players }
|
197
|
-
end
|
1
|
+
RSpec.shared_examples 'lazy loaded' do
|
2
|
+
it 'is lazy loaded' do
|
3
|
+
expect(object.lazy).to eq(true)
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
RSpec.describe ChgkRating::Client do
|
8
|
+
let(:team_1) { test_client.team(1, true) }
|
9
|
+
let(:team_52853) { test_client.team(52853, true) }
|
10
|
+
let(:tournament_3506) { test_client.tournament(3506, true) }
|
11
|
+
|
12
|
+
def with_erroneous_cassette
|
13
|
+
VCR.use_cassette('erroneous_request') { yield }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'errors' do
|
17
|
+
it 'should raise an error for an erroneous request' do
|
18
|
+
expect do
|
19
|
+
# That's a very strange bug that makes VCR raise UnhandledHTTPError
|
20
|
+
# so for now disable VCR for Ruby 2.5+
|
21
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5.0')
|
22
|
+
test_client.tournament '/thats/an/error'
|
23
|
+
else
|
24
|
+
with_erroneous_cassette { test_client.tournament '/thats/an/error' }
|
25
|
+
end
|
26
|
+
end.to raise_error(ChgkRating::Error::NotFound)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#team_at_tournament' do
|
31
|
+
subject { test_client.team_at_tournament tournament_3506, team_52853 }
|
32
|
+
|
33
|
+
it { is_expected.to be_an_instance_of ChgkRating::Models::TournamentTeam }
|
34
|
+
|
35
|
+
include_examples 'lazy loaded' do
|
36
|
+
let(:object) { subject }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#tournament' do
|
41
|
+
subject { test_client.tournament 3506, true }
|
42
|
+
|
43
|
+
include_examples 'lazy loaded' do
|
44
|
+
let(:object) { subject }
|
45
|
+
end
|
46
|
+
|
47
|
+
it { is_expected.to be_an_instance_of ChgkRating::Models::Tournament }
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#rating' do
|
51
|
+
subject do
|
52
|
+
VCR.use_cassette('rating_release') { test_client.rating team_1, 24 }
|
53
|
+
end
|
54
|
+
|
55
|
+
it { is_expected.to be_an_instance_of ChgkRating::Models::Rating }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#recap' do
|
59
|
+
subject do
|
60
|
+
VCR.use_cassette 'recap_last_season' do
|
61
|
+
test_client.recap test_client.team(7931, true), :last
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it { is_expected.to be_an_instance_of ChgkRating::Models::Recap }
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#team' do
|
69
|
+
subject { test_client.team 1, true }
|
70
|
+
|
71
|
+
it { is_expected.to be_an_instance_of ChgkRating::Models::Team }
|
72
|
+
|
73
|
+
include_examples 'lazy loaded' do
|
74
|
+
let(:object) { subject }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#player' do
|
79
|
+
subject { test_client.player 42511, true }
|
80
|
+
|
81
|
+
it { is_expected.to be_an_instance_of ChgkRating::Models::Player }
|
82
|
+
|
83
|
+
include_examples 'lazy loaded' do
|
84
|
+
let(:object) { subject }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#ratings' do
|
89
|
+
subject do
|
90
|
+
VCR.use_cassette 'team_ratings' do
|
91
|
+
test_client.ratings team_1
|
92
|
+
end
|
93
|
+
end
|
94
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::Ratings }
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#team_players_at_tournament' do
|
98
|
+
subject do
|
99
|
+
VCR.use_cassette 'team_players_at_tournament' do
|
100
|
+
test_client.team_players_at_tournament tournament_3506, team_52853
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::TournamentPlayers }
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#team_results_at_tournament' do
|
108
|
+
subject do
|
109
|
+
VCR.use_cassette 'team_results_at_tournament' do
|
110
|
+
test_client.team_results_at_tournament tournament_3506, team_52853
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::TournamentTeamResults }
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#teams_at_tournament' do
|
118
|
+
subject do
|
119
|
+
VCR.use_cassette 'teams_at_tournament' do
|
120
|
+
test_client.teams_at_tournament tournament_3506
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::TournamentTeams }
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#tournaments' do
|
128
|
+
context 'all tournaments for a team by season' do
|
129
|
+
subject do
|
130
|
+
VCR.use_cassette 'team_tournaments_season' do
|
131
|
+
test_client.tournaments team_or_id: team_1, season_id: 4
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::Tournaments }
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'tournaments for a team' do
|
139
|
+
subject do
|
140
|
+
VCR.use_cassette 'team_tournaments' do
|
141
|
+
test_client.tournaments team_or_id: team_1
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::Tournaments }
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'all tournaments' do
|
149
|
+
subject do
|
150
|
+
VCR.use_cassette 'tournaments' do
|
151
|
+
test_client.tournaments
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::Tournaments }
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe '#recaps' do
|
160
|
+
subject do
|
161
|
+
VCR.use_cassette 'recaps' do
|
162
|
+
test_client.recaps team_1
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::Recaps }
|
167
|
+
end
|
168
|
+
|
169
|
+
describe '#search_teams' do
|
170
|
+
subject do
|
171
|
+
VCR.use_cassette 'teams_searching' do
|
172
|
+
test_client.search_teams name: 'э', town: 'мин'
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::Teams::Search }
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '#teams' do
|
180
|
+
subject do
|
181
|
+
VCR.use_cassette 'teams' do
|
182
|
+
test_client.teams
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::Teams }
|
187
|
+
end
|
188
|
+
|
189
|
+
describe '#search_players' do
|
190
|
+
subject do
|
191
|
+
VCR.use_cassette 'players_searching' do
|
192
|
+
test_client.search_players name: 'вас', surname: 'а'
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::Players::Search }
|
197
|
+
end
|
198
|
+
|
199
|
+
describe '#players' do
|
200
|
+
subject do
|
201
|
+
VCR.use_cassette 'players' do
|
202
|
+
test_client.players
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
it { is_expected.to be_an_instance_of ChgkRating::Collections::Players }
|
207
|
+
end
|
198
208
|
end
|