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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3e53b64ea30c84c114b5b01ceb285985bb4ac2bb319fd5f6e4561fbca0b71bbc
|
4
|
+
data.tar.gz: 2f1dc39b971c9d27fce1ad4b19d8bc537cebc587ed4a16e20d630983bffa0cb5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d2dd209511a8b1ba0157a14170674d3050db1c957311d50e750c9e07b015457e210142cc107ddfc70a5b17a887803db8ef8ab1d7b72799220d124c4bf5d39a63
|
7
|
+
data.tar.gz: c6a48f19b76ef12a483fcf7e0e3d28b15dc97646400fd1a832d7afe417e9d74f4c30ff822886377ad5fd6d07ada01c6fdb9b79738cc8cc4030e9d5dd56483d93
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
## Our Standards
|
8
|
+
|
9
|
+
Examples of behavior that contributes to creating a positive environment include:
|
10
|
+
|
11
|
+
* Using welcoming and inclusive language
|
12
|
+
* Being respectful of differing viewpoints and experiences
|
13
|
+
* Gracefully accepting constructive criticism
|
14
|
+
* Focusing on what is best for the community
|
15
|
+
* Showing empathy towards other community members
|
16
|
+
|
17
|
+
Examples of unacceptable behavior by participants include:
|
18
|
+
|
19
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
20
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
21
|
+
* Public or private harassment
|
22
|
+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
23
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
24
|
+
|
25
|
+
## Our Responsibilities
|
26
|
+
|
27
|
+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
28
|
+
|
29
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
30
|
+
|
31
|
+
## Scope
|
32
|
+
|
33
|
+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
34
|
+
|
35
|
+
## Enforcement
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at golosizpru@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
38
|
+
|
39
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
40
|
+
|
41
|
+
## Attribution
|
42
|
+
|
43
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
44
|
+
|
45
|
+
[homepage]: http://contributor-covenant.org
|
46
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
1. [Fork the repository.][fork]
|
4
|
+
2. [Create a topic branch.][branch]
|
5
|
+
3. Implement your feature or bug fix.
|
6
|
+
4. Don't forget to add specs and make sure they pass by running `rspec .`.
|
7
|
+
5. Make sure your code complies with the style guide by running `rubocop`. `rubocop -a` can automatically fix most issues for you. Run `rubocop -A` to make it more aggressive.
|
8
|
+
6. If necessary, add documentation for your feature or bug fix.
|
9
|
+
7. Commit and push your changes.
|
10
|
+
8. [Submit a pull request.][pr]
|
11
|
+
|
12
|
+
[fork]: http://help.github.com/fork-a-repo/
|
13
|
+
[branch]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-branches
|
14
|
+
[pr]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests
|
@@ -0,0 +1,11 @@
|
|
1
|
+
### Summary
|
2
|
+
|
3
|
+
Provide a general description of the code changes in your pull
|
4
|
+
request. Were there any bugs you had fixed? If so, mention them. If
|
5
|
+
these bugs have open GitHub issues, be sure to tag them here as well,
|
6
|
+
to keep the conversation linked together.
|
7
|
+
|
8
|
+
### Other Information
|
9
|
+
|
10
|
+
If there's anything else that's important and relevant to your pull
|
11
|
+
request, mention that information here.
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# RatingChgkV2
|
2
|
+
|
3
|
+
![CI](https://github.com/bodrovis/rating-chgk-v2/actions/workflows/ci.yml/badge.svg)
|
4
|
+
[![Test Coverage](https://codecov.io/gh/bodrovis/rating-chgk-v2/graph/badge.svg)](https://codecov.io/gh/bodrovis/rating-chgk-v2)
|
5
|
+
|
6
|
+
Ruby client for [competitive "What? Where? When?" (aka "CHGK") API](http://api.rating.chgk.net/). This gem is a replacement for [ChgkRating](https://github.com/bodrovis/ChgkRating) which worked only with the deprecated API version.
|
7
|
+
|
8
|
+
## Installation and requirements
|
9
|
+
|
10
|
+
This gem requires Ruby 2.7+. Install it by running:
|
11
|
+
|
12
|
+
```
|
13
|
+
$ gem install rating-chgk-v2
|
14
|
+
```
|
15
|
+
|
16
|
+
Include it in your script:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require 'rating_chgk_v2'
|
20
|
+
```
|
21
|
+
|
22
|
+
## Client initialization
|
23
|
+
|
24
|
+
Initialize an API client:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
@client = RatingChgkV2.client
|
28
|
+
```
|
29
|
+
|
30
|
+
Optionally, provide your JWT token and connection options (please note that JWT is not required to access most of the endpoints):
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
@client = RatingChgkV2.client token: 'MY_JWT', params: {open_timeout: 100, timeout: 500}
|
34
|
+
```
|
35
|
+
|
36
|
+
Now use client to perform API requests:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
teams = @client.teams itemsPerPage: 2, name: 'Н', page: 3
|
40
|
+
```
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
**[Please find documentation at our Wiki](https://github.com/bodrovis/rating-chgk-v2/wiki)**.
|
45
|
+
|
46
|
+
## Running tests
|
47
|
+
|
48
|
+
Tests are written in RSpec (all HTTP requests are stubbed):
|
49
|
+
|
50
|
+
```
|
51
|
+
rspec .
|
52
|
+
```
|
53
|
+
|
54
|
+
Observe test results and coverage.
|
55
|
+
|
56
|
+
## Copyright and license
|
57
|
+
|
58
|
+
Licensed under the [MIT license](./LICENSE.md).
|
59
|
+
|
60
|
+
Copyright (c) 2022 [Ilya Bodrov-Krukowski](http://bodrovis.tech)
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bundler/setup'
|
7
|
+
Bundler::GemHelper.install_tasks
|
8
|
+
rescue LoadError
|
9
|
+
puts 'although not required, bundler is recommened for running the tests'
|
10
|
+
end
|
11
|
+
|
12
|
+
task default: :spec
|
13
|
+
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
|
17
|
+
require 'rubocop/rake_task'
|
18
|
+
RuboCop::RakeTask.new do |task|
|
19
|
+
task.requires << 'rubocop-performance'
|
20
|
+
task.requires << 'rubocop-rspec'
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
class Client
|
5
|
+
include RatingChgkV2::Rest
|
6
|
+
|
7
|
+
attr_reader :token
|
8
|
+
attr_accessor :timeout, :open_timeout
|
9
|
+
|
10
|
+
def initialize(token: '', params: {})
|
11
|
+
@token = token
|
12
|
+
@timeout = params.fetch(:timeout, nil)
|
13
|
+
@open_timeout = params.fetch(:open_timeout, nil)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Collections
|
5
|
+
# Base class for all collections. A collection contains an array of models, for example
|
6
|
+
# a collection of players, tournaments, or regions. Some collections are paginated but not all.
|
7
|
+
class BaseCollection
|
8
|
+
include Enumerable
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
MODEL = ''
|
12
|
+
attr_reader :items, :endpoint
|
13
|
+
|
14
|
+
def_delegators :items, :[], :last, :each
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def load(method, endpoint)
|
18
|
+
new endpoint.send(method), endpoint
|
19
|
+
end
|
20
|
+
|
21
|
+
def paginated
|
22
|
+
include RatingChgkV2::Concerns::Paginated
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(raw_data, endpoint = nil)
|
27
|
+
setup raw_data, endpoint
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def setup(raw_data, endpoint)
|
33
|
+
@endpoint = endpoint
|
34
|
+
@items = produce_models_from raw_data
|
35
|
+
end
|
36
|
+
|
37
|
+
def produce_models_from(raw_data)
|
38
|
+
return [] if raw_data&.empty?
|
39
|
+
|
40
|
+
model_name = self.class.const_get :MODEL
|
41
|
+
model_klass = RatingChgkV2::Models.const_get "#{model_name}Model"
|
42
|
+
raw_data.map do |item|
|
43
|
+
model_klass.new item
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Concerns
|
5
|
+
module Paginated
|
6
|
+
def next_page!
|
7
|
+
page_num = current_page + 1
|
8
|
+
params = endpoint.params.merge({page: page_num})
|
9
|
+
endpoint.reinitialize new_params: params
|
10
|
+
setup endpoint.do_get, endpoint
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def prev_page!
|
15
|
+
return if current_page <= 1
|
16
|
+
|
17
|
+
page_num = current_page - 1
|
18
|
+
params = endpoint.params.merge({page: page_num})
|
19
|
+
endpoint.reinitialize new_params: params
|
20
|
+
setup endpoint.do_get, endpoint
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def current_page
|
27
|
+
endpoint.params[:page] || 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RatingChgkV2
|
4
|
+
module Connection
|
5
|
+
BASE_URL = 'https://api.rating.chgk.net/'
|
6
|
+
|
7
|
+
def connection(client)
|
8
|
+
Faraday.new(options(client), request_params_for(client)) do |faraday|
|
9
|
+
faraday.adapter Faraday.default_adapter
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def options(client)
|
16
|
+
headers = {
|
17
|
+
accept: 'application/json',
|
18
|
+
user_agent: "rating-chgk-v2 gem/#{RatingChgkV2::VERSION}",
|
19
|
+
'Content-Type': 'application/json',
|
20
|
+
accept_encoding: 'gzip,deflate,br'
|
21
|
+
}
|
22
|
+
|
23
|
+
headers = headers.merge({Authorization: "Bearer #{client.token}"}) if client.token
|
24
|
+
|
25
|
+
{headers: headers, url: BASE_URL}
|
26
|
+
end
|
27
|
+
|
28
|
+
# Allows to customize request params per-client
|
29
|
+
def request_params_for(client)
|
30
|
+
{request: {timeout: client.timeout, open_timeout: client.open_timeout}}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
- token
|
@@ -0,0 +1,20 @@
|
|
1
|
+
- id
|
2
|
+
- name
|
3
|
+
- lastEditDate
|
4
|
+
- dateStart
|
5
|
+
- dateEnd
|
6
|
+
- type
|
7
|
+
- orgcommittee
|
8
|
+
- synchData
|
9
|
+
- mainPayment
|
10
|
+
- discountedPayment
|
11
|
+
- discountedPaymentReason
|
12
|
+
- currency
|
13
|
+
- editors
|
14
|
+
- tournamentInRatingBalanced
|
15
|
+
- difficultyForecast
|
16
|
+
- maiiAegis
|
17
|
+
- maiiAegisUpdatedAt
|
18
|
+
- maiiRating
|
19
|
+
- maiiRatingUpdatedAt
|
20
|
+
- questionQty
|