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
@@ -1,17 +1,17 @@
1
- module ChgkRating
2
- module Collections
3
- class Players < Base
4
- include ChgkRating::Concerns::Searching
5
-
6
- private
7
-
8
- def process(_results, params = {})
9
- super { |result| ChgkRating::Models::Player.new result, lazy: params[:lazy] }
10
- end
11
-
12
- def api_path
13
- 'players'
14
- end
15
- end
16
- end
1
+ module ChgkRating
2
+ module Collections
3
+ class Players < Base
4
+ include ChgkRating::Concerns::Searching
5
+
6
+ private
7
+
8
+ def process(_results, params = {})
9
+ super { |result| ChgkRating::Models::Player.new result, lazy: params[:lazy] }
10
+ end
11
+
12
+ def api_path
13
+ 'players'
14
+ end
15
+ end
16
+ end
17
17
  end
@@ -1,23 +1,23 @@
1
- module ChgkRating
2
- module Collections
3
- class Ratings < Base
4
- attr_reader :team
5
-
6
- def initialize(params = {})
7
- @team = build_model params[:team]
8
-
9
- super
10
- end
11
-
12
- private
13
-
14
- def process(*_args)
15
- super { |result| ChgkRating::Models::Rating.new result }
16
- end
17
-
18
- def api_path
19
- "teams/#{@team.id}/rating"
20
- end
21
- end
22
- end
1
+ module ChgkRating
2
+ module Collections
3
+ class Ratings < Base
4
+ attr_reader :team
5
+
6
+ def initialize(params = {})
7
+ @team = build_model params[:team]
8
+
9
+ super
10
+ end
11
+
12
+ private
13
+
14
+ def process(*_args)
15
+ super { |result| ChgkRating::Models::Rating.new result }
16
+ end
17
+
18
+ def api_path
19
+ "teams/#{@team.id}/rating"
20
+ end
21
+ end
22
+ end
23
23
  end
@@ -1,25 +1,25 @@
1
- module ChgkRating
2
- module Collections
3
- class Recaps < Base
4
- attr_reader :team
5
-
6
- def initialize(params = {})
7
- @team = build_model params[:team]
8
-
9
- super
10
- end
11
-
12
- private
13
-
14
- def process(results, _params)
15
- results.each do |season,value|
16
- results[season] = ChgkRating::Models::Recap.new value, team: @team
17
- end
18
- end
19
-
20
- def api_path
21
- "teams/#{@team.id}/recaps"
22
- end
23
- end
24
- end
1
+ module ChgkRating
2
+ module Collections
3
+ class Recaps < Base
4
+ attr_reader :team
5
+
6
+ def initialize(params = {})
7
+ @team = build_model params[:team]
8
+
9
+ super
10
+ end
11
+
12
+ private
13
+
14
+ def process(results, _params)
15
+ results.each do |season,value|
16
+ results[season] = ChgkRating::Models::Recap.new value, team: @team
17
+ end
18
+ end
19
+
20
+ def api_path
21
+ "teams/#{@team.id}/recaps"
22
+ end
23
+ end
24
+ end
25
25
  end
@@ -1,17 +1,17 @@
1
- module ChgkRating
2
- module Collections
3
- class Teams < Base
4
- include ChgkRating::Concerns::Searching
5
-
6
- private
7
-
8
- def process(_results, params = {})
9
- super { |result| ChgkRating::Models::Team.new result, lazy: params[:lazy] }
10
- end
11
-
12
- def api_path
13
- 'teams'
14
- end
15
- end
16
- end
1
+ module ChgkRating
2
+ module Collections
3
+ class Teams < Base
4
+ include ChgkRating::Concerns::Searching
5
+
6
+ private
7
+
8
+ def process(_results, params = {})
9
+ super { |result| ChgkRating::Models::Team.new result, lazy: params[:lazy] }
10
+ end
11
+
12
+ def api_path
13
+ 'teams'
14
+ end
15
+ end
16
+ end
17
17
  end
