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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +12 -12
  3. data/.github/PULL_REQUEST_TEMPLATE.md +10 -10
  4. data/CHANGELOG.md +7 -0
  5. data/Gemfile +2 -6
  6. data/LICENSE +21 -21
  7. data/README.md +2 -1
  8. data/Rakefile +12 -12
  9. data/chgk_rating.gemspec +28 -28
  10. data/lib/chgk_rating.rb +51 -52
  11. data/lib/chgk_rating/attribute_mappings.rb +138 -137
  12. data/lib/chgk_rating/chgk_object.rb +12 -12
  13. data/lib/chgk_rating/client.rb +172 -172
  14. data/lib/chgk_rating/collections/base.rb +78 -78
  15. data/lib/chgk_rating/collections/players.rb +16 -16
  16. data/lib/chgk_rating/collections/ratings.rb +22 -22
  17. data/lib/chgk_rating/collections/recaps.rb +24 -24
  18. data/lib/chgk_rating/collections/teams.rb +16 -16
  19. data/lib/chgk_rating/collections/tournament_players.rb +23 -23
  20. data/lib/chgk_rating/collections/tournament_team_results.rb +23 -23
  21. data/lib/chgk_rating/collections/tournament_teams.rb +21 -21
  22. data/lib/chgk_rating/collections/tournaments.rb +46 -46
  23. data/lib/chgk_rating/concerns/searching.rb +24 -20
  24. data/lib/chgk_rating/connection.rb +18 -18
  25. data/lib/chgk_rating/error.rb +45 -45
  26. data/lib/chgk_rating/models/base.rb +89 -89
  27. data/lib/chgk_rating/models/player.rb +10 -10
  28. data/lib/chgk_rating/models/rating.rb +18 -18
  29. data/lib/chgk_rating/models/recap.rb +18 -18
  30. data/lib/chgk_rating/models/team.rb +61 -61
  31. data/lib/chgk_rating/models/tournament.rb +45 -45
  32. data/lib/chgk_rating/models/tournament_player.rb +7 -7
  33. data/lib/chgk_rating/models/tournament_team.rb +28 -28
  34. data/lib/chgk_rating/models/tournament_team_result.rb +7 -7
  35. data/lib/chgk_rating/request.rb +31 -31
  36. data/lib/chgk_rating/utils/snakecase.rb +15 -15
  37. data/lib/chgk_rating/utils/transformations.rb +82 -82
  38. data/lib/chgk_rating/version.rb +2 -2
  39. data/lib/ext/date.rb +10 -10
  40. data/lib/ext/date_time.rb +4 -4
  41. data/lib/ext/uri.rb +8 -8
  42. data/spec/lib/chgk_rating/client_spec.rb +207 -197
  43. data/spec/lib/chgk_rating/collections/players_spec.rb +44 -44
  44. data/spec/lib/chgk_rating/collections/ratings_spec.rb +24 -24
  45. data/spec/lib/chgk_rating/collections/recaps_spec.rb +20 -20
  46. data/spec/lib/chgk_rating/collections/teams_spec.rb +41 -41
  47. data/spec/lib/chgk_rating/collections/tournament_players_spec.rb +17 -17
  48. data/spec/lib/chgk_rating/collections/tournament_team_results_spec.rb +16 -16
  49. data/spec/lib/chgk_rating/collections/tournament_teams_spec.rb +59 -57
  50. data/spec/lib/chgk_rating/collections/tournaments_spec.rb +61 -61
  51. data/spec/lib/chgk_rating/models/base_spec.rb +33 -33
  52. data/spec/lib/chgk_rating/models/player_spec.rb +34 -34
  53. data/spec/lib/chgk_rating/models/rating_spec.rb +26 -26
  54. data/spec/lib/chgk_rating/models/recap_spec.rb +34 -34
  55. data/spec/lib/chgk_rating/models/team_spec.rb +88 -88
  56. data/spec/lib/chgk_rating/models/tournament_player_spec.rb +20 -20
  57. data/spec/lib/chgk_rating/models/tournament_spec.rb +91 -91
  58. data/spec/lib/chgk_rating/models/tournament_team_result_spec.rb +18 -18
  59. data/spec/lib/chgk_rating/models/tournament_team_spec.rb +35 -35
  60. data/spec/lib/chgk_rating/utils/snakecase_spec.rb +11 -11
  61. data/spec/lib/chgk_rating/utils/transformations_spec.rb +15 -15
  62. data/spec/lib/chgk_rating_spec.rb +4 -4
  63. data/spec/lib/ext/date_spec.rb +6 -6
  64. data/spec/lib/ext/date_time_spec.rb +10 -10
  65. data/spec/lib/ext/uri_spec.rb +6 -6
  66. data/spec/spec_helper.rb +12 -12
  67. data/spec/support/shared_examples.rb +62 -62
  68. data/spec/support/test_client.rb +5 -5
  69. data/spec/support/vcr.rb +10 -9
  70. 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
