-
Notifications
You must be signed in to change notification settings - Fork 1
Getting started
This gem requires Ruby 2.7+. Install it by running:
$ gem install rating-chgk-v2
Include it in your script:
require 'rating_chgk_v2'
Initialize an API client:
@client = RatingChgkV2.client
Optionally, provide your JWT token and connection options:
@client = RatingChgkV2.client token: 'MY_JWT', params: {open_timeout: 100, timeout: 500}
Please note that JWT is required only if you are creating, updating, or deleting resources.
Now use client to perform API requests:
teams = @client.teams itemsPerPage: 2, name: 'Н', page: 3
Resources lists are represented as collections. For example, you can have a collection of teams:
teams = test_client.teams itemsPerPage: 2, page: 3
Collections act as enumerables (Enumerable
module is included for every collection) and respond to methods like []
, first
, last
, each
.
You can access a raw array of all collection items using the items
method:
teams.items
Each item is represented as a model (see below).
Some collections are paginated (please check documentation for a specific endpoint to learn whether it supports pagination) and respond to additional methods: next_page!
and prev_page!
. These methods load the previous or the next page:
tournaments = client.player_tournaments 123, itemsPerPage: 2, page: 1 # Fetch player tournaments, first page, 2 items per page
tournaments.next_page! # Fetch the second page for the same player, 2 items per page
Individual items are represented as models. Models respond to methods named after the resource's attributes:
country = client.country 20
country.name # => Нидерланды
country.id # => 20
You can find attributes names for each model inside YAML files in the data
folder.
You can fetch models from collections:
countries = client.countries
country = countries[1]
country.name # => Австралия
country.id # => 2