@@ -1,24 +1,24 @@
1
- module ChgkRating
2
- module Collections
3
- class TournamentPlayers < Base
4
- attr_reader :team, :tournament
5
-
6
- def initialize(params = {})
7
- @tournament = build_model params[:tournament], ChgkRating::Models::Tournament
8
- @team = build_model params[:team]
9
-
10
- super
11
- end
12
-
13
- private
14
-
15
- def process(*_args)
16
- super { |result| ChgkRating::Models::TournamentPlayer.new result }
17
- end
18
-
19
- def api_path
20
- "tournaments/#{@tournament.id}/recaps/#{@team.id}"
21
- end
22
- end
23
- end
1
+ module ChgkRating
2
+ module Collections
3
+ class TournamentPlayers < Base
4
+ attr_reader :team, :tournament
5
+
6
+ def initialize(params = {})
7
+ @tournament = build_model params[:tournament], ChgkRating::Models::Tournament
8
+ @team = build_model params[:team]
9
+
10
+ super
11
+ end
12
+
13
+ private
14
+
15
+ def process(*_args)
16
+ super { |result| ChgkRating::Models::TournamentPlayer.new result }
17
+ end
18
+
19
+ def api_path
20
+ "tournaments/#{@tournament.id}/recaps/#{@team.id}"
21
+ end
22
+ end
23
+ end
24
24
  end
@@ -1,24 +1,24 @@
1
- module ChgkRating
2
- module Collections
3
- class TournamentTeamResults < Base
4
- attr_reader :team, :tournament
5
-
6
- def initialize(params)
7
- @tournament = build_model params[:tournament], ChgkRating::Models::Tournament
8
- @team = build_model params[:team]
9
-
10
- super
11
- end
12
-
13
- private
14
-
15
- def process(*_args)
16
- super { |result| ChgkRating::Models::TournamentTeamResult.new result }
17
- end
18
-
19
- def api_path
20
- "tournaments/#{@tournament.id}/results/#{@team.id}"
21
- end
22
- end
23
- end
1
+ module ChgkRating
2
+ module Collections
3
+ class TournamentTeamResults < Base
4
+ attr_reader :team, :tournament
5
+
6
+ def initialize(params)
7
+ @tournament = build_model params[:tournament], ChgkRating::Models::Tournament
8
+ @team = build_model params[:team]
9
+
10
+ super
11
+ end
12
+
13
+ private
14
+
15
+ def process(*_args)
16
+ super { |result| ChgkRating::Models::TournamentTeamResult.new result }
17
+ end
18
+
19
+ def api_path
20
+ "tournaments/#{@tournament.id}/results/#{@team.id}"
21
+ end
22
+ end
23
+ end
24
24
  end
@@ -1,22 +1,22 @@
1
- module ChgkRating
2
- module Collections
3
- class TournamentTeams < Base
4
- attr_reader :tournament
5
- def initialize(params = {})
6
- @tournament = build_model params[:tournament], ChgkRating::Models::Tournament
7
-
8
- super
9
- end
10
-
11
- private
12
-
13
- def process(_results, params = {})
14
- super { |result| ChgkRating::Models::TournamentTeam.new result, lazy: params[:lazy] }
15
- end
16
-
17
- def api_path
18
- "tournaments/#{@tournament.id}/list"
19
- end
20
- end
21
- end
1
+ module ChgkRating
2
+ module Collections
3
+ class TournamentTeams < Base
4
+ attr_reader :tournament
5
+ def initialize(params = {})
6
+ @tournament = build_model params[:tournament], ChgkRating::Models::Tournament
7
+
8
+ super
9
+ end
10
+
11
+ private
12
+
13
+ def process(_results, params = {})
14
+ super { |result| ChgkRating::Models::TournamentTeam.new result, lazy: params[:lazy] }
15
+ end
16
+
17
+ def api_path
18
+ "tournaments/#{@tournament.id}/list"
19
+ end
20
+ end
21
+ end
22
22
  end