- context 'errors' do
13
- it 'should raise an error for an erroneous request' do
14
- expect( -> { VCR.use_cassette 'erroneous_request' do
15
- test_client.tournament '/thats/an/error'
16
- end } ).to raise_error(ChgkRating::Error::NotFound)
17
- end
18
- end
19
-
20
- describe '#team_at_tournament' do
21
- subject { test_client.team_at_tournament tournament_3506, team_52853 }
22
-
23
- it { is_expected.to be_an_instance_of ChgkRating::Models::TournamentTeam }
24
-
25
- include_examples 'lazy loaded' do
26
- let(:object) { subject }
27
- end
28
- end
29
-
30
- describe '#tournament' do
31
- subject { test_client.tournament 3506, true }
32
-
33
- include_examples 'lazy loaded' do
34
- let(:object) { subject }
35
- end
36
-
37
- it { is_expected.to be_an_instance_of ChgkRating::Models::Tournament }
38
- end
39
-
40
- describe '#rating' do
41
- subject do
42
- VCR.use_cassette('rating_release') { test_client.rating team_1, 24 }
43
- end
44
-
45
- it { is_expected.to be_an_instance_of ChgkRating::Models::Rating }
46
- end
47
-
48
- describe '#recap' do
49
- subject do
50
- VCR.use_cassette 'recap_last_season' do
51
- test_client.recap test_client.team(7931, true), :last
52
- end
53
- end
54
-
55
- it { is_expected.to be_an_instance_of ChgkRating::Models::Recap }
56
- end
57
-
58
- describe '#team' do
59
- subject { test_client.team 1, true }
60
-
61
- it { is_expected.to be_an_instance_of ChgkRating::Models::Team }
62
-
63
- include_examples 'lazy loaded' do
64
- let(:object) { subject }
65
- end
66
- end
67
-
68
- describe '#player' do
69
- subject { test_client.player 42511, true }
70
-
71
- it { is_expected.to be_an_instance_of ChgkRating::Models::Player }
72
-
73
- include_examples 'lazy loaded' do
74
- let(:object) { subject }
75
- end
76
- end
77
-
78
- describe '#ratings' do
79
- subject do
80
- VCR.use_cassette 'team_ratings' do
81
- test_client.ratings team_1
82
- end
83
- end
84
- it { is_expected.to be_an_instance_of ChgkRating::Collections::Ratings }
85
- end
86
-
87
- describe '#team_players_at_tournament' do
88
- subject do
89
- VCR.use_cassette 'team_players_at_tournament' do
90
- test_client.team_players_at_tournament tournament_3506, team_52853
91
- end
92
- end
93
-
94
- it { is_expected.to be_an_instance_of ChgkRating::Collections::TournamentPlayers }
95
- end
96
-
97
- describe '#team_results_at_tournament' do
98
- subject do
99
- VCR.use_cassette 'team_results_at_tournament' do
100
- test_client.team_results_at_tournament tournament_3506, team_52853
101
- end
102
- end
103
-
104
- it { is_expected.to be_an_instance_of ChgkRating::Collections::TournamentTeamResults }
105
- end
106
-
107
- describe '#teams_at_tournament' do
108
- subject do
109
- VCR.use_cassette 'teams_at_tournament' do
110
- test_client.teams_at_tournament tournament_3506
111
- end
112
- end
113
-
114
- it { is_expected.to be_an_instance_of ChgkRating::Collections::TournamentTeams }
115
- end
116
-
117
- describe '#tournaments' do
118
- context 'all tournaments for a team by season' do
119
- subject do
120
- VCR.use_cassette 'team_tournaments_season' do
121
- test_client.tournaments team_or_id: team_1, season_id: 4
122
- end
123
- end
124
-
125
- it { is_expected.to be_an_instance_of ChgkRating::Collections::Tournaments }
126
- end
127
-
128
- context 'tournaments for a team' do
129
- subject do
130
- VCR.use_cassette 'team_tournaments' do
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 'all tournaments' do
139
- subject do
140
- VCR.use_cassette 'tournaments' do
141
- test_client.tournaments
142
- end
143
- end
144
-
145
- it { is_expected.to be_an_instance_of ChgkRating::Collections::Tournaments }
146
- end
147
- end
148
-
149
- describe '#recaps' do
150
- subject do
151
- VCR.use_cassette 'recaps' do
152
- test_client.recaps team_1
153
- end
154
- end
155
-
156
- it { is_expected.to be_an_instance_of ChgkRating::Collections::Recaps }
157
- end
158
-
159
- describe '#search_teams' do
160
- subject do
161
- VCR.use_cassette 'teams_searching' do
162
- test_client.search_teams name: 'э', town: 'мин'
163
- end
164
- end
165
-
166
- it { is_expected.to be_an_instance_of ChgkRating::Collections::Teams::Search }
167
- end
168
-
169
- describe '#teams' do
170
- subject do
171
- VCR.use_cassette 'teams' do
172
- test_client.teams
173
- end
174
- end
175
-
176
- it { is_expected.to be_an_instance_of ChgkRating::Collections::Teams }
177
- end
178
-
179
- describe '#search_players' do
180
- subject do
181
- VCR.use_cassette 'players_searching' do
182
- test_client.search_players name: 'вас', surname: 'а'
183
- end
184
- end
185
-
186
- it { is_expected.to be_an_instance_of ChgkRating::Collections::Players::Search }
187
- end
188
-
189
- describe '#players' do
190
- subject do
191
- VCR.use_cassette 'players' do
192
- test_client.players
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