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 Endpoints
|
5
|
+
class BaseEndpoint
|
6
|
+
include RatingChgkV2::Request
|
7
|
+
|
8
|
+
attr_reader :params
|
9
|
+
|
10
|
+
def initialize(client, query_params = [], params = {})
|
11
|
+
setup client, base_query.push(*query_params), params
|
12
|
+
end
|
13
|
+
|
14
|
+
def reinitialize(new_params: {}, add_query: [])
|
15
|
+
add_query = [add_query] unless add_query.is_a?(Array)
|
16
|
+
new_query = add_query&.any? ? @query_params.push(*add_query) : @query_params
|
17
|
+
setup @client, new_query, new_params
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
HTTP_METHODS_REGEXP = /\Ado_(get|post|put|delete)\z/.freeze
|
24
|
+
|
25
|
+
def respond_to_missing?(method, _include_all)
|
26
|
+
return true if HTTP_METHODS_REGEXP.match?(method.to_s)
|
27
|
+
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
def method_missing(method, *_args)
|
32
|
+
if method.to_s =~ HTTP_METHODS_REGEXP
|
33
|
+
send Regexp.last_match(1), @uri, @client, @params
|
34
|
+
else
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup(client, query_params = [], params = {})
|
40
|
+
@query_params = query_params
|
41
|
+
@uri = partial_uri(@query_params)
|
42
|
+
@client = client
|
43
|
+
@params = params
|
44
|
+
end
|
45
|
+
|
46
|
+
def partial_uri(raw_mapping)
|
47
|
+
template = Addressable::Template.new '{/segments*}'
|
48
|
+
template.expand(
|
49
|
+
segments: raw_mapping.to_a.flatten
|
50
|
+
).to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
def base_query
|
54
|
+
[]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
class Error < StandardError
|
5
|
+
ClientError = Class.new(self)
|
6
|
+
ServerError = Class.new(self)
|
7
|
+
|
8
|
+
BadRequest = Class.new(ClientError)
|
9
|
+
Unauthorized = Class.new(ClientError)
|
10
|
+
NotAcceptable = Class.new(ClientError)
|
11
|
+
NotFound = Class.new(ClientError)
|
12
|
+
Conflict = Class.new(ClientError)
|
13
|
+
TooManyRequests = Class.new(ClientError)
|
14
|
+
Forbidden = Class.new(ClientError)
|
15
|
+
Locked = Class.new(ClientError)
|
16
|
+
MethodNotAllowed = Class.new(ClientError)
|
17
|
+
|
18
|
+
NotImplemented = Class.new(ServerError)
|
19
|
+
BadGateway = Class.new(ServerError)
|
20
|
+
ServiceUnavailable = Class.new(ServerError)
|
21
|
+
GatewayTimeout = Class.new(ServerError)
|
22
|
+
|
23
|
+
ERRORS = {
|
24
|
+
400 => RatingChgkV2::Error::BadRequest,
|
25
|
+
401 => RatingChgkV2::Error::Unauthorized,
|
26
|
+
403 => RatingChgkV2::Error::Forbidden,
|
27
|
+
404 => RatingChgkV2::Error::NotFound,
|
28
|
+
405 => RatingChgkV2::Error::MethodNotAllowed,
|
29
|
+
406 => RatingChgkV2::Error::NotAcceptable,
|
30
|
+
409 => RatingChgkV2::Error::Conflict,
|
31
|
+
423 => RatingChgkV2::Error::Locked,
|
32
|
+
429 => RatingChgkV2::Error::TooManyRequests,
|
33
|
+
500 => RatingChgkV2::Error::ServerError,
|
34
|
+
502 => RatingChgkV2::Error::BadGateway,
|
35
|
+
503 => RatingChgkV2::Error::ServiceUnavailable,
|
36
|
+
504 => RatingChgkV2::Error::GatewayTimeout
|
37
|
+
}.freeze
|
38
|
+
|
39
|
+
class << self
|
40
|
+
# Create a new error from an HTTP response
|
41
|
+
def from_response(body)
|
42
|
+
msg = body['detail'] || body['message']
|
43
|
+
new msg.to_s
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Initializes a new Error object
|
48
|
+
def initialize(message = '')
|
49
|
+
super(message)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module RatingChgkV2
|
6
|
+
module JsonHandler
|
7
|
+
# JSON custom parser. Uses built-in JSON by default but can be overridden to any other parser
|
8
|
+
|
9
|
+
# Converts Ruby object to JSON
|
10
|
+
def custom_dump(obj)
|
11
|
+
JSON.dump obj
|
12
|
+
end
|
13
|
+
|
14
|
+
# Converts JSON to Ruby object
|
15
|
+
def custom_load(obj)
|
16
|
+
JSON.parse obj
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Models
|
5
|
+
class BaseModel
|
6
|
+
using RatingChgkV2::Utils::StringUtils
|
7
|
+
|
8
|
+
attr_reader :endpoint
|
9
|
+
|
10
|
+
def self.load(method, endpoint)
|
11
|
+
new endpoint.send(method), endpoint
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(raw_data, endpoint = nil)
|
15
|
+
@endpoint = endpoint
|
16
|
+
|
17
|
+
self.class.const_get(:ATTRIBUTES).each do |att|
|
18
|
+
instance_variable_set :"@#{att}", (raw_data[att] || raw_data[att.to_sym])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.inherited(subclass)
|
23
|
+
subclass.class_exec do
|
24
|
+
filename = subclass.name.base_class_name.snakecase.delete_suffix('_model')
|
25
|
+
attrs = YAML.load_file File.expand_path("../data/#{filename}.yml", __dir__)
|
26
|
+
|
27
|
+
const_set :ATTRIBUTES, attrs
|
28
|
+
|
29
|
+
attrs.each do |att|
|
30
|
+
attr_reader(att)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Models
|
5
|
+
class CountryModel < BaseModel
|
6
|
+
def update(params = {})
|
7
|
+
endpoint.reinitialize new_params: params
|
8
|
+
self.class.load :do_put, endpoint
|
9
|
+
end
|
10
|
+
|
11
|
+
def destroy
|
12
|
+
endpoint.do_delete
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Models
|
5
|
+
class PlayerModel < BaseModel
|
6
|
+
def seasons(params = {})
|
7
|
+
endpoint.reinitialize new_params: params, add_query: :seasons
|
8
|
+
RatingChgkV2::Collections::PlayerSeasonsCollection.load :do_get, endpoint
|
9
|
+
end
|
10
|
+
|
11
|
+
def tournaments(params = {})
|
12
|
+
endpoint.reinitialize new_params: params, add_query: :tournaments
|
13
|
+
RatingChgkV2::Collections::PlayerTournamentsCollection.load :do_get, endpoint
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Models
|
5
|
+
class SeasonModel < BaseModel
|
6
|
+
def update(params = {})
|
7
|
+
endpoint.reinitialize new_params: params
|
8
|
+
self.class.load :do_put, endpoint
|
9
|
+
end
|
10
|
+
|
11
|
+
def destroy
|
12
|
+
endpoint.do_delete
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Models
|
5
|
+
class TeamModel < BaseModel
|
6
|
+
def seasons(params = {})
|
7
|
+
endpoint.reinitialize new_params: params, add_query: :seasons
|
8
|
+
RatingChgkV2::Collections::PlayerSeasonsCollection.load :do_get, endpoint
|
9
|
+
end
|
10
|
+
|
11
|
+
def tournaments(params = {})
|
12
|
+
endpoint.reinitialize new_params: params, add_query: :tournaments
|
13
|
+
RatingChgkV2::Collections::TeamTournamentsCollection.load :do_get, endpoint
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Models
|
5
|
+
class TournamentModel < BaseModel
|
6
|
+
def appeals
|
7
|
+
endpoint.reinitialize add_query: :appeals
|
8
|
+
RatingChgkV2::Collections::TournamentAppealsCollection.load :do_get, endpoint
|
9
|
+
end
|
10
|
+
|
11
|
+
def requests
|
12
|
+
endpoint.reinitialize add_query: :requests
|
13
|
+
RatingChgkV2::Collections::TournamentRequestsCollection.load :do_get, endpoint
|
14
|
+
end
|
15
|
+
|
16
|
+
def results(params = {})
|
17
|
+
endpoint.reinitialize new_params: params, add_query: :results
|
18
|
+
RatingChgkV2::Collections::TournamentResultsCollection.load :do_get, endpoint
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Models
|
5
|
+
class VenueModel < BaseModel
|
6
|
+
def update(params = {})
|
7
|
+
endpoint.reinitialize new_params: params
|
8
|
+
self.class.load :do_put, endpoint
|
9
|
+
end
|
10
|
+
|
11
|
+
def destroy
|
12
|
+
endpoint.do_delete
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|