chgk_rating 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile +3 -1
- data/LICENSE +1 -1
- data/README.md +4 -4
- data/Rakefile +4 -2
- data/chgk_rating.gemspec +19 -12
- data/lib/chgk_rating/attribute_mappings.rb +107 -108
- data/lib/chgk_rating/chgk_object.rb +5 -1
- data/lib/chgk_rating/client.rb +4 -2
- data/lib/chgk_rating/collections/base.rb +20 -15
- data/lib/chgk_rating/collections/players.rb +3 -1
- data/lib/chgk_rating/collections/ratings/player_ratings.rb +3 -1
- data/lib/chgk_rating/collections/ratings/team_ratings.rb +3 -1
- data/lib/chgk_rating/collections/recaps.rb +4 -2
- data/lib/chgk_rating/collections/teams.rb +3 -1
- data/lib/chgk_rating/collections/tournaments/player_tournaments.rb +12 -8
- data/lib/chgk_rating/collections/tournaments/tournament_team_players.rb +3 -1
- data/lib/chgk_rating/collections/tournaments/tournament_team_results.rb +3 -1
- data/lib/chgk_rating/collections/tournaments/tournament_teams.rb +4 -1
- data/lib/chgk_rating/collections/tournaments/tournaments.rb +12 -8
- data/lib/chgk_rating/concerns/searching.rb +10 -9
- data/lib/chgk_rating/connection.rb +10 -8
- data/lib/chgk_rating/error.rb +7 -5
- data/lib/chgk_rating/models/base.rb +23 -16
- data/lib/chgk_rating/models/player.rb +3 -1
- data/lib/chgk_rating/models/rating/player_rating.rb +3 -1
- data/lib/chgk_rating/models/rating/rating.rb +3 -1
- data/lib/chgk_rating/models/rating/team_rating.rb +3 -1
- data/lib/chgk_rating/models/recap.rb +3 -1
- data/lib/chgk_rating/models/team.rb +3 -1
- data/lib/chgk_rating/models/tournament/player_tournament.rb +3 -1
- data/lib/chgk_rating/models/tournament/tournament.rb +3 -1
- data/lib/chgk_rating/models/tournament/tournament_team.rb +3 -1
- data/lib/chgk_rating/models/tournament/tournament_team_player.rb +3 -1
- data/lib/chgk_rating/models/tournament/tournament_team_result.rb +3 -1
- data/lib/chgk_rating/request.rb +10 -9
- data/lib/chgk_rating/utils/snakecase.rb +9 -7
- data/lib/chgk_rating/utils/transformations.rb +42 -36
- data/lib/chgk_rating/version.rb +4 -2
- data/lib/chgk_rating.rb +3 -1
- data/lib/ext/date.rb +6 -8
- data/lib/ext/date_time.rb +4 -2
- data/lib/ext/uri.rb +6 -6
- metadata +61 -80
- data/spec/lib/chgk_rating/client_spec.rb +0 -247
- data/spec/lib/chgk_rating/collections/player_ratings_spec.rb +0 -15
- data/spec/lib/chgk_rating/collections/players_spec.rb +0 -45
- data/spec/lib/chgk_rating/collections/recaps_spec.rb +0 -21
- data/spec/lib/chgk_rating/collections/team_ratings_spec.rb +0 -25
- data/spec/lib/chgk_rating/collections/teams_spec.rb +0 -42
- data/spec/lib/chgk_rating/collections/tournaments/player_tournaments_spec.rb +0 -38
- data/spec/lib/chgk_rating/collections/tournaments/tournament_team_players_spec.rb +0 -18
- data/spec/lib/chgk_rating/collections/tournaments/tournament_team_results_spec.rb +0 -17
- data/spec/lib/chgk_rating/collections/tournaments/tournament_teams_spec.rb +0 -58
- data/spec/lib/chgk_rating/collections/tournaments/tournaments_spec.rb +0 -62
- data/spec/lib/chgk_rating/models/base_spec.rb +0 -34
- data/spec/lib/chgk_rating/models/player_rating_spec.rb +0 -22
- data/spec/lib/chgk_rating/models/player_spec.rb +0 -62
- data/spec/lib/chgk_rating/models/recap_spec.rb +0 -35
- data/spec/lib/chgk_rating/models/team_rating_spec.rb +0 -27
- data/spec/lib/chgk_rating/models/team_spec.rb +0 -97
- data/spec/lib/chgk_rating/models/tournament/tournament_spec.rb +0 -95
- data/spec/lib/chgk_rating/models/tournament/tournament_team_player_spec.rb +0 -21
- data/spec/lib/chgk_rating/models/tournament/tournament_team_result_spec.rb +0 -19
- data/spec/lib/chgk_rating/models/tournament/tournament_team_spec.rb +0 -36
- data/spec/lib/chgk_rating/utils/snakecase_spec.rb +0 -12
- data/spec/lib/chgk_rating/utils/transformations_spec.rb +0 -16
- data/spec/lib/chgk_rating_spec.rb +0 -5
- data/spec/lib/ext/date_spec.rb +0 -7
- data/spec/lib/ext/date_time_spec.rb +0 -11
- data/spec/lib/ext/uri_spec.rb +0 -7
- data/spec/spec_helper.rb +0 -15
- data/spec/support/shared_examples.rb +0 -63
- data/spec/support/test_client.rb +0 -6
- data/spec/support/vcr.rb +0 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 61be2615dc148c3adab710b6a3d2fb2e2209ffff2414972101b94d3ba35ebbfe
|
|
4
|
+
data.tar.gz: d26da02ff2a2886e0c253106c6f1096bb1572d2db8a4d5476acb149f70d18653
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea945aa9897881ecea27085dc0a224d33a2a0fb029a5624e7069a4831571bae5672effc2800b5d92e53e7d89f8b6856a5e925bf5a075843b1fcbe7e1c5b8532d
|
|
7
|
+
data.tar.gz: 52d3b312ebe06c301836562afa298de73f1a4682bd7d03057043f3883c08d23d2ece2725f2e0174291c69db0df9445c962260af255b64568c8c74c1b321ee418
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v2.2.0 (2022-07-07)
|
|
4
|
+
|
|
5
|
+
* **Drop support for Ruby 2.4 and 2.5 (EOL)**
|
|
6
|
+
* Switched to Faraday v2 (thanks, @L-Eugene)
|
|
7
|
+
* Fixed various minor issues
|
|
8
|
+
* Switched to GH Actions
|
|
9
|
+
* Use Rubocop
|
|
10
|
+
* Update test matrix
|
|
11
|
+
|
|
3
12
|
## v2.1.0 (2021-12-29)
|
|
4
13
|
|
|
5
14
|
* Updated API mappings (thanks, @L-Eugene)
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# ChgkRating
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/rb/chgk_rating)
|
|
4
|
-
|
|
5
|
-
[
|
|
5
|
+
[](https://codecov.io/gh/bodrovis/ChgkRating)
|
|
6
6
|
|
|
7
|
-
**This gem is in passive maintenance mode. I won't release any new features or introduce any complex enhancements as ChgkRating v1 is deprecated.**
|
|
7
|
+
**This gem is in passive maintenance mode. I won't release any new features or introduce any complex enhancements as ChgkRating v1 is deprecated. Please use [rating-chgk-v2 gem](https://github.com/bodrovis/rating-chgk-v2) which works with the new version of the API.**
|
|
8
8
|
|
|
9
9
|
Ruby interface for the [rating.chgk.info](http://rating.chgk.info/index.php/api) WebAPI. This is not just a wrapper, but rather a quite complex opinionated client that allows to easily work with various API resources.
|
|
10
10
|
|
|
@@ -64,4 +64,4 @@ Tests run against mock responses so you don't need to perform any special setup.
|
|
|
64
64
|
|
|
65
65
|
This plugin is licensed under the [MIT License](https://github.com/bodrovis/ChgkRating/blob/master/LICENSE).
|
|
66
66
|
|
|
67
|
-
Copyright (c) [Ilya
|
|
67
|
+
Copyright (c) [Ilya Krukowski](http://bodrovis.tech)
|
data/Rakefile
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rake'
|
|
2
4
|
|
|
3
5
|
begin
|
|
@@ -7,7 +9,7 @@ rescue LoadError
|
|
|
7
9
|
puts 'although not required, bundler is recommened for running the tests'
|
|
8
10
|
end
|
|
9
11
|
|
|
10
|
-
task :
|
|
12
|
+
task default: :spec
|
|
11
13
|
|
|
12
14
|
require 'rspec/core/rake_task'
|
|
13
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
data/chgk_rating.gemspec
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path('lib/chgk_rating/version', __dir__)
|
|
2
4
|
|
|
3
5
|
Gem::Specification.new do |spec|
|
|
4
6
|
spec.name = 'chgk_rating'
|
|
5
7
|
spec.version = ChgkRating::VERSION
|
|
6
|
-
spec.authors = ['Ilya
|
|
8
|
+
spec.authors = ['Ilya Krukowski']
|
|
7
9
|
spec.email = ['golosizpru@gmail.com']
|
|
8
10
|
spec.summary = 'Ruby interface to the competitive What? Where? When? rating API'
|
|
9
|
-
spec.description = 'Opinionated Ruby client for the competitive What? Where? When?
|
|
11
|
+
spec.description = 'Opinionated Ruby client for the competitive What? Where? When? ' \
|
|
12
|
+
'rating WebAPI (rating.chgk.info) that ' \
|
|
13
|
+
'allows to work with data as with Ruby objects'
|
|
10
14
|
spec.homepage = 'http://chgk-rating.bodrovis.tech/'
|
|
11
15
|
spec.license = 'MIT'
|
|
12
16
|
spec.platform = Gem::Platform::RUBY
|
|
13
|
-
spec.required_ruby_version = '>= 2.
|
|
17
|
+
spec.required_ruby_version = '>= 2.6.0'
|
|
14
18
|
|
|
15
|
-
spec.files
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
spec.test_files = Dir["spec/**/*.rb"]
|
|
19
|
+
spec.files = Dir['README.md', 'LICENSE', 'CONTRIBUTING.md',
|
|
20
|
+
'CHANGELOG.md', 'lib/**/*.rb', 'chgk_rating.gemspec', '.github/*.md',
|
|
21
|
+
'Gemfile', 'Rakefile']
|
|
19
22
|
spec.extra_rdoc_files = ['README.md']
|
|
20
23
|
spec.require_paths = ['lib']
|
|
21
24
|
|
|
22
|
-
spec.add_dependency 'faraday', '~>
|
|
23
|
-
spec.add_dependency '
|
|
25
|
+
spec.add_dependency 'faraday', '~> 2.0'
|
|
26
|
+
spec.add_dependency 'faraday-follow_redirects', '~> 0.3'
|
|
24
27
|
spec.add_dependency 'multi_json', '~> 1.15'
|
|
25
28
|
|
|
29
|
+
spec.add_development_dependency 'codecov', '~> 0.1'
|
|
26
30
|
spec.add_development_dependency 'rake', '~> 13.0'
|
|
27
31
|
spec.add_development_dependency 'rspec', '~> 3.6'
|
|
28
|
-
spec.add_development_dependency '
|
|
29
|
-
spec.add_development_dependency '
|
|
32
|
+
spec.add_development_dependency 'rubocop', '~> 1.31'
|
|
33
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.5'
|
|
34
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.11'
|
|
35
|
+
spec.add_development_dependency 'vcr', '~> 6.0'
|
|
36
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
30
37
|
end
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ChgkRating
|
|
2
4
|
module AttributeMappings
|
|
3
5
|
extend ChgkRating::Utils::Transformations
|
|
4
6
|
|
|
5
7
|
class << self
|
|
6
8
|
def find(name)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
{}
|
|
11
|
-
end
|
|
9
|
+
const_get name.snakecase_upcase
|
|
10
|
+
rescue NameError
|
|
11
|
+
{}
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def generate_mappings_for(data)
|
|
@@ -20,21 +20,20 @@ module ChgkRating
|
|
|
20
20
|
private
|
|
21
21
|
|
|
22
22
|
def name_from(raw_name)
|
|
23
|
-
{
|
|
23
|
+
{raw_name: raw_name.to_s}
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def parse_raw_scheme(raw_scheme)
|
|
27
27
|
if raw_scheme.respond_to? :inject
|
|
28
28
|
scheme_from raw_scheme
|
|
29
29
|
else
|
|
30
|
-
{
|
|
30
|
+
{raw_scheme => name_from(raw_scheme)}
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def scheme_from(raw_scheme)
|
|
35
|
-
raw_scheme.
|
|
35
|
+
raw_scheme.each_with_object({}) do |(key, value), memo|
|
|
36
36
|
memo[key] = scheme_value_from key, value
|
|
37
|
-
memo
|
|
38
37
|
end
|
|
39
38
|
end
|
|
40
39
|
|
|
@@ -51,7 +50,7 @@ module ChgkRating
|
|
|
51
50
|
return unless raw_schemes&.any?
|
|
52
51
|
|
|
53
52
|
if raw_schemes.is_a? Array
|
|
54
|
-
raw_schemes.
|
|
53
|
+
raw_schemes.reduce({}) do |memo, raw_scheme|
|
|
55
54
|
memo.merge parse_raw_scheme(raw_scheme)
|
|
56
55
|
end
|
|
57
56
|
else
|
|
@@ -61,107 +60,107 @@ module ChgkRating
|
|
|
61
60
|
end
|
|
62
61
|
|
|
63
62
|
generate_mappings_for({
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
63
|
+
PLAYER: [
|
|
64
|
+
{id: 'idplayer'},
|
|
65
|
+
:name,
|
|
66
|
+
:surname,
|
|
67
|
+
:patronymic,
|
|
68
|
+
:comment,
|
|
69
|
+
:db_chgk_info_tag
|
|
70
|
+
],
|
|
71
|
+
RATING: {
|
|
72
|
+
release_id: 'idrelease',
|
|
73
|
+
rating: [],
|
|
74
|
+
rating_position: [],
|
|
75
|
+
tech_rating: [],
|
|
76
|
+
date: ['date', :date]
|
|
77
|
+
},
|
|
78
|
+
PLAYER_RATING: {
|
|
79
|
+
player: ['idplayer', :player_id],
|
|
80
|
+
tournaments_in_year: [],
|
|
81
|
+
tournament_count_total: []
|
|
82
|
+
},
|
|
83
|
+
TEAM_RATING: {
|
|
84
|
+
team: ['idteam', :team_id],
|
|
85
|
+
formula: ['formula', :sym]
|
|
86
|
+
},
|
|
87
|
+
RECAP: {
|
|
88
|
+
season_id: 'idseason',
|
|
89
|
+
team: ['idteam', :team_id],
|
|
90
|
+
captain: ['captain', :player_id],
|
|
91
|
+
players: ['players', :players_ids]
|
|
92
|
+
},
|
|
93
|
+
PLAYER_TOURNAMENT: [
|
|
94
|
+
tournament: ['idtournament', :tournament_id],
|
|
95
|
+
team: ['idteam', :team_id],
|
|
96
|
+
in_base_team: ['in_base_team', :boolean_binboolean]
|
|
97
|
+
],
|
|
98
|
+
TOURNAMENT: [
|
|
99
|
+
{
|
|
100
|
+
id: 'idtournament',
|
|
101
|
+
date_start: ['date_start', :datetime],
|
|
102
|
+
date_end: ['date_end', :datetime],
|
|
103
|
+
tour_count: [],
|
|
104
|
+
tour_questions: [],
|
|
105
|
+
tour_ques_per_tour: [],
|
|
106
|
+
questions_total: [],
|
|
107
|
+
main_payment_value: ['main_payment_value', :float],
|
|
108
|
+
discounted_payment_value: ['discounted_payment_value', :float],
|
|
109
|
+
tournament_in_rating: ['tournament_in_rating', :boolean_binboolean],
|
|
110
|
+
date_requests_allowed_to: ['date_requests_allowed_to', :datetime],
|
|
111
|
+
site_url: ['site_url', :uri],
|
|
112
|
+
date_archived_at: ['date_archived_at', :datetime]
|
|
87
113
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
114
|
+
:name,
|
|
115
|
+
:town,
|
|
116
|
+
:long_name,
|
|
117
|
+
:type_name,
|
|
118
|
+
:main_payment_currency,
|
|
119
|
+
:discounted_payment_currency,
|
|
120
|
+
:discounted_payment_reason,
|
|
121
|
+
:archive,
|
|
122
|
+
:comment
|
|
123
|
+
],
|
|
124
|
+
TOURNAMENT_TEAM_PLAYER: {
|
|
125
|
+
id: 'idplayer',
|
|
126
|
+
is_captain: ['is_captain', :boolean_binboolean],
|
|
127
|
+
is_base: ['is_base', :boolean_binboolean],
|
|
128
|
+
is_foreign: ['is_foreign', :boolean_binboolean]
|
|
129
|
+
},
|
|
130
|
+
TOURNAMENT_TEAM: [
|
|
131
|
+
{
|
|
132
|
+
id: 'idteam',
|
|
133
|
+
position: ['position', :float],
|
|
134
|
+
questions_total: [],
|
|
135
|
+
result: ['mask', :splitboolean_arraystrboolean],
|
|
136
|
+
bonus_b: [],
|
|
137
|
+
tech_rating_rt: [],
|
|
138
|
+
tech_rating_rg: [],
|
|
139
|
+
tech_rating_rb: [],
|
|
140
|
+
rating_r: [],
|
|
141
|
+
predicted_position: [],
|
|
142
|
+
diff_bonus: [],
|
|
143
|
+
included_in_rating: ['included_in_rating', :boolean_binboolean]
|
|
93
144
|
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
date_start: ['date_start', :datetime],
|
|
103
|
-
date_end: ['date_end', :datetime],
|
|
104
|
-
tour_count: [],
|
|
105
|
-
tour_questions: [],
|
|
106
|
-
tour_ques_per_tour: [],
|
|
107
|
-
questions_total: [],
|
|
108
|
-
main_payment_value: ['main_payment_value', :float],
|
|
109
|
-
discounted_payment_value: ['discounted_payment_value', :float],
|
|
110
|
-
tournament_in_rating: ['tournament_in_rating', :boolean_binboolean],
|
|
111
|
-
date_requests_allowed_to: ['date_requests_allowed_to', :datetime],
|
|
112
|
-
site_url: ['site_url', :uri],
|
|
113
|
-
date_archived_at: ['date_archived_at', :datetime]
|
|
114
|
-
},
|
|
115
|
-
:name,
|
|
116
|
-
:town,
|
|
117
|
-
:long_name,
|
|
118
|
-
:type_name,
|
|
119
|
-
:main_payment_currency,
|
|
120
|
-
:discounted_payment_currency,
|
|
121
|
-
:discounted_payment_reason,
|
|
122
|
-
:archive,
|
|
123
|
-
:comment
|
|
124
|
-
],
|
|
125
|
-
TOURNAMENT_TEAM_PLAYER: {
|
|
126
|
-
id: 'idplayer',
|
|
127
|
-
is_captain: ['is_captain', :boolean_binboolean],
|
|
128
|
-
is_base: ['is_base', :boolean_binboolean],
|
|
129
|
-
is_foreign: ['is_foreign', :boolean_binboolean]
|
|
145
|
+
:current_name,
|
|
146
|
+
:base_name
|
|
147
|
+
],
|
|
148
|
+
TEAM: [
|
|
149
|
+
{
|
|
150
|
+
id: 'idteam',
|
|
151
|
+
tournaments_this_season: [],
|
|
152
|
+
tournaments_total: []
|
|
130
153
|
},
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
rating_r: [],
|
|
142
|
-
predicted_position: [],
|
|
143
|
-
diff_bonus: [],
|
|
144
|
-
included_in_rating: ['included_in_rating', :boolean_binboolean]
|
|
145
|
-
},
|
|
146
|
-
:current_name,
|
|
147
|
-
:base_name
|
|
148
|
-
],
|
|
149
|
-
TEAM: [
|
|
150
|
-
{
|
|
151
|
-
id: 'idteam',
|
|
152
|
-
tournaments_this_season: [],
|
|
153
|
-
tournaments_total: []
|
|
154
|
-
},
|
|
155
|
-
:name,
|
|
156
|
-
:town,
|
|
157
|
-
:region_name,
|
|
158
|
-
:country_name,
|
|
159
|
-
:comment
|
|
160
|
-
],
|
|
161
|
-
TOURNAMENT_TEAM_RESULT: {
|
|
162
|
-
tour: [],
|
|
163
|
-
result: ['mask', :arrayboolean_arraystrboolean]
|
|
164
|
-
}
|
|
154
|
+
:name,
|
|
155
|
+
:town,
|
|
156
|
+
:region_name,
|
|
157
|
+
:country_name,
|
|
158
|
+
:comment
|
|
159
|
+
],
|
|
160
|
+
TOURNAMENT_TEAM_RESULT: {
|
|
161
|
+
tour: [],
|
|
162
|
+
result: ['mask', :arrayboolean_arraystrboolean]
|
|
163
|
+
}
|
|
165
164
|
})
|
|
166
165
|
end
|
|
167
166
|
end
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ChgkRating
|
|
2
4
|
class ChgkObject
|
|
3
5
|
def build_model(object, klass = ChgkRating::Models::Team, params = {lazy: true})
|
|
4
6
|
return unless object
|
|
7
|
+
|
|
5
8
|
object.instance_of?(klass) ? object : klass.new(object, params)
|
|
6
9
|
end
|
|
7
10
|
|
|
8
11
|
def extract_id_from(obj, klass = ChgkRating::Models::Team)
|
|
9
12
|
return unless obj
|
|
10
13
|
return obj unless obj.is_a? klass
|
|
14
|
+
|
|
11
15
|
obj&.id
|
|
12
16
|
end
|
|
13
17
|
end
|
|
14
|
-
end
|
|
18
|
+
end
|
data/lib/chgk_rating/client.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ChgkRating
|
|
2
4
|
class Client
|
|
3
5
|
# Returns a single Team
|
|
@@ -138,7 +140,7 @@ module ChgkRating
|
|
|
138
140
|
# @option params [String or Integer] :page The requested page. Default is 1
|
|
139
141
|
def tournaments(team_or_id: nil, season_id: nil, params: {})
|
|
140
142
|
ChgkRating::Collections::Tournaments.new params.merge(
|
|
141
|
-
|
|
143
|
+
team: team_or_id, season_id: season_id
|
|
142
144
|
)
|
|
143
145
|
end
|
|
144
146
|
|
|
@@ -201,4 +203,4 @@ module ChgkRating
|
|
|
201
203
|
team_at_tournament(tournament_or_id, team_or_id).players
|
|
202
204
|
end
|
|
203
205
|
end
|
|
204
|
-
end
|
|
206
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ChgkRating
|
|
2
4
|
module Collections
|
|
3
5
|
class Base < ChgkObject
|
|
@@ -8,7 +10,7 @@ module ChgkRating
|
|
|
8
10
|
|
|
9
11
|
def initialize(params = {})
|
|
10
12
|
results = params[:collection] ||
|
|
11
|
-
|
|
13
|
+
prepare(get(api_path, build_request_params_from(params)))
|
|
12
14
|
|
|
13
15
|
@items = process results, params
|
|
14
16
|
end
|
|
@@ -22,27 +24,30 @@ module ChgkRating
|
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
def to_a
|
|
25
|
-
raise ChgkRating::Error::NotArrayType unless
|
|
26
|
-
|
|
27
|
+
raise ChgkRating::Error::NotArrayType unless respond_to?(:to_a)
|
|
28
|
+
|
|
29
|
+
items.to_a.map(&:to_h)
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
def to_h
|
|
30
|
-
raise ChgkRating::Error::NotHashType unless
|
|
31
|
-
|
|
33
|
+
raise ChgkRating::Error::NotHashType unless respond_to?(:to_h)
|
|
34
|
+
|
|
35
|
+
items.to_h { |k, v| revert_to_hash(k, v) }
|
|
32
36
|
end
|
|
33
37
|
|
|
34
38
|
def respond_to?(method, include_all = false)
|
|
35
39
|
method = method.to_sym
|
|
36
|
-
if %i
|
|
37
|
-
|
|
40
|
+
if %i[to_a to_h].include?(method.to_sym)
|
|
41
|
+
convertable? method
|
|
38
42
|
else
|
|
39
43
|
super
|
|
40
44
|
end
|
|
41
45
|
end
|
|
42
46
|
|
|
43
47
|
def convertable?(method)
|
|
44
|
-
return true if (method == :to_a &&
|
|
45
|
-
|
|
48
|
+
return true if (method == :to_a && items.is_a?(Array)) ||
|
|
49
|
+
(method == :to_h && items.is_a?(Hash))
|
|
50
|
+
|
|
46
51
|
false
|
|
47
52
|
end
|
|
48
53
|
|
|
@@ -54,26 +59,26 @@ module ChgkRating
|
|
|
54
59
|
|
|
55
60
|
def build_request_params_from(params)
|
|
56
61
|
request_params = params[:request].to_h
|
|
57
|
-
request_params[:page] = params.delete(:page).to_i if params.
|
|
62
|
+
request_params[:page] = params.delete(:page).to_i if params.key?(:page)
|
|
58
63
|
request_params
|
|
59
64
|
end
|
|
60
65
|
|
|
61
66
|
def prepare(raw_results)
|
|
62
67
|
if raw_results.respond_to?(:has_key?)
|
|
63
|
-
return raw_results['tournaments'] if raw_results.
|
|
64
|
-
return raw_results['items'] if raw_results.
|
|
68
|
+
return raw_results['tournaments'] if raw_results.key?('tournaments')
|
|
69
|
+
return raw_results['items'] if raw_results.key?('items')
|
|
65
70
|
end
|
|
66
71
|
|
|
67
72
|
raw_results
|
|
68
73
|
end
|
|
69
74
|
|
|
70
|
-
def process(results, *_args)
|
|
75
|
+
def process(results, *_args, &block)
|
|
71
76
|
if results.is_a? Hash
|
|
72
77
|
results.each { |season, result| results[season] = yield result }
|
|
73
78
|
else
|
|
74
|
-
results.map
|
|
79
|
+
results.map(&block)
|
|
75
80
|
end
|
|
76
81
|
end
|
|
77
82
|
end
|
|
78
83
|
end
|
|
79
|
-
end
|
|
84
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ChgkRating
|
|
2
4
|
module Collections
|
|
3
5
|
class Recaps < Base
|
|
@@ -12,7 +14,7 @@ module ChgkRating
|
|
|
12
14
|
private
|
|
13
15
|
|
|
14
16
|
def process(results, _params)
|
|
15
|
-
results.each do |season,value|
|
|
17
|
+
results.each do |season, value|
|
|
16
18
|
results[season] = ChgkRating::Models::Recap.new value, team: @team
|
|
17
19
|
end
|
|
18
20
|
end
|
|
@@ -22,4 +24,4 @@ module ChgkRating
|
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
26
|
end
|
|
25
|
-
end
|
|
27
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ChgkRating
|
|
2
4
|
module Collections
|
|
3
5
|
class PlayerTournaments < Base
|
|
@@ -12,12 +14,12 @@ module ChgkRating
|
|
|
12
14
|
|
|
13
15
|
def revert_to_hash(key, values)
|
|
14
16
|
[
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
key,
|
|
18
|
+
{
|
|
19
|
+
'idplayer' => @player.id.to_s,
|
|
20
|
+
'idseason' => key,
|
|
21
|
+
'tournaments' => values.map(&:to_h)
|
|
22
|
+
}
|
|
21
23
|
]
|
|
22
24
|
end
|
|
23
25
|
|
|
@@ -33,12 +35,14 @@ module ChgkRating
|
|
|
33
35
|
end
|
|
34
36
|
end
|
|
35
37
|
|
|
36
|
-
# @return [String] Either `tournaments`, `teams/ID/tournaments`, `players/ID/tournaments`,
|
|
38
|
+
# @return [String] Either `tournaments`, `teams/ID/tournaments`, `players/ID/tournaments`,
|
|
39
|
+
# `teams/ID/tournaments/SEASON_ID`, `players/ID/tournaments/SEASON_ID`
|
|
37
40
|
def api_path
|
|
38
41
|
path = "players/#{@player.id}/tournaments"
|
|
39
42
|
return path unless @season_id
|
|
43
|
+
|
|
40
44
|
path + "/#{@season_id}"
|
|
41
45
|
end
|
|
42
46
|
end
|
|
43
47
|
end
|
|
44
|
-
end
|
|
48
|
+
end
|