crawlora-sofascore 0.2.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 +33 -0
- data/lib/crawlora/sofascore/client.rb +346 -0
- data/lib/crawlora/sofascore/version.rb +5 -0
- data/lib/crawlora/sofascore.rb +2 -0
- metadata +50 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7b7e369b8fffde9969c0ea9c185b5dc46adc2fae78ce1b169aef52173f855d43
|
|
4
|
+
data.tar.gz: 4b76078f69f9983f5a0c746ef6c8f31a316cc2751c3d14826f49757f790d82f7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a174521a92c2a68df623dd51eda768a3d6316174cf762935b8c0d8c68836526cf1f16cc3a2d5cd4c45f918302d85d167bf945fbe543bc7b56624e40cf2d6b076
|
|
7
|
+
data.tar.gz: 67ec71ab4e1b04a5f89d1673954f11a453758763519c23f360f572f79f985ac3588e0a874c3b48ac9cbb499ddb43b7ff81fd876eed4353e111c072bfa54f921b
|
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,33 @@
|
|
|
1
|
+
# Crawlora SofaScore Ruby client
|
|
2
|
+
|
|
3
|
+
This gem calls the Crawlora hosted API at `https://api.crawlora.net/api/v1`. It does not call or scrape SofaScore directly. Requests require your Crawlora API key and use your account's service plan.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem "crawlora-sofascore"
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Create an account at [crawlora.net](https://crawlora.net/signup), open the [Crawlora console](https://crawlora.net/app) to get an API key, and set `CRAWLORA_API_KEY` before running the client:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
require "json"
|
|
15
|
+
require "crawlora/sofascore"
|
|
16
|
+
|
|
17
|
+
client = Crawlora::Sofascore::Client.new
|
|
18
|
+
result = client.request("sofascore-search", JSON.parse("{\"q\": \"Liverpool\"}"))
|
|
19
|
+
puts result
|
|
20
|
+
client.close
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Use a generated operation 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 contains 43 operations and follows contract revision `sha256:91686922e3c5ab6569dbe0abd882fbbbc86c4395a86f151582a2291fb11de036`.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
client = Crawlora::Sofascore::Client.new(api_key: ENV.fetch("CRAWLORA_API_KEY"), timeout: 30)
|
|
27
|
+
# client.<operation_method>(<contract parameters>)
|
|
28
|
+
client.close
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Client options include `api_key`, `base_url`, and `timeout`. Ruby stdlib provides the HTTP and JSON transport. The gem follows contract revision `sha256:91686922e3c5ab6569dbe0abd882fbbbc86c4395a86f151582a2291fb11de036` and contains 43 operations.
|
|
32
|
+
|
|
33
|
+
See [Crawlora](https://crawlora.net/), the [API documentation](https://crawlora.net/docs), and [the package repository](https://github.com/Crawlora-org/crawlora-sofascore) for account setup, the generated operation reference, and release history.
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Crawlora
|
|
6
|
+
module Sofascore
|
|
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
|
+
{"sofascore-categories": {"id": "sofascore-categories", "method": "GET", "params": [{"description": "Sport key", "enum": ["american-football", "aussie-rules", "badminton", "bandy", "baseball", "basketball", "beach-volley", "cricket", "darts", "esports", "floorball", "football", "futsal", "handball", "ice-hockey", "mma", "minifootball", "padel", "rugby", "snooker", "table-tennis", "tennis", "volleyball", "waterpolo"], "in": "query", "name": "sport", "required": true, "type": "string", "x-example": "football"}], "path": "/sofascore/categories", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["american-football", "aussie-rules", "badminton", "bandy", "baseball", "basketball", "beach-volley", "cricket", "darts", "esports", "floorball", "football", "futsal", "handball", "ice-hockey", "mma", "minifootball", "padel", "rugby", "snooker", "table-tennis", "tennis", "volleyball", "waterpolo"], "in": "query", "name": "sport", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-category-tournaments": {"id": "sofascore-category-tournaments", "method": "GET", "params": [{"description": "Numeric SofaScore category id from the categories endpoint", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "1"}], "path": "/sofascore/category-tournaments", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-event": {"id": "sofascore-event", "method": "GET", "params": [{"description": "Numeric SofaScore event (match) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "14025013"}], "path": "/sofascore/event", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-event-best-players": {"id": "sofascore-event-best-players", "method": "GET", "params": [{"description": "Numeric SofaScore event (match) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "16363867"}], "path": "/sofascore/event-best-players", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-event-comments": {"id": "sofascore-event-comments", "method": "GET", "params": [{"description": "Numeric SofaScore event (match) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "16363867"}], "path": "/sofascore/event-comments", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-event-graph": {"id": "sofascore-event-graph", "method": "GET", "params": [{"description": "Numeric SofaScore event (match) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "16363867"}], "path": "/sofascore/event-graph", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-event-h2h": {"id": "sofascore-event-h2h", "method": "GET", "params": [{"description": "Numeric SofaScore event (match) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "14025013"}], "path": "/sofascore/event-h2h", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-event-incidents": {"id": "sofascore-event-incidents", "method": "GET", "params": [{"description": "Numeric SofaScore event (match) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "14025013"}], "path": "/sofascore/event-incidents", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-event-lineups": {"id": "sofascore-event-lineups", "method": "GET", "params": [{"description": "Numeric SofaScore event (match) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "14025013"}], "path": "/sofascore/event-lineups", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-event-odds": {"id": "sofascore-event-odds", "method": "GET", "params": [{"description": "Numeric SofaScore event (match) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "14025013"}], "path": "/sofascore/event-odds", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-event-player-statistics": {"id": "sofascore-event-player-statistics", "method": "GET", "params": [{"description": "Numeric SofaScore event (match) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "16363867"}, {"description": "Numeric SofaScore player id that took part in the match", "in": "query", "name": "player_id", "required": true, "type": "string", "x-example": "839956"}], "path": "/sofascore/event-player-statistics", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "player_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-event-shotmap": {"id": "sofascore-event-shotmap", "method": "GET", "params": [{"description": "Numeric SofaScore event (match) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "16363867"}], "path": "/sofascore/event-shotmap", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-event-statistics": {"id": "sofascore-event-statistics", "method": "GET", "params": [{"description": "Numeric SofaScore event (match) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "14025013"}], "path": "/sofascore/event-statistics", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-live-events": {"id": "sofascore-live-events", "method": "GET", "params": [{"description": "Sport key", "enum": ["american-football", "aussie-rules", "badminton", "bandy", "baseball", "basketball", "beach-volley", "cricket", "darts", "esports", "floorball", "football", "futsal", "handball", "ice-hockey", "mma", "minifootball", "padel", "rugby", "snooker", "table-tennis", "tennis", "volleyball", "waterpolo"], "in": "query", "name": "sport", "required": true, "type": "string", "x-example": "football"}], "path": "/sofascore/live-events", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["american-football", "aussie-rules", "badminton", "bandy", "baseball", "basketball", "beach-volley", "cricket", "darts", "esports", "floorball", "football", "futsal", "handball", "ice-hockey", "mma", "minifootball", "padel", "rugby", "snooker", "table-tennis", "tennis", "volleyball", "waterpolo"], "in": "query", "name": "sport", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-manager": {"id": "sofascore-manager", "method": "GET", "params": [{"description": "Numeric SofaScore manager id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "794873"}], "path": "/sofascore/manager", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-manager-events": {"id": "sofascore-manager-events", "method": "GET", "params": [{"description": "Numeric SofaScore manager id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "794873"}, {"description": "Zero-based page number", "in": "query", "name": "page", "type": "integer", "x-example": 0}], "path": "/sofascore/manager-events", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "sofascore-player": {"id": "sofascore-player", "method": "GET", "params": [{"description": "Numeric SofaScore player id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "855833"}], "path": "/sofascore/player", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-player-season-statistics": {"id": "sofascore-player-season-statistics", "method": "GET", "params": [{"description": "Numeric SofaScore player id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "839956"}, {"description": "Numeric SofaScore unique-tournament (competition) id from player-statistics-seasons", "in": "query", "name": "tournament_id", "required": true, "type": "string", "x-example": "17"}, {"description": "Numeric SofaScore season id from player-statistics-seasons", "in": "query", "name": "season", "required": true, "type": "string", "x-example": "96668"}, {"default": "overall", "description": "Statistics view", "enum": ["overall", "home", "away", "regular_season", "playoffs"], "in": "query", "name": "type", "type": "string"}], "path": "/sofascore/player-season-statistics", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "tournament_id", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "string"}, {"enum": ["overall", "home", "away", "regular_season", "playoffs"], "in": "query", "name": "type", "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-player-statistics-seasons": {"id": "sofascore-player-statistics-seasons", "method": "GET", "params": [{"description": "Numeric SofaScore player id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "839956"}], "path": "/sofascore/player-statistics-seasons", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-player-transfers": {"id": "sofascore-player-transfers", "method": "GET", "params": [{"description": "Numeric SofaScore player id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "839956"}], "path": "/sofascore/player-transfers", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-ranking-types": {"id": "sofascore-ranking-types", "method": "GET", "params": [], "path": "/sofascore/ranking-types", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "sofascore-rankings": {"id": "sofascore-rankings", "method": "GET", "params": [{"description": "Ranking id from sofascore-ranking-types", "enum": [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 34, 35, 36, 37, 40, 41, 42, 43, 44, 45, 46], "in": "query", "name": "type", "required": true, "type": "integer", "x-example": 5}, {"description": "Return only the first N rows, 1 to 500. Omit to return every row", "in": "query", "maximum": 500, "minimum": 1, "name": "limit", "type": "integer", "x-example": 10}], "path": "/sofascore/rankings", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "34", "35", "36", "37", "40", "41", "42", "43", "44", "45", "46"], "in": "query", "name": "type", "required": true, "type": "integer"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "sofascore-round-events": {"id": "sofascore-round-events", "method": "GET", "params": [{"description": "Numeric SofaScore unique-tournament (competition) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "17"}, {"description": "Numeric SofaScore season id", "in": "query", "name": "season", "required": true, "type": "string", "x-example": "76986"}, {"description": "Round number", "in": "query", "name": "round", "required": true, "type": "integer", "x-example": 1}, {"description": "Round slug from tournament-rounds, for example round-of-16; required for knockout and named cup rounds", "in": "query", "name": "slug", "type": "string", "x-example": "round-of-16"}, {"description": "Round prefix from tournament-rounds, for example Qualification; only valid together with slug", "in": "query", "name": "prefix", "type": "string", "x-example": "Qualification"}], "path": "/sofascore/round-events", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "string"}, {"in": "query", "name": "round", "required": true, "type": "integer"}, {"in": "query", "name": "slug", "type": "string"}, {"in": "query", "name": "prefix", "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-scheduled-events": {"id": "sofascore-scheduled-events", "method": "GET", "params": [{"description": "Numeric SofaScore category id from the categories endpoint", "in": "query", "name": "category_id", "required": true, "type": "string", "x-example": "13"}, {"description": "UTC calendar date, YYYY-MM-DD", "in": "query", "name": "date", "required": true, "type": "string", "x-example": "2026-10-08"}], "path": "/sofascore/scheduled-events", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "category_id", "required": true, "type": "string"}, {"in": "query", "name": "date", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-scheduled-tournaments": {"id": "sofascore-scheduled-tournaments", "method": "GET", "params": [{"description": "Sport key", "enum": ["american-football", "aussie-rules", "badminton", "bandy", "baseball", "basketball", "beach-volley", "cricket", "darts", "esports", "floorball", "football", "futsal", "handball", "ice-hockey", "mma", "minifootball", "padel", "rugby", "snooker", "table-tennis", "tennis", "volleyball", "waterpolo"], "in": "query", "name": "sport", "required": true, "type": "string", "x-example": "football"}, {"description": "UTC calendar date, YYYY-MM-DD", "in": "query", "name": "date", "required": true, "type": "string", "x-example": "2026-10-08"}, {"description": "One-based page number; defaults to 1", "in": "query", "maximum": 100, "minimum": 1, "name": "page", "type": "integer", "x-example": 1}], "path": "/sofascore/scheduled-tournaments", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["american-football", "aussie-rules", "badminton", "bandy", "baseball", "basketball", "beach-volley", "cricket", "darts", "esports", "floorball", "football", "futsal", "handball", "ice-hockey", "mma", "minifootball", "padel", "rugby", "snooker", "table-tennis", "tennis", "volleyball", "waterpolo"], "in": "query", "name": "sport", "required": true, "type": "string"}, {"in": "query", "name": "date", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "sofascore-search": {"id": "sofascore-search", "method": "GET", "params": [{"description": "Free-text search query", "in": "query", "name": "q", "required": true, "type": "string", "x-example": "barcelona"}], "path": "/sofascore/search", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "q", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-season-events": {"id": "sofascore-season-events", "method": "GET", "params": [{"description": "Numeric SofaScore unique-tournament (competition) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "17"}, {"description": "Numeric SofaScore season id", "in": "query", "name": "season", "required": true, "type": "string", "x-example": "96668"}, {"description": "Upcoming fixtures or finished results", "enum": ["next", "last"], "in": "query", "name": "direction", "required": true, "type": "string", "x-example": "last"}, {"description": "Zero-based page number. Defaults to 0", "in": "query", "minimum": 0, "name": "page", "type": "integer", "x-example": 0}], "path": "/sofascore/season-events", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "string"}, {"enum": ["next", "last"], "in": "query", "name": "direction", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "sofascore-sports": {"id": "sofascore-sports", "method": "GET", "params": [], "path": "/sofascore/sports", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "sofascore-standings": {"id": "sofascore-standings", "method": "GET", "params": [{"description": "Numeric SofaScore unique-tournament (competition) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "17"}, {"description": "Numeric SofaScore season id", "in": "query", "name": "season", "required": true, "type": "string", "x-example": "76986"}, {"description": "Standings variant", "enum": ["total", "home", "away"], "in": "query", "name": "type", "required": true, "type": "string", "x-example": "total"}], "path": "/sofascore/standings", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "string"}, {"enum": ["total", "home", "away"], "in": "query", "name": "type", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-team": {"id": "sofascore-team", "method": "GET", "params": [{"description": "Numeric SofaScore team id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "2817"}], "path": "/sofascore/team", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-team-events": {"id": "sofascore-team-events", "method": "GET", "params": [{"description": "Numeric SofaScore team id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "2817"}, {"description": "Fixture direction", "enum": ["next", "last"], "in": "query", "name": "direction", "required": true, "type": "string", "x-example": "next"}, {"description": "Zero-based page number", "in": "query", "name": "page", "type": "integer", "x-example": 0}], "path": "/sofascore/team-events", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"enum": ["next", "last"], "in": "query", "name": "direction", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "sofascore-team-of-the-week": {"id": "sofascore-team-of-the-week", "method": "GET", "params": [{"description": "Numeric SofaScore unique-tournament (competition) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "17"}, {"description": "Numeric SofaScore season id", "in": "query", "name": "season", "required": true, "type": "string", "x-example": "96668"}, {"description": "Numeric period id from sofascore-team-of-the-week-periods", "in": "query", "name": "period", "required": true, "type": "string", "x-example": "29321"}], "path": "/sofascore/team-of-the-week", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "string"}, {"in": "query", "name": "period", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-team-of-the-week-periods": {"id": "sofascore-team-of-the-week-periods", "method": "GET", "params": [{"description": "Numeric SofaScore unique-tournament (competition) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "17"}, {"description": "Numeric SofaScore season id", "in": "query", "name": "season", "required": true, "type": "string", "x-example": "96668"}], "path": "/sofascore/team-of-the-week-periods", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-team-players": {"id": "sofascore-team-players", "method": "GET", "params": [{"description": "Numeric SofaScore team id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "2817"}], "path": "/sofascore/team-players", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-team-season-statistics": {"id": "sofascore-team-season-statistics", "method": "GET", "params": [{"description": "Numeric SofaScore team id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "17"}, {"description": "Numeric SofaScore unique-tournament (competition) id from team-statistics-seasons", "in": "query", "name": "tournament_id", "required": true, "type": "string", "x-example": "17"}, {"description": "Numeric SofaScore season id from team-statistics-seasons", "in": "query", "name": "season", "required": true, "type": "string", "x-example": "96668"}, {"default": "overall", "description": "Statistics view", "enum": ["overall", "home", "away", "regular_season", "playoffs"], "in": "query", "name": "type", "type": "string"}], "path": "/sofascore/team-season-statistics", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "tournament_id", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "string"}, {"enum": ["overall", "home", "away", "regular_season", "playoffs"], "in": "query", "name": "type", "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-team-statistics-seasons": {"id": "sofascore-team-statistics-seasons", "method": "GET", "params": [{"description": "Numeric SofaScore team id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "17"}], "path": "/sofascore/team-statistics-seasons", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-team-transfers": {"id": "sofascore-team-transfers", "method": "GET", "params": [{"description": "Numeric SofaScore team id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "17"}], "path": "/sofascore/team-transfers", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-tournament-info": {"id": "sofascore-tournament-info", "method": "GET", "params": [{"description": "Numeric SofaScore unique-tournament (competition) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "17"}, {"description": "Numeric SofaScore season id. Omit for competition metadata only", "in": "query", "name": "season", "type": "string", "x-example": "96668"}], "path": "/sofascore/tournament-info", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "season", "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-tournament-player-statistics": {"id": "sofascore-tournament-player-statistics", "method": "GET", "params": [{"description": "Numeric SofaScore unique-tournament (competition) id of a football competition", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "17"}, {"description": "Numeric SofaScore season id", "in": "query", "name": "season", "required": true, "type": "string", "x-example": "96668"}, {"description": "Statistic to sort by. Defaults to rating", "enum": ["rating", "goals", "expectedGoals", "assists", "successfulDribbles", "tackles", "accuratePassesPercentage", "bigChancesMissed", "totalShots", "goalConversionPercentage", "interceptions", "clearances", "errorLeadToGoal", "outfielderBlocks", "bigChancesCreated", "accuratePasses", "keyPasses", "saves", "cleanSheet", "penaltySave", "savedShotsFromInsideTheBox", "runsOut"], "in": "query", "name": "order", "type": "string", "x-example": "goals"}, {"description": "Sort direction. Defaults to desc", "enum": ["desc", "asc"], "in": "query", "name": "direction", "type": "string", "x-example": "desc"}, {"description": "How statistics are accumulated. Defaults to total", "enum": ["total", "perGame", "per90"], "in": "query", "name": "accumulation", "type": "string", "x-example": "total"}, {"description": "Statistic columns returned. Defaults to summary", "enum": ["summary", "attack", "defence", "passing", "goalkeeper"], "in": "query", "name": "group", "type": "string", "x-example": "summary"}, {"description": "Rows per page, 1 to 100. Defaults to 20", "in": "query", "maximum": 100, "minimum": 1, "name": "limit", "type": "integer", "x-example": 20}, {"description": "Rows to skip. Defaults to 0", "in": "query", "minimum": 0, "name": "offset", "type": "integer", "x-example": 0}], "path": "/sofascore/tournament-player-statistics", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "string"}, {"enum": ["rating", "goals", "expectedGoals", "assists", "successfulDribbles", "tackles", "accuratePassesPercentage", "bigChancesMissed", "totalShots", "goalConversionPercentage", "interceptions", "clearances", "errorLeadToGoal", "outfielderBlocks", "bigChancesCreated", "accuratePasses", "keyPasses", "saves", "cleanSheet", "penaltySave", "savedShotsFromInsideTheBox", "runsOut"], "in": "query", "name": "order", "type": "string"}, {"enum": ["desc", "asc"], "in": "query", "name": "direction", "type": "string"}, {"enum": ["total", "perGame", "per90"], "in": "query", "name": "accumulation", "type": "string"}, {"enum": ["summary", "attack", "defence", "passing", "goalkeeper"], "in": "query", "name": "group", "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}, {"in": "query", "name": "offset", "type": "integer"}], "security": ["ApiKeyAuth"]}, "sofascore-tournament-rounds": {"id": "sofascore-tournament-rounds", "method": "GET", "params": [{"description": "Numeric SofaScore unique-tournament (competition) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "7"}, {"description": "Numeric SofaScore season id from tournament-seasons", "in": "query", "name": "season", "required": true, "type": "string", "x-example": "76953"}], "path": "/sofascore/tournament-rounds", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-tournament-seasons": {"id": "sofascore-tournament-seasons", "method": "GET", "params": [{"description": "Numeric SofaScore unique-tournament (competition) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "17"}], "path": "/sofascore/tournament-seasons", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "sofascore-tournament-top-players": {"id": "sofascore-tournament-top-players", "method": "GET", "params": [{"description": "Numeric SofaScore unique-tournament (competition) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "17"}, {"description": "Numeric SofaScore season id", "in": "query", "name": "season", "required": true, "type": "string", "x-example": "96668"}, {"description": "Statistics scope. Defaults to overall", "enum": ["overall", "regular_season", "playoffs"], "in": "query", "name": "type", "type": "string", "x-example": "overall"}, {"description": "Rows per category, 1 to 50. Omit to return every row", "in": "query", "maximum": 50, "minimum": 1, "name": "limit", "type": "integer", "x-example": 5}], "path": "/sofascore/tournament-top-players", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "string"}, {"enum": ["overall", "regular_season", "playoffs"], "in": "query", "name": "type", "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "sofascore-tournament-top-teams": {"id": "sofascore-tournament-top-teams", "method": "GET", "params": [{"description": "Numeric SofaScore unique-tournament (competition) id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "17"}, {"description": "Numeric SofaScore season id", "in": "query", "name": "season", "required": true, "type": "string", "x-example": "96668"}, {"description": "Statistics scope. Defaults to overall", "enum": ["overall", "regular_season", "playoffs"], "in": "query", "name": "type", "type": "string", "x-example": "overall"}, {"description": "Rows per category, 1 to 50. Omit to return every row", "in": "query", "maximum": 50, "minimum": 1, "name": "limit", "type": "integer", "x-example": 5}], "path": "/sofascore/tournament-top-teams", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "string"}, {"enum": ["overall", "regular_season", "playoffs"], "in": "query", "name": "type", "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}}
|
|
23
|
+
JSON
|
|
24
|
+
OPERATION_IDS = JSON.parse(<<~'JSON').freeze
|
|
25
|
+
["sofascore-categories", "sofascore-category-tournaments", "sofascore-event", "sofascore-event-best-players", "sofascore-event-comments", "sofascore-event-graph", "sofascore-event-h2h", "sofascore-event-incidents", "sofascore-event-lineups", "sofascore-event-odds", "sofascore-event-player-statistics", "sofascore-event-shotmap", "sofascore-event-statistics", "sofascore-live-events", "sofascore-manager", "sofascore-manager-events", "sofascore-player", "sofascore-player-season-statistics", "sofascore-player-statistics-seasons", "sofascore-player-transfers", "sofascore-ranking-types", "sofascore-rankings", "sofascore-round-events", "sofascore-scheduled-events", "sofascore-scheduled-tournaments", "sofascore-search", "sofascore-season-events", "sofascore-sports", "sofascore-standings", "sofascore-team", "sofascore-team-events", "sofascore-team-of-the-week", "sofascore-team-of-the-week-periods", "sofascore-team-players", "sofascore-team-season-statistics", "sofascore-team-statistics-seasons", "sofascore-team-transfers", "sofascore-tournament-info", "sofascore-tournament-player-statistics", "sofascore-tournament-rounds", "sofascore-tournament-seasons", "sofascore-tournament-top-players", "sofascore-tournament-top-teams"]
|
|
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-sofascore-ruby/0.2.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
|
+
url = build_url(operation, normalized)
|
|
49
|
+
uri = URI.parse(url)
|
|
50
|
+
request = Net::HTTP::Get.new(uri)
|
|
51
|
+
request["x-api-key"] = @api_key
|
|
52
|
+
request["User-Agent"] = @user_agent
|
|
53
|
+
request["Accept"] = operation["produces"].include?("text/plain") ? "application/json, text/plain" : "application/json"
|
|
54
|
+
begin
|
|
55
|
+
if @transport
|
|
56
|
+
response = @transport.call(url, request.to_hash, @timeout)
|
|
57
|
+
status = Integer(response.fetch(:status) { response.fetch("status") })
|
|
58
|
+
body = response.fetch(:body) { response.fetch("body", "") }
|
|
59
|
+
headers = response.fetch(:headers) { response.fetch("headers", {}) }
|
|
60
|
+
content_type = headers["content-type"] || headers["Content-Type"]
|
|
61
|
+
else
|
|
62
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
63
|
+
http.use_ssl = uri.scheme == "https"
|
|
64
|
+
http.open_timeout = @timeout
|
|
65
|
+
http.read_timeout = @timeout
|
|
66
|
+
response = http.start { |connection| connection.request(request) }
|
|
67
|
+
status = response.code.to_i
|
|
68
|
+
body = response.body
|
|
69
|
+
content_type = response["content-type"]
|
|
70
|
+
end
|
|
71
|
+
rescue Timeout::Error, SocketError, SystemCallError, IOError, EOFError, Net::HTTPBadResponse, Net::ProtocolError, OpenSSL::SSL::SSLError => error
|
|
72
|
+
raise Errors::NetworkError.new("Crawlora request failed: #{error.message}", operation_id: operation_id)
|
|
73
|
+
end
|
|
74
|
+
unless status >= 200 && status < 300
|
|
75
|
+
klass = status >= 500 ? Errors::ServerError : Errors::ClientError
|
|
76
|
+
raise klass.new("Crawlora returned HTTP #{status}", status: status, operation_id: operation_id, body: body)
|
|
77
|
+
end
|
|
78
|
+
parse_response(body, content_type, operation, normalized, response_type)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def close
|
|
82
|
+
@closed = true
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def closed?
|
|
86
|
+
@closed
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def with
|
|
90
|
+
return self unless block_given?
|
|
91
|
+
yield self
|
|
92
|
+
ensure
|
|
93
|
+
close if block_given?
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def self.operation_count
|
|
97
|
+
OPERATION_COUNT
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def self.operation_ids
|
|
101
|
+
OPERATION_IDS
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def self.operations
|
|
105
|
+
OPERATIONS
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
define_method('categories') do |**params|
|
|
109
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
110
|
+
request('sofascore-categories', params, response_type: response_type)
|
|
111
|
+
end
|
|
112
|
+
define_method('category_tournaments') do |**params|
|
|
113
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
114
|
+
request('sofascore-category-tournaments', params, response_type: response_type)
|
|
115
|
+
end
|
|
116
|
+
define_method('event') do |**params|
|
|
117
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
118
|
+
request('sofascore-event', params, response_type: response_type)
|
|
119
|
+
end
|
|
120
|
+
define_method('event_best_players') do |**params|
|
|
121
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
122
|
+
request('sofascore-event-best-players', params, response_type: response_type)
|
|
123
|
+
end
|
|
124
|
+
define_method('event_comments') do |**params|
|
|
125
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
126
|
+
request('sofascore-event-comments', params, response_type: response_type)
|
|
127
|
+
end
|
|
128
|
+
define_method('event_graph') do |**params|
|
|
129
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
130
|
+
request('sofascore-event-graph', params, response_type: response_type)
|
|
131
|
+
end
|
|
132
|
+
define_method('event_h2h') do |**params|
|
|
133
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
134
|
+
request('sofascore-event-h2h', params, response_type: response_type)
|
|
135
|
+
end
|
|
136
|
+
define_method('event_incidents') do |**params|
|
|
137
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
138
|
+
request('sofascore-event-incidents', params, response_type: response_type)
|
|
139
|
+
end
|
|
140
|
+
define_method('event_lineups') do |**params|
|
|
141
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
142
|
+
request('sofascore-event-lineups', params, response_type: response_type)
|
|
143
|
+
end
|
|
144
|
+
define_method('event_odds') do |**params|
|
|
145
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
146
|
+
request('sofascore-event-odds', params, response_type: response_type)
|
|
147
|
+
end
|
|
148
|
+
define_method('event_player_statistics') do |**params|
|
|
149
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
150
|
+
request('sofascore-event-player-statistics', params, response_type: response_type)
|
|
151
|
+
end
|
|
152
|
+
define_method('event_shotmap') do |**params|
|
|
153
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
154
|
+
request('sofascore-event-shotmap', params, response_type: response_type)
|
|
155
|
+
end
|
|
156
|
+
define_method('event_statistics') do |**params|
|
|
157
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
158
|
+
request('sofascore-event-statistics', params, response_type: response_type)
|
|
159
|
+
end
|
|
160
|
+
define_method('live_events') do |**params|
|
|
161
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
162
|
+
request('sofascore-live-events', params, response_type: response_type)
|
|
163
|
+
end
|
|
164
|
+
define_method('manager') do |**params|
|
|
165
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
166
|
+
request('sofascore-manager', params, response_type: response_type)
|
|
167
|
+
end
|
|
168
|
+
define_method('manager_events') do |**params|
|
|
169
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
170
|
+
request('sofascore-manager-events', params, response_type: response_type)
|
|
171
|
+
end
|
|
172
|
+
define_method('player') do |**params|
|
|
173
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
174
|
+
request('sofascore-player', params, response_type: response_type)
|
|
175
|
+
end
|
|
176
|
+
define_method('player_season_statistics') do |**params|
|
|
177
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
178
|
+
request('sofascore-player-season-statistics', params, response_type: response_type)
|
|
179
|
+
end
|
|
180
|
+
define_method('player_statistics_seasons') do |**params|
|
|
181
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
182
|
+
request('sofascore-player-statistics-seasons', params, response_type: response_type)
|
|
183
|
+
end
|
|
184
|
+
define_method('player_transfers') do |**params|
|
|
185
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
186
|
+
request('sofascore-player-transfers', params, response_type: response_type)
|
|
187
|
+
end
|
|
188
|
+
define_method('ranking_types') do |**params|
|
|
189
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
190
|
+
request('sofascore-ranking-types', params, response_type: response_type)
|
|
191
|
+
end
|
|
192
|
+
define_method('rankings') do |**params|
|
|
193
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
194
|
+
request('sofascore-rankings', params, response_type: response_type)
|
|
195
|
+
end
|
|
196
|
+
define_method('round_events') do |**params|
|
|
197
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
198
|
+
request('sofascore-round-events', params, response_type: response_type)
|
|
199
|
+
end
|
|
200
|
+
define_method('scheduled_events') do |**params|
|
|
201
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
202
|
+
request('sofascore-scheduled-events', params, response_type: response_type)
|
|
203
|
+
end
|
|
204
|
+
define_method('scheduled_tournaments') do |**params|
|
|
205
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
206
|
+
request('sofascore-scheduled-tournaments', params, response_type: response_type)
|
|
207
|
+
end
|
|
208
|
+
define_method('search') do |**params|
|
|
209
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
210
|
+
request('sofascore-search', params, response_type: response_type)
|
|
211
|
+
end
|
|
212
|
+
define_method('season_events') do |**params|
|
|
213
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
214
|
+
request('sofascore-season-events', params, response_type: response_type)
|
|
215
|
+
end
|
|
216
|
+
define_method('sports') do |**params|
|
|
217
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
218
|
+
request('sofascore-sports', params, response_type: response_type)
|
|
219
|
+
end
|
|
220
|
+
define_method('standings') do |**params|
|
|
221
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
222
|
+
request('sofascore-standings', params, response_type: response_type)
|
|
223
|
+
end
|
|
224
|
+
define_method('team') do |**params|
|
|
225
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
226
|
+
request('sofascore-team', params, response_type: response_type)
|
|
227
|
+
end
|
|
228
|
+
define_method('team_events') do |**params|
|
|
229
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
230
|
+
request('sofascore-team-events', params, response_type: response_type)
|
|
231
|
+
end
|
|
232
|
+
define_method('team_of_the_week') do |**params|
|
|
233
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
234
|
+
request('sofascore-team-of-the-week', params, response_type: response_type)
|
|
235
|
+
end
|
|
236
|
+
define_method('team_of_the_week_periods') do |**params|
|
|
237
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
238
|
+
request('sofascore-team-of-the-week-periods', params, response_type: response_type)
|
|
239
|
+
end
|
|
240
|
+
define_method('team_players') do |**params|
|
|
241
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
242
|
+
request('sofascore-team-players', params, response_type: response_type)
|
|
243
|
+
end
|
|
244
|
+
define_method('team_season_statistics') do |**params|
|
|
245
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
246
|
+
request('sofascore-team-season-statistics', params, response_type: response_type)
|
|
247
|
+
end
|
|
248
|
+
define_method('team_statistics_seasons') do |**params|
|
|
249
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
250
|
+
request('sofascore-team-statistics-seasons', params, response_type: response_type)
|
|
251
|
+
end
|
|
252
|
+
define_method('team_transfers') do |**params|
|
|
253
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
254
|
+
request('sofascore-team-transfers', params, response_type: response_type)
|
|
255
|
+
end
|
|
256
|
+
define_method('tournament_info') do |**params|
|
|
257
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
258
|
+
request('sofascore-tournament-info', params, response_type: response_type)
|
|
259
|
+
end
|
|
260
|
+
define_method('tournament_player_statistics') do |**params|
|
|
261
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
262
|
+
request('sofascore-tournament-player-statistics', params, response_type: response_type)
|
|
263
|
+
end
|
|
264
|
+
define_method('tournament_rounds') do |**params|
|
|
265
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
266
|
+
request('sofascore-tournament-rounds', params, response_type: response_type)
|
|
267
|
+
end
|
|
268
|
+
define_method('tournament_seasons') do |**params|
|
|
269
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
270
|
+
request('sofascore-tournament-seasons', params, response_type: response_type)
|
|
271
|
+
end
|
|
272
|
+
define_method('tournament_top_players') do |**params|
|
|
273
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
274
|
+
request('sofascore-tournament-top-players', params, response_type: response_type)
|
|
275
|
+
end
|
|
276
|
+
define_method('tournament_top_teams') do |**params|
|
|
277
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
278
|
+
request('sofascore-tournament-top-teams', params, response_type: response_type)
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
private
|
|
282
|
+
|
|
283
|
+
def build_url(operation, params)
|
|
284
|
+
known = operation["params"].map { |param| param["name"] }
|
|
285
|
+
unknown = params.keys - known
|
|
286
|
+
raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
|
|
287
|
+
path = operation["path"].dup
|
|
288
|
+
operation["params"].select { |param| param["in"] == "path" }.each do |param|
|
|
289
|
+
value = params[param["name"]]
|
|
290
|
+
raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
|
|
291
|
+
path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
|
|
292
|
+
end
|
|
293
|
+
pairs = []
|
|
294
|
+
operation["queryParams"].each do |param|
|
|
295
|
+
name = param["name"]
|
|
296
|
+
value = params.key?(name) ? params[name] : param["default"]
|
|
297
|
+
if value.nil?
|
|
298
|
+
raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
|
|
299
|
+
next
|
|
300
|
+
end
|
|
301
|
+
enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
|
|
302
|
+
if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
|
|
303
|
+
raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
|
|
304
|
+
end
|
|
305
|
+
if value.is_a?(Array)
|
|
306
|
+
format = param["collectionFormat"] || "csv"
|
|
307
|
+
if format == "multi"
|
|
308
|
+
value.each { |item| pairs << [name, scalar(item)] }
|
|
309
|
+
else
|
|
310
|
+
separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
|
|
311
|
+
pairs << [name, value.map { |item| scalar(item) }.join(separator)]
|
|
312
|
+
end
|
|
313
|
+
else
|
|
314
|
+
pairs << [name, scalar(value)]
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
|
|
318
|
+
@base_url + path + (query.empty? ? "" : "?" + query)
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
def scalar(value)
|
|
322
|
+
value == true ? "true" : (value == false ? "false" : value.to_s)
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
def percent_encode(value)
|
|
326
|
+
URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def parse_response(body, content_type, operation, params, response_type)
|
|
330
|
+
type = response_type.to_s
|
|
331
|
+
raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
|
|
332
|
+
format = operation["params"].find { |param| param["name"] == "format" }
|
|
333
|
+
text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
|
|
334
|
+
raw_format = params["format"] && text_formats.include?(params["format"].to_s)
|
|
335
|
+
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)
|
|
336
|
+
is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
|
|
337
|
+
return body if type == "text" || raw_format || (type == "auto" && !is_json)
|
|
338
|
+
JSON.parse(body)
|
|
339
|
+
rescue JSON::ParserError => error
|
|
340
|
+
raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
public
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: crawlora-sofascore
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Crawlora
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-10-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Credential-free SofaScore API access through Crawlora's hosted service.
|
|
14
|
+
email:
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- CHANGELOG.md
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.md
|
|
22
|
+
- lib/crawlora/sofascore.rb
|
|
23
|
+
- lib/crawlora/sofascore/client.rb
|
|
24
|
+
- lib/crawlora/sofascore/version.rb
|
|
25
|
+
homepage: https://github.com/Crawlora-org/crawlora-sofascore
|
|
26
|
+
licenses:
|
|
27
|
+
- MIT
|
|
28
|
+
metadata:
|
|
29
|
+
source_code_uri: https://github.com/Crawlora-org/crawlora-sofascore
|
|
30
|
+
rubygems_mfa_required: 'true'
|
|
31
|
+
post_install_message:
|
|
32
|
+
rdoc_options: []
|
|
33
|
+
require_paths:
|
|
34
|
+
- lib
|
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '2.6'
|
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: '0'
|
|
45
|
+
requirements: []
|
|
46
|
+
rubygems_version: 3.4.19
|
|
47
|
+
signing_key:
|
|
48
|
+
specification_version: 4
|
|
49
|
+
summary: SofaScore client for the Crawlora hosted API
|
|
50
|
+
test_files: []
|