crawlora-gosugamers 0.1.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +57 -0
- data/lib/crawlora/gosugamers/client.rb +264 -0
- data/lib/crawlora/gosugamers/version.rb +5 -0
- data/lib/crawlora/gosugamers.rb +2 -0
- metadata +52 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7a75cd8951ff63f4fe6f46fe9387e6acbbd6a3fd207c7fc2ca8910a40c9d371c
|
|
4
|
+
data.tar.gz: 9bee57783ef81ba4f7225fc39cbe55489e89feda1b2f9a9a30f72e13b7987754
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 86e952b943d4c6bfa3338a382d85aaebe4f105debaa3e928940c306dff75555082a1281a758a2fcf8509dce0de3a212da3adb714a19eeb253677fdc2a741cb3e
|
|
7
|
+
data.tar.gz: dbe81fad57237f01cab6addf2fae44ff4896c7a0d4ebe7d1d6cfa56aaa07c5735d6730bb7aa5ac0842889927c1c659a711a034591b58178dcb7d21862b7cf245
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Crawlora
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Crawlora GosuGamers API client for Ruby (`crawlora-gosugamers`)
|
|
2
|
+
|
|
3
|
+
This Ruby gem calls Crawlora's hosted GosuGamers API at `https://api.crawlora.net/api/v1`. It exposes 17 endpoints covering esports matches, results, tournaments, games, news, and articles; it does not call or scrape GosuGamers directly. Requests require your Crawlora API key and use your account's service plan.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem "crawlora-gosugamers"
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Create an account at [crawlora.net](https://crawlora.net/signup?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=gosugamers-ruby-signup), open the [Crawlora console](https://crawlora.net/app?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=gosugamers-ruby-console) to get an API key, and set `CRAWLORA_API_KEY` before running the client:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
require "json"
|
|
15
|
+
require "crawlora/gosugamers"
|
|
16
|
+
|
|
17
|
+
client = Crawlora::Gosugamers::Client.new
|
|
18
|
+
result = client.request("gosugamers-article", JSON.parse("{\"id\": \"sample\"}"))
|
|
19
|
+
puts result
|
|
20
|
+
client.close
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Use an operation-specific method for normal calls. `request(operation_id, params = {}, response_type: :auto)` is available for every operation. `response_type: :text` returns raw response text. This gem includes 17 API operations.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
client = Crawlora::Gosugamers::Client.new(api_key: ENV.fetch("CRAWLORA_API_KEY"), timeout: 30)
|
|
27
|
+
# client.<operation_method>(<endpoint parameters>)
|
|
28
|
+
client.close
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Client options include `api_key`, `base_url`, and `timeout`. Ruby stdlib provides the HTTP and JSON support.
|
|
32
|
+
|
|
33
|
+
## Supported GosuGamers API endpoints
|
|
34
|
+
|
|
35
|
+
Browse every route included in this gem. The [endpoint reference](https://github.com/Crawlora-org/crawlora-gosugamers/blob/main/docs/usage.md) includes parameter and response details.
|
|
36
|
+
|
|
37
|
+
| Method | Endpoint | API operation | Description |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| `GET` | `/gosugamers/article` | `gosugamers-article` | GosuGamers article |
|
|
40
|
+
| `GET` | `/gosugamers/articles` | `gosugamers-articles` | GosuGamers news and features archive |
|
|
41
|
+
| `GET` | `/gosugamers/encounters` | `gosugamers-encounters` | GosuGamers head-to-head meetings |
|
|
42
|
+
| `GET` | `/gosugamers/games` | `gosugamers-games` | GosuGamers game sections |
|
|
43
|
+
| `GET` | `/gosugamers/match` | `gosugamers-match` | GosuGamers esports match detail |
|
|
44
|
+
| `GET` | `/gosugamers/match-game` | `gosugamers-match-game` | GosuGamers single game (map) of a match |
|
|
45
|
+
| `GET` | `/gosugamers/matches` | `gosugamers-matches` | GosuGamers upcoming and live esports matches |
|
|
46
|
+
| `GET` | `/gosugamers/player` | `gosugamers-player` | GosuGamers esports player profile |
|
|
47
|
+
| `GET` | `/gosugamers/rankings` | `gosugamers-rankings` | GosuGamers team rankings |
|
|
48
|
+
| `GET` | `/gosugamers/results` | `gosugamers-results` | GosuGamers recent esports match results |
|
|
49
|
+
| `GET` | `/gosugamers/stage-groups` | `gosugamers-stage-groups` | GosuGamers tournament stage groups |
|
|
50
|
+
| `GET` | `/gosugamers/team` | `gosugamers-team` | GosuGamers esports team profile |
|
|
51
|
+
| `GET` | `/gosugamers/team-results` | `gosugamers-team-results` | GosuGamers team match history |
|
|
52
|
+
| `GET` | `/gosugamers/tournament` | `gosugamers-tournament` | GosuGamers esports tournament detail |
|
|
53
|
+
| `GET` | `/gosugamers/tournament-participants` | `gosugamers-tournament-participants` | GosuGamers tournament participants |
|
|
54
|
+
| `GET` | `/gosugamers/tournament-talents` | `gosugamers-tournament-talents` | GosuGamers tournament broadcast talents |
|
|
55
|
+
| `GET` | `/gosugamers/tournaments` | `gosugamers-tournaments` | GosuGamers esports tournament directory |
|
|
56
|
+
|
|
57
|
+
See [Crawlora](https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=gosugamers-ruby-homepage), the [API documentation](https://crawlora.net/docs?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=gosugamers-ruby-api-docs), and [the package repository](https://github.com/Crawlora-org/crawlora-gosugamers) for account setup, the API operation reference, and release history.
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Crawlora
|
|
6
|
+
module Gosugamers
|
|
7
|
+
module Errors
|
|
8
|
+
class Error < StandardError
|
|
9
|
+
attr_reader :status, :operation_id, :body
|
|
10
|
+
|
|
11
|
+
def initialize(message, status: nil, operation_id: nil, body: nil)
|
|
12
|
+
super(message)
|
|
13
|
+
@status, @operation_id, @body = status, operation_id, body
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
class ClientError < Error; end
|
|
17
|
+
class ServerError < Error; end
|
|
18
|
+
class NetworkError < Error; end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
OPERATIONS = JSON.parse(<<~'JSON').freeze
|
|
22
|
+
{"gosugamers-article": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-article", "method": "GET", "params": [{"description": "Numeric article id from gosugamers-articles", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "79434"}], "path": "/gosugamers/article", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "gosugamers-articles": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-articles", "method": "GET", "params": [{"description": "Article section; one of dota2, counterstrike, lol, valorant, mobile-legends, pubg-mobile, wild-rift, free-fire, battlegrounds-mobile-india, entertainment, genshin-impact, honkai-star-rail, zenless-zone-zero, honor-of-kings, umamusume-pretty-derby; omit for all", "enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india", "entertainment", "genshin-impact", "honkai-star-rail", "zenless-zone-zero", "honor-of-kings", "umamusume-pretty-derby"], "in": "query", "name": "section", "type": "string"}, {"description": "Article type; one of news, features; omit for both", "enum": ["news", "features"], "in": "query", "name": "type", "type": "string"}, {"description": "1-based page; defaults to 1", "in": "query", "minimum": 1, "name": "page", "type": "integer"}, {"description": "Page size, 1 to 100; defaults to 10", "in": "query", "maximum": 100, "minimum": 1, "name": "page_size", "type": "integer"}], "path": "/gosugamers/articles", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india", "entertainment", "genshin-impact", "honkai-star-rail", "zenless-zone-zero", "honor-of-kings", "umamusume-pretty-derby"], "in": "query", "name": "section", "type": "string"}, {"enum": ["news", "features"], "in": "query", "name": "type", "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "page_size", "type": "integer"}], "security": ["ApiKeyAuth"]}, "gosugamers-encounters": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-encounters", "method": "GET", "params": [{"description": "Game section of the match; one of dota2, counterstrike, lol, valorant, mobile-legends, pubg-mobile, wild-rift, free-fire, battlegrounds-mobile-india", "enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "required": true, "type": "string"}, {"description": "Numeric id of the match whose other meetings are wanted; that match is left out", "in": "query", "name": "match_id", "required": true, "type": "string", "x-example": "660816"}, {"description": "Numeric id of the first team", "in": "query", "name": "team1_id", "required": true, "type": "string", "x-example": "38335"}, {"description": "Numeric id of the second team", "in": "query", "name": "team2_id", "required": true, "type": "string", "x-example": "37547"}], "path": "/gosugamers/encounters", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "required": true, "type": "string"}, {"in": "query", "name": "match_id", "required": true, "type": "string"}, {"in": "query", "name": "team1_id", "required": true, "type": "string"}, {"in": "query", "name": "team2_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "gosugamers-games": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-games", "method": "GET", "params": [], "path": "/gosugamers/games", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "gosugamers-match": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-match", "method": "GET", "params": [{"description": "Game section; one of dota2, counterstrike, lol, valorant, mobile-legends, pubg-mobile, wild-rift, free-fire, battlegrounds-mobile-india", "enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "required": true, "type": "string", "x-example": "dota2"}, {"description": "Numeric tournament id from gosugamers-matches or gosugamers-results (tournament.id)", "in": "query", "name": "tournament_id", "required": true, "type": "string", "x-example": "63208"}, {"description": "Numeric match id from gosugamers-matches or gosugamers-results (id)", "in": "query", "name": "match_id", "required": true, "type": "string", "x-example": "663299"}], "path": "/gosugamers/match", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "required": true, "type": "string"}, {"in": "query", "name": "tournament_id", "required": true, "type": "string"}, {"in": "query", "name": "match_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "gosugamers-match-game": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-match-game", "method": "GET", "params": [{"description": "Numeric game id from the games list of gosugamers-match", "in": "query", "name": "game_id", "required": true, "type": "string", "x-example": "1361936"}], "path": "/gosugamers/match-game", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "game_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "gosugamers-matches": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-matches", "method": "GET", "params": [{"description": "Game section; one of dota2, counterstrike, lol, valorant, mobile-legends, pubg-mobile, wild-rift, free-fire, battlegrounds-mobile-india; omit for all games", "enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "type": "string"}, {"description": "1-based page; page 1 with the default size is read from the public page, any other page or size from the site's JSON API; defaults to 1", "in": "query", "minimum": 1, "name": "page", "type": "integer"}, {"description": "Page size, 1 to 100; defaults to 10", "in": "query", "maximum": 100, "minimum": 1, "name": "page_size", "type": "integer"}], "path": "/gosugamers/matches", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "page_size", "type": "integer"}], "security": ["ApiKeyAuth"]}, "gosugamers-player": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-player", "method": "GET", "params": [{"description": "Game section; one of dota2, counterstrike, lol, valorant, mobile-legends, pubg-mobile, wild-rift, free-fire, battlegrounds-mobile-india", "enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "required": true, "type": "string", "x-example": "dota2"}, {"description": "Numeric player id from gosugamers-team (roster[].id)", "in": "query", "name": "player_id", "required": true, "type": "string", "x-example": "368742"}], "path": "/gosugamers/player", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "required": true, "type": "string"}, {"in": "query", "name": "player_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "gosugamers-rankings": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-rankings", "method": "GET", "params": [{"description": "Game section; one of dota2, counterstrike, lol, valorant, mobile-legends, pubg-mobile, wild-rift, free-fire, battlegrounds-mobile-india", "enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "required": true, "type": "string"}, {"description": "Ranking region id from the regions list of the response; 0 is Global; defaults to 0", "in": "query", "minimum": 0, "name": "region_id", "type": "integer"}, {"description": "Team name prefix, up to 100 characters", "in": "query", "name": "q", "type": "string", "x-example": "Te"}, {"description": "1-based page; defaults to 1", "in": "query", "minimum": 1, "name": "page", "type": "integer"}, {"description": "Page size, 1 to 100; defaults to 10", "in": "query", "maximum": 100, "minimum": 1, "name": "page_size", "type": "integer"}], "path": "/gosugamers/rankings", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "required": true, "type": "string"}, {"in": "query", "name": "region_id", "type": "integer"}, {"in": "query", "name": "q", "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "page_size", "type": "integer"}], "security": ["ApiKeyAuth"]}, "gosugamers-results": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-results", "method": "GET", "params": [{"description": "Game section; one of dota2, counterstrike, lol, valorant, mobile-legends, pubg-mobile, wild-rift, free-fire, battlegrounds-mobile-india; omit for all games", "enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "type": "string"}, {"description": "1-based page; page 1 with the default size is read from the public page, any other page or size from the site's JSON API; defaults to 1", "in": "query", "minimum": 1, "name": "page", "type": "integer"}, {"description": "Page size, 1 to 100; defaults to 10", "in": "query", "maximum": 100, "minimum": 1, "name": "page_size", "type": "integer"}], "path": "/gosugamers/results", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "page_size", "type": "integer"}], "security": ["ApiKeyAuth"]}, "gosugamers-stage-groups": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-stage-groups", "method": "GET", "params": [{"description": "Numeric tournament id from gosugamers-tournaments or gosugamers-matches", "in": "query", "name": "tournament_id", "required": true, "type": "string", "x-example": "63147"}, {"description": "Numeric stage id (stages[].id) from gosugamers-tournament", "in": "query", "name": "stage_id", "required": true, "type": "string", "x-example": "28413"}], "path": "/gosugamers/stage-groups", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "tournament_id", "required": true, "type": "string"}, {"in": "query", "name": "stage_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "gosugamers-team": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-team", "method": "GET", "params": [{"description": "Game section; one of dota2, counterstrike, lol, valorant, mobile-legends, pubg-mobile, wild-rift, free-fire, battlegrounds-mobile-india", "enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "required": true, "type": "string", "x-example": "dota2"}, {"description": "Numeric team id from gosugamers-matches, gosugamers-results or gosugamers-match (teams[].id)", "in": "query", "name": "team_id", "required": true, "type": "string", "x-example": "51203"}], "path": "/gosugamers/team", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "required": true, "type": "string"}, {"in": "query", "name": "team_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "gosugamers-team-results": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-team-results", "method": "GET", "params": [{"description": "Numeric team id from gosugamers-rankings, gosugamers-results or gosugamers-team", "in": "query", "name": "team_id", "required": true, "type": "string", "x-example": "37547"}, {"description": "1-based page; defaults to 1", "in": "query", "minimum": 1, "name": "page", "type": "integer"}, {"description": "Page size, 1 to 100; defaults to 10", "in": "query", "maximum": 100, "minimum": 1, "name": "page_size", "type": "integer"}], "path": "/gosugamers/team-results", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "team_id", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "page_size", "type": "integer"}], "security": ["ApiKeyAuth"]}, "gosugamers-tournament": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-tournament", "method": "GET", "params": [{"description": "Game section; one of dota2, counterstrike, lol, valorant, mobile-legends, pubg-mobile, wild-rift, free-fire, battlegrounds-mobile-india", "enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "required": true, "type": "string", "x-example": "dota2"}, {"description": "Numeric tournament id from gosugamers-matches or gosugamers-results (tournament.id)", "in": "query", "name": "tournament_id", "required": true, "type": "string", "x-example": "63208"}], "path": "/gosugamers/tournament", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "required": true, "type": "string"}, {"in": "query", "name": "tournament_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "gosugamers-tournament-participants": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-tournament-participants", "method": "GET", "params": [{"description": "Game section of the tournament; one of dota2, counterstrike, lol, valorant, mobile-legends, pubg-mobile, wild-rift, free-fire, battlegrounds-mobile-india", "enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "required": true, "type": "string"}, {"description": "Numeric tournament id from gosugamers-tournaments, gosugamers-matches or gosugamers-results", "in": "query", "name": "tournament_id", "required": true, "type": "string", "x-example": "63147"}], "path": "/gosugamers/tournament-participants", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "required": true, "type": "string"}, {"in": "query", "name": "tournament_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "gosugamers-tournament-talents": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-tournament-talents", "method": "GET", "params": [{"description": "Numeric tournament id from gosugamers-tournaments, gosugamers-matches or gosugamers-results", "in": "query", "name": "tournament_id", "required": true, "type": "string", "x-example": "63147"}], "path": "/gosugamers/tournament-talents", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "tournament_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "gosugamers-tournaments": {"bodyParam": null, "bodyRequired": false, "id": "gosugamers-tournaments", "method": "GET", "params": [{"description": "Game section; one of dota2, counterstrike, lol, valorant, mobile-legends, pubg-mobile, wild-rift, free-fire, battlegrounds-mobile-india; omit for all games", "enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "type": "string"}, {"description": "Tournament state; one of all, ongoing, upcoming, past; defaults to all", "enum": ["all", "ongoing", "upcoming", "past"], "in": "query", "name": "state", "type": "string"}, {"description": "Tournament name prefix, up to 100 characters", "in": "query", "name": "q", "type": "string", "x-example": "VCT"}, {"description": "1-based page; defaults to 1", "in": "query", "minimum": 1, "name": "page", "type": "integer"}, {"description": "Page size, 1 to 100; defaults to 10", "in": "query", "maximum": 100, "minimum": 1, "name": "page_size", "type": "integer"}], "path": "/gosugamers/tournaments", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["dota2", "counterstrike", "lol", "valorant", "mobile-legends", "pubg-mobile", "wild-rift", "free-fire", "battlegrounds-mobile-india"], "in": "query", "name": "game", "type": "string"}, {"enum": ["all", "ongoing", "upcoming", "past"], "in": "query", "name": "state", "type": "string"}, {"in": "query", "name": "q", "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "page_size", "type": "integer"}], "security": ["ApiKeyAuth"]}}
|
|
23
|
+
JSON
|
|
24
|
+
OPERATION_IDS = JSON.parse(<<~'JSON').freeze
|
|
25
|
+
["gosugamers-article", "gosugamers-articles", "gosugamers-encounters", "gosugamers-games", "gosugamers-match", "gosugamers-match-game", "gosugamers-matches", "gosugamers-player", "gosugamers-rankings", "gosugamers-results", "gosugamers-stage-groups", "gosugamers-team", "gosugamers-team-results", "gosugamers-tournament", "gosugamers-tournament-participants", "gosugamers-tournament-talents", "gosugamers-tournaments"]
|
|
26
|
+
JSON
|
|
27
|
+
OPERATION_COUNT = OPERATION_IDS.length
|
|
28
|
+
|
|
29
|
+
class Client
|
|
30
|
+
attr_reader :base_url
|
|
31
|
+
|
|
32
|
+
def initialize(api_key: ENV["CRAWLORA_API_KEY"], base_url: "https://api.crawlora.net/api/v1", timeout: 30, user_agent: "crawlora-gosugamers-ruby/0.1.0", transport: nil)
|
|
33
|
+
@api_key = api_key
|
|
34
|
+
@base_url = base_url.to_s.sub(%r{/+$}, "")
|
|
35
|
+
@timeout = Float(timeout)
|
|
36
|
+
@user_agent = user_agent
|
|
37
|
+
@transport = transport
|
|
38
|
+
@closed = false
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def request(operation_id, params = {}, response_type: :auto)
|
|
42
|
+
raise Errors::ClientError, "client is closed" if @closed
|
|
43
|
+
operation_id = operation_id.to_s
|
|
44
|
+
operation = OPERATIONS[operation_id]
|
|
45
|
+
raise Errors::ClientError.new("unknown operation: #{operation_id}", operation_id: operation_id) unless operation
|
|
46
|
+
raise Errors::ClientError.new("Crawlora API key is required", operation_id: operation_id) if @api_key.nil? || @api_key.to_s.empty?
|
|
47
|
+
normalized = params.each_with_object({}) { |(key, value), out| out[key.to_s] = value }
|
|
48
|
+
payload = request_body(operation, normalized)
|
|
49
|
+
url = build_url(operation, normalized)
|
|
50
|
+
uri = URI.parse(url)
|
|
51
|
+
request = operation["method"] == "POST" ? Net::HTTP::Post.new(uri) : Net::HTTP::Get.new(uri)
|
|
52
|
+
unless payload.nil?
|
|
53
|
+
request.body = payload
|
|
54
|
+
request["Content-Type"] = "application/json"
|
|
55
|
+
end
|
|
56
|
+
request["x-api-key"] = @api_key
|
|
57
|
+
request["User-Agent"] = @user_agent
|
|
58
|
+
request["Accept"] = operation["produces"].include?("text/plain") ? "application/json, text/plain" : "application/json"
|
|
59
|
+
begin
|
|
60
|
+
if @transport
|
|
61
|
+
response = if operation["method"] == "POST"
|
|
62
|
+
@transport.call(url, request.to_hash, @timeout, "POST", payload)
|
|
63
|
+
else
|
|
64
|
+
@transport.call(url, request.to_hash, @timeout)
|
|
65
|
+
end
|
|
66
|
+
status = Integer(response.fetch(:status) { response.fetch("status") })
|
|
67
|
+
body = response.fetch(:body) { response.fetch("body", "") }
|
|
68
|
+
headers = response.fetch(:headers) { response.fetch("headers", {}) }
|
|
69
|
+
content_type = headers["content-type"] || headers["Content-Type"]
|
|
70
|
+
else
|
|
71
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
72
|
+
http.use_ssl = uri.scheme == "https"
|
|
73
|
+
http.open_timeout = @timeout
|
|
74
|
+
http.read_timeout = @timeout
|
|
75
|
+
response = http.start { |connection| connection.request(request) }
|
|
76
|
+
status = response.code.to_i
|
|
77
|
+
body = response.body
|
|
78
|
+
content_type = response["content-type"]
|
|
79
|
+
end
|
|
80
|
+
rescue Timeout::Error, SocketError, SystemCallError, IOError, EOFError, Net::HTTPBadResponse, Net::ProtocolError, OpenSSL::SSL::SSLError => error
|
|
81
|
+
raise Errors::NetworkError.new("Crawlora request failed: #{error.message}", operation_id: operation_id)
|
|
82
|
+
end
|
|
83
|
+
unless status >= 200 && status < 300
|
|
84
|
+
klass = status >= 500 ? Errors::ServerError : Errors::ClientError
|
|
85
|
+
raise klass.new("Crawlora returned HTTP #{status}", status: status, operation_id: operation_id, body: body)
|
|
86
|
+
end
|
|
87
|
+
parse_response(body, content_type, operation, normalized, response_type)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def close
|
|
91
|
+
@closed = true
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def closed?
|
|
95
|
+
@closed
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def with
|
|
99
|
+
return self unless block_given?
|
|
100
|
+
yield self
|
|
101
|
+
ensure
|
|
102
|
+
close if block_given?
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def self.operation_count
|
|
106
|
+
OPERATION_COUNT
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def self.operation_ids
|
|
110
|
+
OPERATION_IDS
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def self.operations
|
|
114
|
+
OPERATIONS
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
define_method('article') do |**params|
|
|
118
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
119
|
+
request('gosugamers-article', params, response_type: response_type)
|
|
120
|
+
end
|
|
121
|
+
define_method('articles') do |**params|
|
|
122
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
123
|
+
request('gosugamers-articles', params, response_type: response_type)
|
|
124
|
+
end
|
|
125
|
+
define_method('encounters') do |**params|
|
|
126
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
127
|
+
request('gosugamers-encounters', params, response_type: response_type)
|
|
128
|
+
end
|
|
129
|
+
define_method('games') do |**params|
|
|
130
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
131
|
+
request('gosugamers-games', params, response_type: response_type)
|
|
132
|
+
end
|
|
133
|
+
define_method('match') do |**params|
|
|
134
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
135
|
+
request('gosugamers-match', params, response_type: response_type)
|
|
136
|
+
end
|
|
137
|
+
define_method('match_game') do |**params|
|
|
138
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
139
|
+
request('gosugamers-match-game', params, response_type: response_type)
|
|
140
|
+
end
|
|
141
|
+
define_method('matches') do |**params|
|
|
142
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
143
|
+
request('gosugamers-matches', params, response_type: response_type)
|
|
144
|
+
end
|
|
145
|
+
define_method('player') do |**params|
|
|
146
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
147
|
+
request('gosugamers-player', params, response_type: response_type)
|
|
148
|
+
end
|
|
149
|
+
define_method('rankings') do |**params|
|
|
150
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
151
|
+
request('gosugamers-rankings', params, response_type: response_type)
|
|
152
|
+
end
|
|
153
|
+
define_method('results') do |**params|
|
|
154
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
155
|
+
request('gosugamers-results', params, response_type: response_type)
|
|
156
|
+
end
|
|
157
|
+
define_method('stage_groups') do |**params|
|
|
158
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
159
|
+
request('gosugamers-stage-groups', params, response_type: response_type)
|
|
160
|
+
end
|
|
161
|
+
define_method('team') do |**params|
|
|
162
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
163
|
+
request('gosugamers-team', params, response_type: response_type)
|
|
164
|
+
end
|
|
165
|
+
define_method('team_results') do |**params|
|
|
166
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
167
|
+
request('gosugamers-team-results', params, response_type: response_type)
|
|
168
|
+
end
|
|
169
|
+
define_method('tournament') do |**params|
|
|
170
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
171
|
+
request('gosugamers-tournament', params, response_type: response_type)
|
|
172
|
+
end
|
|
173
|
+
define_method('tournament_participants') do |**params|
|
|
174
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
175
|
+
request('gosugamers-tournament-participants', params, response_type: response_type)
|
|
176
|
+
end
|
|
177
|
+
define_method('tournament_talents') do |**params|
|
|
178
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
179
|
+
request('gosugamers-tournament-talents', params, response_type: response_type)
|
|
180
|
+
end
|
|
181
|
+
define_method('tournaments') do |**params|
|
|
182
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
183
|
+
request('gosugamers-tournaments', params, response_type: response_type)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
private
|
|
187
|
+
|
|
188
|
+
# POST operations take their JSON body under the body parameter name or "body".
|
|
189
|
+
def request_body(operation, params)
|
|
190
|
+
name = operation["bodyParam"]
|
|
191
|
+
return nil if name.nil?
|
|
192
|
+
value = params.key?(name) ? params[name] : params["body"]
|
|
193
|
+
if value.nil?
|
|
194
|
+
raise Errors::ClientError.new("missing request body: #{name}", operation_id: operation["id"]) if operation["bodyRequired"]
|
|
195
|
+
return nil
|
|
196
|
+
end
|
|
197
|
+
value.is_a?(String) ? value : JSON.generate(value)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def build_url(operation, params)
|
|
201
|
+
known = operation["params"].map { |param| param["name"] }
|
|
202
|
+
known << "body" if operation["bodyParam"]
|
|
203
|
+
unknown = params.keys - known
|
|
204
|
+
raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
|
|
205
|
+
path = operation["path"].dup
|
|
206
|
+
operation["params"].select { |param| param["in"] == "path" }.each do |param|
|
|
207
|
+
value = params[param["name"]]
|
|
208
|
+
raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
|
|
209
|
+
path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
|
|
210
|
+
end
|
|
211
|
+
pairs = []
|
|
212
|
+
operation["queryParams"].each do |param|
|
|
213
|
+
name = param["name"]
|
|
214
|
+
value = params.key?(name) ? params[name] : param["default"]
|
|
215
|
+
if value.nil?
|
|
216
|
+
raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
|
|
217
|
+
next
|
|
218
|
+
end
|
|
219
|
+
enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
|
|
220
|
+
if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
|
|
221
|
+
raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
|
|
222
|
+
end
|
|
223
|
+
if value.is_a?(Array)
|
|
224
|
+
format = param["collectionFormat"] || "csv"
|
|
225
|
+
if format == "multi"
|
|
226
|
+
value.each { |item| pairs << [name, scalar(item)] }
|
|
227
|
+
else
|
|
228
|
+
separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
|
|
229
|
+
pairs << [name, value.map { |item| scalar(item) }.join(separator)]
|
|
230
|
+
end
|
|
231
|
+
else
|
|
232
|
+
pairs << [name, scalar(value)]
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
|
|
236
|
+
@base_url + path + (query.empty? ? "" : "?" + query)
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def scalar(value)
|
|
240
|
+
value == true ? "true" : (value == false ? "false" : value.to_s)
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def percent_encode(value)
|
|
244
|
+
URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def parse_response(body, content_type, operation, params, response_type)
|
|
248
|
+
type = response_type.to_s
|
|
249
|
+
raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
|
|
250
|
+
format = operation["params"].find { |param| param["name"] == "format" }
|
|
251
|
+
text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
|
|
252
|
+
raw_format = params["format"] && text_formats.include?(params["format"].to_s)
|
|
253
|
+
json_format = format && format["enum"] && format["enum"].any? { |value| %w[json application/json].include?(value.to_s.downcase) } && %w[json application/json].include?(params["format"].to_s.downcase)
|
|
254
|
+
is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
|
|
255
|
+
return body if type == "text" || raw_format || (type == "auto" && !is_json)
|
|
256
|
+
JSON.parse(body)
|
|
257
|
+
rescue JSON::ParserError => error
|
|
258
|
+
raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
public
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: crawlora-gosugamers
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Crawlora
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-11-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Ruby client for Crawlora's hosted GosuGamers API. Covers esports matches,
|
|
14
|
+
results, tournaments, games, news, and articles across 17 endpoints.
|
|
15
|
+
email:
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- CHANGELOG.md
|
|
21
|
+
- LICENSE
|
|
22
|
+
- README.md
|
|
23
|
+
- lib/crawlora/gosugamers.rb
|
|
24
|
+
- lib/crawlora/gosugamers/client.rb
|
|
25
|
+
- lib/crawlora/gosugamers/version.rb
|
|
26
|
+
homepage: https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=gosugamers-ruby-homepage
|
|
27
|
+
licenses:
|
|
28
|
+
- MIT
|
|
29
|
+
metadata:
|
|
30
|
+
source_code_uri: https://github.com/Crawlora-org/crawlora-gosugamers
|
|
31
|
+
documentation_uri: https://github.com/Crawlora-org/crawlora-gosugamers/blob/main/ruby/README.md
|
|
32
|
+
rubygems_mfa_required: 'true'
|
|
33
|
+
post_install_message:
|
|
34
|
+
rdoc_options: []
|
|
35
|
+
require_paths:
|
|
36
|
+
- lib
|
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '2.6'
|
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
requirements: []
|
|
48
|
+
rubygems_version: 3.4.19
|
|
49
|
+
signing_key:
|
|
50
|
+
specification_version: 4
|
|
51
|
+
summary: GosuGamers API client for Crawlora (17 endpoints)
|
|
52
|
+
test_files: []
|