rating-chgk-v2 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/CODE_OF_CONDUCT.md +46 -0
- data/.github/CONTRIBUTING.md +14 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +11 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +5 -0
- data/README.md +60 -0
- data/Rakefile +21 -0
- data/lib/rating_chgk_v2/client.rb +16 -0
- data/lib/rating_chgk_v2/collections/base_collection.rb +48 -0
- data/lib/rating_chgk_v2/collections/countries_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/player_seasons_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/player_tournaments_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/players_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/regions_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/releases_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/seasons_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/team_tournaments_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/teams_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/tournament_appeals_collection.rb +9 -0
- data/lib/rating_chgk_v2/collections/tournament_flags_collection.rb +9 -0
- data/lib/rating_chgk_v2/collections/tournament_requests_collection.rb +9 -0
- data/lib/rating_chgk_v2/collections/tournament_results_collection.rb +9 -0
- data/lib/rating_chgk_v2/collections/tournament_types_collection.rb +9 -0
- data/lib/rating_chgk_v2/collections/tournaments_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/towns_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/venue_types_collection.rb +11 -0
- data/lib/rating_chgk_v2/collections/venues_collection.rb +11 -0
- data/lib/rating_chgk_v2/concerns/paginated.rb +31 -0
- data/lib/rating_chgk_v2/connection.rb +33 -0
- data/lib/rating_chgk_v2/data/authentication_token.yml +1 -0
- data/lib/rating_chgk_v2/data/country.yml +2 -0
- data/lib/rating_chgk_v2/data/player.yml +4 -0
- data/lib/rating_chgk_v2/data/player_season.yml +6 -0
- data/lib/rating_chgk_v2/data/player_tournament.yml +3 -0
- data/lib/rating_chgk_v2/data/region.yml +3 -0
- data/lib/rating_chgk_v2/data/release.yml +4 -0
- data/lib/rating_chgk_v2/data/season.yml +3 -0
- data/lib/rating_chgk_v2/data/team.yml +3 -0
- data/lib/rating_chgk_v2/data/team_tournament.yml +2 -0
- data/lib/rating_chgk_v2/data/tournament.yml +20 -0
- data/lib/rating_chgk_v2/data/tournament_flag.yml +3 -0
- data/lib/rating_chgk_v2/data/tournament_result.yml +10 -0
- data/lib/rating_chgk_v2/data/tournament_synch_appeal.yml +10 -0
- data/lib/rating_chgk_v2/data/tournament_synch_controversial.yml +8 -0
- data/lib/rating_chgk_v2/data/tournament_synch_request.yml +8 -0
- data/lib/rating_chgk_v2/data/tournament_type.yml +2 -0
- data/lib/rating_chgk_v2/data/town.yml +4 -0
- data/lib/rating_chgk_v2/data/venue.yml +6 -0
- data/lib/rating_chgk_v2/data/venue_type.yml +2 -0
- data/lib/rating_chgk_v2/endpoints/authentication_token_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/base_endpoint.rb +58 -0
- data/lib/rating_chgk_v2/endpoints/countries_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/players_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/regions_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/releases_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/seasons_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/teams_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/tournament_flags_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/tournament_synch_appeals_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/tournament_synch_controversials_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/tournament_synch_requests_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/tournament_types_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/tournaments_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/towns_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/venue_types_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/endpoints/venues_endpoint.rb +13 -0
- data/lib/rating_chgk_v2/error.rb +52 -0
- data/lib/rating_chgk_v2/json_handler.rb +19 -0
- data/lib/rating_chgk_v2/models/authentication_token_model.rb +8 -0
- data/lib/rating_chgk_v2/models/base_model.rb +38 -0
- data/lib/rating_chgk_v2/models/country_model.rb +16 -0
- data/lib/rating_chgk_v2/models/player_model.rb +17 -0
- data/lib/rating_chgk_v2/models/player_season_model.rb +8 -0
- data/lib/rating_chgk_v2/models/player_tournament_model.rb +8 -0
- data/lib/rating_chgk_v2/models/region_model.rb +8 -0
- data/lib/rating_chgk_v2/models/release_model.rb +8 -0
- data/lib/rating_chgk_v2/models/season_model.rb +16 -0
- data/lib/rating_chgk_v2/models/team_model.rb +17 -0
- data/lib/rating_chgk_v2/models/team_tournament_model.rb +8 -0
- data/lib/rating_chgk_v2/models/tournament_flag_model.rb +8 -0
- data/lib/rating_chgk_v2/models/tournament_model.rb +22 -0
- data/lib/rating_chgk_v2/models/tournament_result_model.rb +8 -0
- data/lib/rating_chgk_v2/models/tournament_synch_appeal_model.rb +8 -0
- data/lib/rating_chgk_v2/models/tournament_synch_controversial_model.rb +8 -0
- data/lib/rating_chgk_v2/models/tournament_synch_request_model.rb +8 -0
- data/lib/rating_chgk_v2/models/tournament_type_model.rb +8 -0
- data/lib/rating_chgk_v2/models/town_model.rb +8 -0
- data/lib/rating_chgk_v2/models/venue_model.rb +16 -0
- data/lib/rating_chgk_v2/models/venue_type_model.rb +8 -0
- data/lib/rating_chgk_v2/request.rb +58 -0
- data/lib/rating_chgk_v2/rest/authentication_token.rb +11 -0
- data/lib/rating_chgk_v2/rest/countries.rb +27 -0
- data/lib/rating_chgk_v2/rest/players.rb +23 -0
- data/lib/rating_chgk_v2/rest/regions.rb +15 -0
- data/lib/rating_chgk_v2/rest/releases.rb +15 -0
- data/lib/rating_chgk_v2/rest/seasons.rb +27 -0
- data/lib/rating_chgk_v2/rest/teams.rb +23 -0
- data/lib/rating_chgk_v2/rest/tournament_flags.rb +15 -0
- data/lib/rating_chgk_v2/rest/tournament_synch_appeals.rb +11 -0
- data/lib/rating_chgk_v2/rest/tournament_synch_controversials.rb +11 -0
- data/lib/rating_chgk_v2/rest/tournament_synch_requests.rb +11 -0
- data/lib/rating_chgk_v2/rest/tournament_types.rb +15 -0
- data/lib/rating_chgk_v2/rest/tournaments.rb +27 -0
- data/lib/rating_chgk_v2/rest/towns.rb +15 -0
- data/lib/rating_chgk_v2/rest/venue_types.rb +19 -0
- data/lib/rating_chgk_v2/rest/venues.rb +27 -0
- data/lib/rating_chgk_v2/rest.rb +45 -0
- data/lib/rating_chgk_v2/utils/string_utils.rb +28 -0
- data/lib/rating_chgk_v2/version.rb +5 -0
- data/lib/rating_chgk_v2.rb +22 -0
- data/rating-chgk-v2.gemspec +47 -0
- data/spec/lib/rating_chgk_v2/collections/base_collection_spec.rb +53 -0
- data/spec/lib/rating_chgk_v2/collections/countries_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/player_seasons_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/player_tournaments_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/players_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/regions_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/releases_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/seasons_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/teams_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/tournaments_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/towns_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/venue_types_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/collections/venues_collection_spec.rb +5 -0
- data/spec/lib/rating_chgk_v2/connection_spec.rb +22 -0
- data/spec/lib/rating_chgk_v2/endpoints/base_endpoint_spec.rb +15 -0
- data/spec/lib/rating_chgk_v2/error_spec.rb +11 -0
- data/spec/lib/rating_chgk_v2/models/country_model_spec.rb +30 -0
- data/spec/lib/rating_chgk_v2/models/player_model_spec.rb +59 -0
- data/spec/lib/rating_chgk_v2/models/season_model_spec.rb +36 -0
- data/spec/lib/rating_chgk_v2/models/team_model_spec.rb +35 -0
- data/spec/lib/rating_chgk_v2/models/tournament_model_spec.rb +38 -0
- data/spec/lib/rating_chgk_v2/models/venue_model_spec.rb +30 -0
- data/spec/lib/rating_chgk_v2/rest/authentication_token_spec.rb +19 -0
- data/spec/lib/rating_chgk_v2/rest/countries_spec.rb +94 -0
- data/spec/lib/rating_chgk_v2/rest/players_spec.rb +126 -0
- data/spec/lib/rating_chgk_v2/rest/regions_spec.rb +37 -0
- data/spec/lib/rating_chgk_v2/rest/releases_spec.rb +34 -0
- data/spec/lib/rating_chgk_v2/rest/seasons_spec.rb +71 -0
- data/spec/lib/rating_chgk_v2/rest/teams_spec.rb +66 -0
- data/spec/lib/rating_chgk_v2/rest/tournament_flags_spec.rb +27 -0
- data/spec/lib/rating_chgk_v2/rest/tournament_synch_appeals_spec.rb +22 -0
- data/spec/lib/rating_chgk_v2/rest/tournament_synch_controversials_spec.rb +20 -0
- data/spec/lib/rating_chgk_v2/rest/tournament_synch_requests_spec.rb +20 -0
- data/spec/lib/rating_chgk_v2/rest/tournament_types_spec.rb +23 -0
- data/spec/lib/rating_chgk_v2/rest/tournaments_spec.rb +89 -0
- data/spec/lib/rating_chgk_v2/rest/towns_spec.rb +35 -0
- data/spec/lib/rating_chgk_v2/rest/venue_types_spec.rb +46 -0
- data/spec/lib/rating_chgk_v2/rest/venues_spec.rb +71 -0
- data/spec/lib/rating_chgk_v2_spec.rb +9 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/support/shared/paginated.rb +41 -0
- data/spec/support/test_client.rb +7 -0
- data/spec/support/vcr.rb +15 -0
- metadata +455 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Request
|
5
|
+
include RatingChgkV2::Connection
|
6
|
+
include RatingChgkV2::JsonHandler
|
7
|
+
|
8
|
+
def get(path, client, params = {})
|
9
|
+
respond_with(
|
10
|
+
connection(client).get(prepare(path), params),
|
11
|
+
client
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def post(path, client, params = {})
|
16
|
+
respond_with(
|
17
|
+
connection(client).post(prepare(path), custom_dump(params)),
|
18
|
+
client
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def put(path, client, params = {})
|
23
|
+
respond_with(
|
24
|
+
connection(client).put(prepare(path), custom_dump(params)),
|
25
|
+
client
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete(path, client, _params = {})
|
30
|
+
respond_with(
|
31
|
+
# Rubocop tries to replace `delete` with `gsub` but that's a different method here!
|
32
|
+
connection(client).delete(prepare(path)),
|
33
|
+
client
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# Get rid of double slashes in the `path`, leading and trailing slash
|
40
|
+
def prepare(path)
|
41
|
+
path.delete_prefix('/').gsub(%r{//}, '/').gsub(%r{/+\z}, '')
|
42
|
+
end
|
43
|
+
|
44
|
+
def respond_with(response, _client)
|
45
|
+
body = response.body.empty? ? response.body : custom_load(response.body)
|
46
|
+
status = response.status
|
47
|
+
respond_with_error status, body if status.between?(400, 599)
|
48
|
+
|
49
|
+
body
|
50
|
+
end
|
51
|
+
|
52
|
+
def respond_with_error(code, body)
|
53
|
+
raise(RatingChgkV2::Error, body) unless RatingChgkV2::Error::ERRORS.key? code
|
54
|
+
|
55
|
+
raise RatingChgkV2::Error::ERRORS[code].from_response(body)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Rest
|
5
|
+
module Countries
|
6
|
+
def countries(params = {})
|
7
|
+
collection_load name: 'Countries', ep_params: [[], params]
|
8
|
+
end
|
9
|
+
|
10
|
+
def country(id)
|
11
|
+
model_load name: 'Country', ep_name: 'Countries', ep_params: id
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_country(params)
|
15
|
+
model_load name: 'Country', ep_name: 'Countries', ep_params: [[], params], method: :do_post
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_country(id, params)
|
19
|
+
model_load name: 'Country', ep_name: 'Countries', ep_params: [id, params], method: :do_put
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete_country(id)
|
23
|
+
endpoint('Countries', id).do_delete
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Rest
|
5
|
+
module Players
|
6
|
+
def players(params = {})
|
7
|
+
collection_load name: 'Players', ep_params: [[], params]
|
8
|
+
end
|
9
|
+
|
10
|
+
def player(id)
|
11
|
+
model_load name: 'Player', ep_name: 'Players', ep_params: id
|
12
|
+
end
|
13
|
+
|
14
|
+
def player_seasons(id, params = {})
|
15
|
+
collection_load name: 'PlayerSeasons', ep_name: 'Players', ep_params: [[id, :seasons], params]
|
16
|
+
end
|
17
|
+
|
18
|
+
def player_tournaments(id, params = {})
|
19
|
+
collection_load name: 'PlayerTournaments', ep_name: 'Players', ep_params: [[id, :tournaments], params]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Rest
|
5
|
+
module Regions
|
6
|
+
def regions(params = {})
|
7
|
+
collection_load name: 'Regions', ep_params: [[], params]
|
8
|
+
end
|
9
|
+
|
10
|
+
def region(id)
|
11
|
+
model_load name: 'Region', ep_name: 'Regions', ep_params: id
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Rest
|
5
|
+
module Releases
|
6
|
+
def releases(params = {})
|
7
|
+
collection_load name: 'Releases', ep_params: [[], params]
|
8
|
+
end
|
9
|
+
|
10
|
+
def release(id)
|
11
|
+
model_load name: 'Release', ep_name: 'Releases', ep_params: id
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Rest
|
5
|
+
module Seasons
|
6
|
+
def seasons
|
7
|
+
collection_load name: 'Seasons', ep_params: [[]]
|
8
|
+
end
|
9
|
+
|
10
|
+
def season(id)
|
11
|
+
model_load name: 'Season', ep_name: 'Seasons', ep_params: id
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_season(params)
|
15
|
+
model_load name: 'Season', ep_name: 'Seasons', ep_params: [[], params], method: :do_post
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_season(id, params)
|
19
|
+
model_load name: 'Season', ep_name: 'Seasons', ep_params: [id, params], method: :do_put
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete_season(id)
|
23
|
+
endpoint('Seasons', id).do_delete
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Rest
|
5
|
+
module Teams
|
6
|
+
def teams(params = {})
|
7
|
+
collection_load name: 'Teams', ep_params: [[], params]
|
8
|
+
end
|
9
|
+
|
10
|
+
def team(id)
|
11
|
+
model_load name: 'Team', ep_name: 'Teams', ep_params: id
|
12
|
+
end
|
13
|
+
|
14
|
+
def team_seasons(id, params = {})
|
15
|
+
collection_load name: 'PlayerSeasons', ep_name: 'Teams', ep_params: [[id, :seasons], params]
|
16
|
+
end
|
17
|
+
|
18
|
+
def team_tournaments(id, params = {})
|
19
|
+
collection_load name: 'TeamTournaments', ep_name: 'Teams', ep_params: [[id, :tournaments], params]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Rest
|
5
|
+
module TournamentFlags
|
6
|
+
def tournament_flags
|
7
|
+
collection_load name: 'TournamentFlags', ep_params: [[]]
|
8
|
+
end
|
9
|
+
|
10
|
+
def tournament_flag(id)
|
11
|
+
model_load name: 'TournamentFlag', ep_name: 'TournamentFlags', ep_params: id
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Rest
|
5
|
+
module TournamentSynchControversials
|
6
|
+
def tournament_synch_controversial(id)
|
7
|
+
model_load name: 'TournamentSynchControversial', ep_name: 'TournamentSynchControversials', ep_params: id
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Rest
|
5
|
+
module TournamentTypes
|
6
|
+
def tournament_types
|
7
|
+
collection_load name: 'TournamentTypes', ep_params: [[]]
|
8
|
+
end
|
9
|
+
|
10
|
+
def tournament_type(id)
|
11
|
+
model_load name: 'TournamentType', ep_name: 'TournamentTypes', ep_params: id
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Rest
|
5
|
+
module Tournaments
|
6
|
+
def tournaments(params = {})
|
7
|
+
collection_load name: 'Tournaments', ep_params: [[], params]
|
8
|
+
end
|
9
|
+
|
10
|
+
def tournament(id)
|
11
|
+
model_load name: 'Tournament', ep_name: 'Tournaments', ep_params: id
|
12
|
+
end
|
13
|
+
|
14
|
+
def tournament_appeals(id)
|
15
|
+
collection_load name: 'TournamentAppeals', ep_name: 'Tournaments', ep_params: [[id, :appeals]]
|
16
|
+
end
|
17
|
+
|
18
|
+
def tournament_requests(id)
|
19
|
+
collection_load name: 'TournamentRequests', ep_name: 'Tournaments', ep_params: [[id, :requests]]
|
20
|
+
end
|
21
|
+
|
22
|
+
def tournament_results(id, params = {})
|
23
|
+
collection_load name: 'TournamentResults', ep_name: 'Tournaments', ep_params: [[id, :results], params]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Rest
|
5
|
+
module Towns
|
6
|
+
def towns(params = {})
|
7
|
+
collection_load name: 'Towns', ep_params: [[], params]
|
8
|
+
end
|
9
|
+
|
10
|
+
def town(id)
|
11
|
+
model_load name: 'Town', ep_name: 'Towns', ep_params: id
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Rest
|
5
|
+
module VenueTypes
|
6
|
+
def venue_types(params = {})
|
7
|
+
collection_load name: 'VenueTypes', ep_params: [[], params]
|
8
|
+
end
|
9
|
+
|
10
|
+
def venue_type(id)
|
11
|
+
model_load name: 'VenueType', ep_name: 'VenueTypes', ep_params: id
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_venue_type(params)
|
15
|
+
model_load name: 'VenueType', ep_name: 'VenueTypes', ep_params: [[], params], method: :do_post
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Rest
|
5
|
+
module Venues
|
6
|
+
def venues(params = {})
|
7
|
+
collection_load name: 'Venues', ep_params: [[], params]
|
8
|
+
end
|
9
|
+
|
10
|
+
def venue(id)
|
11
|
+
model_load name: 'Venue', ep_name: 'Venues', ep_params: id
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_venue(params)
|
15
|
+
model_load name: 'Venue', ep_name: 'Venues', ep_params: [[], params], method: :do_post
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_venue(id, params)
|
19
|
+
model_load name: 'Venue', ep_name: 'Venues', ep_params: [id, params], method: :do_put
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete_venue(id)
|
23
|
+
endpoint('Venues', id).do_delete
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Rest
|
5
|
+
include RatingChgkV2::Rest::AuthenticationToken
|
6
|
+
include RatingChgkV2::Rest::Countries
|
7
|
+
include RatingChgkV2::Rest::Players
|
8
|
+
include RatingChgkV2::Rest::Regions
|
9
|
+
include RatingChgkV2::Rest::Releases
|
10
|
+
include RatingChgkV2::Rest::Seasons
|
11
|
+
include RatingChgkV2::Rest::Teams
|
12
|
+
include RatingChgkV2::Rest::TournamentFlags
|
13
|
+
include RatingChgkV2::Rest::TournamentSynchAppeals
|
14
|
+
include RatingChgkV2::Rest::TournamentSynchControversials
|
15
|
+
include RatingChgkV2::Rest::TournamentSynchRequests
|
16
|
+
include RatingChgkV2::Rest::TournamentTypes
|
17
|
+
include RatingChgkV2::Rest::Tournaments
|
18
|
+
include RatingChgkV2::Rest::Towns
|
19
|
+
include RatingChgkV2::Rest::VenueTypes
|
20
|
+
include RatingChgkV2::Rest::Venues
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def endpoint(name, query, params = {})
|
25
|
+
klass = RatingChgkV2.const_get "Endpoints::#{name}Endpoint"
|
26
|
+
klass.new self, query, params
|
27
|
+
end
|
28
|
+
|
29
|
+
def collection_load(name:, ep_params:, ep_name: nil, method: :do_get)
|
30
|
+
collection(name).load method, endpoint(ep_name || name, *ep_params)
|
31
|
+
end
|
32
|
+
|
33
|
+
def model_load(name:, ep_params:, ep_name: nil, method: :do_get)
|
34
|
+
model(name).load method, endpoint(ep_name || name, *ep_params)
|
35
|
+
end
|
36
|
+
|
37
|
+
def collection(name)
|
38
|
+
RatingChgkV2.const_get("Collections::#{name}Collection")
|
39
|
+
end
|
40
|
+
|
41
|
+
def model(name)
|
42
|
+
RatingChgkV2.const_get("Models::#{name}Model")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Utils
|
5
|
+
module StringUtils
|
6
|
+
refine String do
|
7
|
+
# Underscore a string such that camelcase, dashes and spaces are
|
8
|
+
# replaced by underscores.
|
9
|
+
# Initial code taken from Facets gem by Rubyworks
|
10
|
+
# https://github.com/rubyworks/facets/blob/master/lib/core/facets/string/snakecase.rb
|
11
|
+
def snakecase
|
12
|
+
base_class_name.
|
13
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
14
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
15
|
+
tr('-', '_').
|
16
|
+
gsub(/\s/, '_').
|
17
|
+
gsub(/__+/, '_').
|
18
|
+
downcase
|
19
|
+
end
|
20
|
+
|
21
|
+
# Turn `Module::Nested::ClassName` to just `ClassName`
|
22
|
+
def base_class_name
|
23
|
+
split('::').last
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zeitwerk'
|
4
|
+
require 'yaml'
|
5
|
+
require 'faraday'
|
6
|
+
require 'addressable/template'
|
7
|
+
require 'forwardable'
|
8
|
+
|
9
|
+
loader = Zeitwerk::Loader.for_gem
|
10
|
+
loader.setup
|
11
|
+
|
12
|
+
module RatingChgkV2
|
13
|
+
class << self
|
14
|
+
def client(token: '', params: {})
|
15
|
+
@client ||= RatingChgkV2::Client.new token: token, params: params
|
16
|
+
end
|
17
|
+
|
18
|
+
def reset_client!
|
19
|
+
@client = nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('lib/rating_chgk_v2/version', __dir__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'rating-chgk-v2'
|
7
|
+
spec.version = RatingChgkV2::VERSION
|
8
|
+
spec.authors = ['Ilya Bodrov-Krukowski']
|
9
|
+
spec.email = ['golosizpru@gmail.com']
|
10
|
+
spec.summary = 'Ruby interface for the new CHGK rating API'
|
11
|
+
spec.description = 'Ruby client for the new CHGK rating API (api.rating.chgk.net).'
|
12
|
+
spec.homepage = 'https://github.com/bodrovis/rating-chgk-v2'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.platform = Gem::Platform::RUBY
|
15
|
+
spec.required_ruby_version = '>= 2.7.0'
|
16
|
+
|
17
|
+
spec.files = Dir['README.md', 'LICENSE',
|
18
|
+
'CHANGELOG.md', 'lib/**/*.rb', 'lib/rating_chgk_v2/data/*.yml',
|
19
|
+
'rating-chgk-v2.gemspec', '.github/*.md',
|
20
|
+
'Gemfile', 'Rakefile']
|
21
|
+
spec.test_files = Dir['spec/**/*.rb']
|
22
|
+
spec.extra_rdoc_files = ['README.md']
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency 'addressable', '~> 2.5'
|
26
|
+
spec.add_dependency 'faraday', '~> 2'
|
27
|
+
spec.add_dependency 'json', '~> 2'
|
28
|
+
spec.add_dependency 'zeitwerk', '~> 2.4'
|
29
|
+
|
30
|
+
spec.add_development_dependency 'codecov', '~> 0.1'
|
31
|
+
spec.add_development_dependency 'dotenv', '~> 2.5'
|
32
|
+
spec.add_development_dependency 'oj', '~> 3.10'
|
33
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.6'
|
35
|
+
spec.add_development_dependency 'rubocop', '~> 1.6'
|
36
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.5'
|
37
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.0'
|
38
|
+
spec.add_development_dependency 'simplecov', '~> 0.16'
|
39
|
+
spec.add_development_dependency 'vcr', '~> 6.0'
|
40
|
+
spec.add_development_dependency 'webmock', '~> 3.14'
|
41
|
+
spec.metadata = {
|
42
|
+
'rubygems_mfa_required' => 'true',
|
43
|
+
'wiki_uri' => 'https://github.com/bodrovis/rating-chgk-v2/wiki',
|
44
|
+
'changelog_uri' => 'https://github.com/bodrovis/rating-chgk-v2/blob/master/CHANGELOG.md',
|
45
|
+
'bug_tracker_uri' => 'https://github.com/bodrovis/rating-chgk-v2/issues'
|
46
|
+
}
|
47
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RatingChgkV2::Collections::BaseCollection do
|
4
|
+
let(:players) do
|
5
|
+
described_class.new [{
|
6
|
+
id: 1,
|
7
|
+
name: 'Ivan',
|
8
|
+
surname: 'Petrov'
|
9
|
+
}, {
|
10
|
+
id: 2,
|
11
|
+
name: 'Petr',
|
12
|
+
surname: 'Ivanov'
|
13
|
+
}]
|
14
|
+
end
|
15
|
+
|
16
|
+
specify '#first' do
|
17
|
+
stub_const "#{described_class}::MODEL", 'Player'
|
18
|
+
|
19
|
+
player = players.first
|
20
|
+
expect(player).to be_an_instance_of(RatingChgkV2::Models::PlayerModel)
|
21
|
+
expect(player.id).to eq(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
specify '#last' do
|
25
|
+
stub_const "#{described_class}::MODEL", 'Player'
|
26
|
+
|
27
|
+
player = players.last
|
28
|
+
expect(player).to be_an_instance_of(RatingChgkV2::Models::PlayerModel)
|
29
|
+
expect(player.id).to eq(2)
|
30
|
+
end
|
31
|
+
|
32
|
+
specify '#[]' do
|
33
|
+
stub_const "#{described_class}::MODEL", 'Player'
|
34
|
+
|
35
|
+
player = players[1]
|
36
|
+
expect(player.id).to eq(2)
|
37
|
+
end
|
38
|
+
|
39
|
+
specify '#each' do
|
40
|
+
stub_const "#{described_class}::MODEL", 'Player'
|
41
|
+
|
42
|
+
klass = RatingChgkV2::Models::PlayerModel
|
43
|
+
|
44
|
+
expect { |b| players.each(&b) }.to yield_successive_args(klass, klass)
|
45
|
+
end
|
46
|
+
|
47
|
+
specify '#map' do
|
48
|
+
stub_const "#{described_class}::MODEL", 'Player'
|
49
|
+
|
50
|
+
mapped = players.map(&:id)
|
51
|
+
expect(mapped).to include(1, 2)
|
52
|
+
end
|
53
|
+
end
|