@@ -1,47 +1,47 @@
1
- module ChgkRating
2
- module Collections
3
- class Tournaments < Base
4
- attr_reader :team, :season_id
5
-
6
- def initialize(params = {})
7
- @team = build_model params[:team]
8
-
9
- @season_id = params[:season_id]
10
- params.merge!(lazy: true) if @team || @season_id
11
- super
12
- end
13
-
14
- def revert_to_hash(key, values)
15
- [
16
- key,
17
- {
18
- 'idteam' => @team.id.to_s,
19
- 'idseason' => key,
20
- 'tournaments' => values.map(&:to_h)
21
- }
22
- ]
23
- end
24
-
25
- private
26
-
27
- def process(_results, params = {})
28
- super do |result|
29
- if @team && @season_id.nil?
30
- ChgkRating::Collections::Tournaments.new(collection: result['tournaments'],
31
- lazy: true).items
32
- else
33
- ChgkRating::Models::Tournament.new result, lazy: params[:lazy]
34
- end
35
- end
36
- end
37
-
38
- def api_path
39
- path = 'tournaments'
40
- return path unless @team
41
- path = "teams/#{@team.id}/#{path}"
42
- return path unless @season_id
43
- path + "/#{@season_id}"
44
- end
45
- end
46
- end
1
+ module ChgkRating
2
+ module Collections
3
+ class Tournaments < Base
4
+ attr_reader :team, :season_id
5
+
6
+ def initialize(params = {})
7
+ @team = build_model params[:team]
8
+
9
+ @season_id = params[:season_id]
10
+ params.merge!(lazy: true) if @team || @season_id
11
+ super
12
+ end
13
+
14
+ def revert_to_hash(key, values)
15
+ [
16
+ key,
17
+ {
18
+ 'idteam' => @team.id.to_s,
19
+ 'idseason' => key,
20
+ 'tournaments' => values.map(&:to_h)
21
+ }
22
+ ]
23
+ end
24
+
25
+ private
26
+
27
+ def process(_results, params = {})
28
+ super do |result|
29
+ if @team && @season_id.nil?
30
+ ChgkRating::Collections::Tournaments.new(collection: result['tournaments'],
31
+ lazy: true).items
32
+ else
33
+ ChgkRating::Models::Tournament.new result, lazy: params[:lazy]
34
+ end
35
+ end
36
+ end
37
+
38
+ def api_path
39
+ path = 'tournaments'
40
+ return path unless @team
41
+ path = "teams/#{@team.id}/#{path}"
42
+ return path unless @season_id
43
+ path + "/#{@season_id}"
44
+ end
45
+ end
46
+ end
47
47
  end
@@ -1,21 +1,25 @@
1
- module ChgkRating
2
- module Concerns
3
- module Searching
4
- # some black magic
5
- def self.included(klass)
6
- klass.const_set(
7
- 'Search',
8
- Class.new(klass) do |*_args|
9
- def api_path
10
- super + '/search'
11
- end
12
- end
13
- )
14
-
15
- klass.define_singleton_method :search do |params|
16
- klass.const_get('Search').new(params)
17
- end
18
- end
19
- end
20
- end
1
+ module ChgkRating
2
+ module Concerns
3
+ module Searching
4
+ # Some black magic indeed...
5
+ # Creates a Search child class of a given class that changes the URI where the
6
+ # GET request should be sent
7
+ def self.included(klass)
8
+ klass.const_set('Search',
9
+ Class.new(klass) do |*_args|
10
+ def api_path
11
+ super + '/search'
12
+ end
13
+ end
14
+ )
15
+
16
+ # The actual method to perform searching
17
+ # Instantiates a Search class with the given search params
18
+ # and send a GET request to the proper URI (defined above)
19
+ klass.define_singleton_method :search do |params|
20
+ klass.const_get('Search').new(params)
21
+ end
22
+ end
23
+ end
24
+ end
21
25
  end