crawlora-openligadb 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 +62 -0
- data/lib/crawlora/openligadb/client.rb +284 -0
- data/lib/crawlora/openligadb/version.rb +5 -0
- data/lib/crawlora/openligadb.rb +2 -0
- metadata +53 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1737f96bb8f82c6a7440948fa9ce0a02498e11eb5e6ca92592139dc451d5bea7
|
|
4
|
+
data.tar.gz: 4344c10ee7156d29b57ab055cbb5b51ef3020f5f4a73d5ec1d8acdeaa4b57203
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 32ae27378211c9f03c42e519a5b37e6f8034ef7bad740bed05cf5755171496035bccf4b9780450268a17e10392df7d4e1ec2abcffec98ee26cf810452c2bf307
|
|
7
|
+
data.tar.gz: 4eb701c943f134e9529d9e15d33c38de21dbce0da0c0b488d004f5ec3f3732275a88293dace53d313a819b73758ad02557b585d1c67f61b2e8bd3425dd0d0135
|
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,62 @@
|
|
|
1
|
+
# Crawlora OpenLigaDB API client for Ruby (`crawlora-openligadb`)
|
|
2
|
+
|
|
3
|
+
This Ruby gem calls Crawlora's hosted OpenLigaDB API at `https://api.crawlora.net/api/v1`. It exposes 22 endpoints covering sports and league discovery, fixtures, match results, standings, scorers, and team match history; it does not call or scrape OpenLigaDB directly. Requests require your Crawlora API key and use your account's service plan.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem "crawlora-openligadb"
|
|
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=openligadb-ruby-signup), open the [Crawlora console](https://crawlora.net/app?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=openligadb-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/openligadb"
|
|
16
|
+
|
|
17
|
+
client = Crawlora::Openligadb::Client.new
|
|
18
|
+
result = client.request("openligadb-current-group", JSON.parse("{\"league_shortcut\": \"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 22 API operations.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
client = Crawlora::Openligadb::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 OpenLigaDB API endpoints
|
|
34
|
+
|
|
35
|
+
Browse every route included in this gem. The [endpoint reference](https://github.com/Crawlora-org/crawlora-openligadb/blob/main/docs/usage.md) includes parameter and response details.
|
|
36
|
+
|
|
37
|
+
| Method | Endpoint | API operation | Description |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| `GET` | `/openligadb/current-group` | `openligadb-current-group` | Get the current league matchday |
|
|
40
|
+
| `GET` | `/openligadb/current-matchday` | `openligadb-current-matchday` | Get current matchday fixtures and results |
|
|
41
|
+
| `GET` | `/openligadb/goal-getters` | `openligadb-goal-getters` | List league season goal-getters |
|
|
42
|
+
| `GET` | `/openligadb/groups` | `openligadb-groups` | List league matchdays and rounds |
|
|
43
|
+
| `GET` | `/openligadb/last-changed` | `openligadb-last-changed` | Get a matchday's last update time |
|
|
44
|
+
| `GET` | `/openligadb/last-match` | `openligadb-last-match` | Get a league's last match |
|
|
45
|
+
| `GET` | `/openligadb/last-team-match` | `openligadb-last-team-match` | Get a team's last match in a league |
|
|
46
|
+
| `GET` | `/openligadb/league-team-matches` | `openligadb-league-team-matches` | Find a team's matches in one league season |
|
|
47
|
+
| `GET` | `/openligadb/leagues` | `openligadb-leagues` | List OpenLigaDB league seasons |
|
|
48
|
+
| `GET` | `/openligadb/match` | `openligadb-match` | Get one OpenLigaDB match |
|
|
49
|
+
| `GET` | `/openligadb/matchday-matches` | `openligadb-matchday-matches` | List one league matchday |
|
|
50
|
+
| `GET` | `/openligadb/matches` | `openligadb-league-matches` | List a league season's matches |
|
|
51
|
+
| `GET` | `/openligadb/matches-by-team` | `openligadb-matches-by-team` | Find recent and upcoming matches by team name |
|
|
52
|
+
| `GET` | `/openligadb/matches-by-team-id` | `openligadb-matches-by-team-id` | Find recent and upcoming matches by team id |
|
|
53
|
+
| `GET` | `/openligadb/next-match` | `openligadb-next-match` | Get a league's next match |
|
|
54
|
+
| `GET` | `/openligadb/next-team-match` | `openligadb-next-team-match` | Get a team's next match in a league |
|
|
55
|
+
| `GET` | `/openligadb/result-infos` | `openligadb-result-infos` | List result types configured for a league |
|
|
56
|
+
| `GET` | `/openligadb/result-types` | `openligadb-result-types` | List global result types |
|
|
57
|
+
| `GET` | `/openligadb/sports` | `openligadb-sports` | List OpenLigaDB sports |
|
|
58
|
+
| `GET` | `/openligadb/table` | `openligadb-table` | Get a league season's table |
|
|
59
|
+
| `GET` | `/openligadb/team-pair-matches` | `openligadb-team-pair-matches` | List matches between two teams |
|
|
60
|
+
| `GET` | `/openligadb/teams` | `openligadb-teams` | List teams in a league season |
|
|
61
|
+
|
|
62
|
+
See [Crawlora](https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=openligadb-ruby-homepage), the [API documentation](https://crawlora.net/docs?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=openligadb-ruby-api-docs), and [the package repository](https://github.com/Crawlora-org/crawlora-openligadb) for account setup, the API operation reference, and release history.
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Crawlora
|
|
6
|
+
module Openligadb
|
|
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
|
+
{"openligadb-current-group": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-current-group", "method": "GET", "params": [{"description": "Exact shortcut from openligadb-leagues", "in": "query", "name": "league_shortcut", "required": true, "type": "string", "x-example": "bl1"}], "path": "/openligadb/current-group", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_shortcut", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "openligadb-current-matchday": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-current-matchday", "method": "GET", "params": [{"description": "Exact shortcut from openligadb-leagues", "in": "query", "name": "league_shortcut", "required": true, "type": "string", "x-example": "bl1"}], "path": "/openligadb/current-matchday", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_shortcut", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "openligadb-goal-getters": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-goal-getters", "method": "GET", "params": [{"description": "Exact shortcut from openligadb-leagues", "in": "query", "name": "league_shortcut", "required": true, "type": "string", "x-example": "bl1"}, {"description": "Season starting year", "in": "query", "name": "season", "required": true, "type": "integer", "x-example": 2026}], "path": "/openligadb/goal-getters", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_shortcut", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "openligadb-groups": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-groups", "method": "GET", "params": [{"description": "Exact shortcut from openligadb-leagues", "in": "query", "name": "league_shortcut", "required": true, "type": "string", "x-example": "bl1"}, {"description": "Season starting year", "in": "query", "name": "season", "required": true, "type": "integer", "x-example": 2026}], "path": "/openligadb/groups", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_shortcut", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "openligadb-last-changed": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-last-changed", "method": "GET", "params": [{"description": "Exact shortcut from openligadb-leagues", "in": "query", "name": "league_shortcut", "required": true, "type": "string", "x-example": "bl1"}, {"description": "Season starting year", "in": "query", "name": "season", "required": true, "type": "integer", "x-example": 2026}, {"description": "Matchday or round id from openligadb-groups", "in": "query", "name": "group_order_id", "required": true, "type": "integer", "x-example": 8}], "path": "/openligadb/last-changed", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_shortcut", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "integer"}, {"in": "query", "name": "group_order_id", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "openligadb-last-match": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-last-match", "method": "GET", "params": [{"description": "Exact shortcut from openligadb-leagues", "in": "query", "name": "league_shortcut", "required": true, "type": "string", "x-example": "bl1"}], "path": "/openligadb/last-match", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_shortcut", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "openligadb-last-team-match": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-last-team-match", "method": "GET", "params": [{"description": "OpenLigaDB league id from openligadb_leagues", "format": "int64", "in": "query", "name": "league_id", "required": true, "type": "integer", "x-example": 4937}, {"description": "OpenLigaDB team id from openligadb_teams", "format": "int64", "in": "query", "name": "team_id", "required": true, "type": "integer", "x-example": 40}], "path": "/openligadb/last-team-match", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_id", "required": true, "type": "integer"}, {"in": "query", "name": "team_id", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "openligadb-league-matches": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-league-matches", "method": "GET", "params": [{"description": "Exact shortcut from openligadb-leagues", "in": "query", "name": "league_shortcut", "required": true, "type": "string", "x-example": "bl1"}, {"description": "Season starting year", "in": "query", "name": "season", "required": true, "type": "integer", "x-example": 2026}], "path": "/openligadb/matches", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_shortcut", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "openligadb-league-team-matches": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-league-team-matches", "method": "GET", "params": [{"description": "Exact shortcut from openligadb-leagues", "in": "query", "name": "league_shortcut", "required": true, "type": "string", "x-example": "bl1"}, {"description": "Season starting year", "in": "query", "name": "season", "required": true, "type": "integer", "x-example": 2026}, {"description": "Partial team-name text; numeric-only values are not accepted", "in": "query", "name": "team_filter", "required": true, "type": "string", "x-example": "Bayern"}], "path": "/openligadb/league-team-matches", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_shortcut", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "integer"}, {"in": "query", "name": "team_filter", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "openligadb-leagues": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-leagues", "method": "GET", "params": [{"description": "Optional season starting year, e.g. 2026 for 2026/27", "in": "query", "name": "season", "type": "integer"}], "path": "/openligadb/leagues", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "season", "type": "integer"}], "security": ["ApiKeyAuth"]}, "openligadb-match": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-match", "method": "GET", "params": [{"description": "OpenLigaDB match id", "format": "int64", "in": "query", "name": "match_id", "required": true, "type": "integer", "x-example": 83224}], "path": "/openligadb/match", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "match_id", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "openligadb-matchday-matches": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-matchday-matches", "method": "GET", "params": [{"description": "Exact shortcut from openligadb-leagues", "in": "query", "name": "league_shortcut", "required": true, "type": "string", "x-example": "bl1"}, {"description": "Season starting year", "in": "query", "name": "season", "required": true, "type": "integer", "x-example": 2026}, {"description": "Matchday or round id from openligadb-groups", "in": "query", "name": "group_order_id", "required": true, "type": "integer", "x-example": 8}], "path": "/openligadb/matchday-matches", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_shortcut", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "integer"}, {"in": "query", "name": "group_order_id", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "openligadb-matches-by-team": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-matches-by-team", "method": "GET", "params": [{"description": "Partial team-name fragment", "in": "query", "name": "team_filter", "required": true, "type": "string", "x-example": "Bayern"}, {"description": "Number of weeks before today to include; zero is allowed", "format": "int64", "in": "query", "name": "weeks_past", "required": true, "type": "integer", "x-example": 1}, {"description": "Number of weeks after today to include; zero is allowed", "format": "int64", "in": "query", "name": "weeks_future", "required": true, "type": "integer", "x-example": 1}], "path": "/openligadb/matches-by-team", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "team_filter", "required": true, "type": "string"}, {"in": "query", "name": "weeks_past", "required": true, "type": "integer"}, {"in": "query", "name": "weeks_future", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "openligadb-matches-by-team-id": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-matches-by-team-id", "method": "GET", "params": [{"description": "OpenLigaDB team id from openligadb_teams", "format": "int64", "in": "query", "name": "team_id", "required": true, "type": "integer", "x-example": 40}, {"description": "Number of weeks before today to include; zero is allowed", "format": "int64", "in": "query", "name": "weeks_past", "required": true, "type": "integer", "x-example": 1}, {"description": "Number of weeks after today to include; zero is allowed", "format": "int64", "in": "query", "name": "weeks_future", "required": true, "type": "integer", "x-example": 1}], "path": "/openligadb/matches-by-team-id", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "team_id", "required": true, "type": "integer"}, {"in": "query", "name": "weeks_past", "required": true, "type": "integer"}, {"in": "query", "name": "weeks_future", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "openligadb-next-match": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-next-match", "method": "GET", "params": [{"description": "Exact shortcut from openligadb-leagues", "in": "query", "name": "league_shortcut", "required": true, "type": "string", "x-example": "bl1"}], "path": "/openligadb/next-match", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_shortcut", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "openligadb-next-team-match": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-next-team-match", "method": "GET", "params": [{"description": "OpenLigaDB league id from openligadb_leagues", "format": "int64", "in": "query", "name": "league_id", "required": true, "type": "integer", "x-example": 4937}, {"description": "OpenLigaDB team id from openligadb_teams", "format": "int64", "in": "query", "name": "team_id", "required": true, "type": "integer", "x-example": 40}], "path": "/openligadb/next-team-match", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_id", "required": true, "type": "integer"}, {"in": "query", "name": "team_id", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "openligadb-result-infos": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-result-infos", "method": "GET", "params": [{"description": "OpenLigaDB league id from openligadb-leagues", "format": "int64", "in": "query", "name": "league_id", "required": true, "type": "integer", "x-example": 4937}], "path": "/openligadb/result-infos", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_id", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "openligadb-result-types": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-result-types", "method": "GET", "params": [], "path": "/openligadb/result-types", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "openligadb-sports": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-sports", "method": "GET", "params": [], "path": "/openligadb/sports", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "openligadb-table": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-table", "method": "GET", "params": [{"description": "Exact shortcut from openligadb-leagues", "in": "query", "name": "league_shortcut", "required": true, "type": "string", "x-example": "bl1"}, {"description": "Season starting year", "in": "query", "name": "season", "required": true, "type": "integer", "x-example": 2026}], "path": "/openligadb/table", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_shortcut", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "openligadb-team-pair-matches": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-team-pair-matches", "method": "GET", "params": [{"description": "First OpenLigaDB team id", "format": "int64", "in": "query", "name": "team_id_1", "required": true, "type": "integer", "x-example": 40}, {"description": "Second OpenLigaDB team id", "format": "int64", "in": "query", "name": "team_id_2", "required": true, "type": "integer", "x-example": 7}], "path": "/openligadb/team-pair-matches", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "team_id_1", "required": true, "type": "integer"}, {"in": "query", "name": "team_id_2", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "openligadb-teams": {"bodyParam": null, "bodyRequired": false, "id": "openligadb-teams", "method": "GET", "params": [{"description": "Exact shortcut from openligadb-leagues", "in": "query", "name": "league_shortcut", "required": true, "type": "string", "x-example": "bl1"}, {"description": "Season starting year", "in": "query", "name": "season", "required": true, "type": "integer", "x-example": 2026}], "path": "/openligadb/teams", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_shortcut", "required": true, "type": "string"}, {"in": "query", "name": "season", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}}
|
|
23
|
+
JSON
|
|
24
|
+
OPERATION_IDS = JSON.parse(<<~'JSON').freeze
|
|
25
|
+
["openligadb-current-group", "openligadb-current-matchday", "openligadb-goal-getters", "openligadb-groups", "openligadb-last-changed", "openligadb-last-match", "openligadb-last-team-match", "openligadb-league-matches", "openligadb-league-team-matches", "openligadb-leagues", "openligadb-match", "openligadb-matchday-matches", "openligadb-matches-by-team", "openligadb-matches-by-team-id", "openligadb-next-match", "openligadb-next-team-match", "openligadb-result-infos", "openligadb-result-types", "openligadb-sports", "openligadb-table", "openligadb-team-pair-matches", "openligadb-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-openligadb-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('current_group') do |**params|
|
|
118
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
119
|
+
request('openligadb-current-group', params, response_type: response_type)
|
|
120
|
+
end
|
|
121
|
+
define_method('current_matchday') do |**params|
|
|
122
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
123
|
+
request('openligadb-current-matchday', params, response_type: response_type)
|
|
124
|
+
end
|
|
125
|
+
define_method('goal_getters') do |**params|
|
|
126
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
127
|
+
request('openligadb-goal-getters', params, response_type: response_type)
|
|
128
|
+
end
|
|
129
|
+
define_method('groups') do |**params|
|
|
130
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
131
|
+
request('openligadb-groups', params, response_type: response_type)
|
|
132
|
+
end
|
|
133
|
+
define_method('last_changed') do |**params|
|
|
134
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
135
|
+
request('openligadb-last-changed', params, response_type: response_type)
|
|
136
|
+
end
|
|
137
|
+
define_method('last_match') do |**params|
|
|
138
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
139
|
+
request('openligadb-last-match', params, response_type: response_type)
|
|
140
|
+
end
|
|
141
|
+
define_method('last_team_match') do |**params|
|
|
142
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
143
|
+
request('openligadb-last-team-match', params, response_type: response_type)
|
|
144
|
+
end
|
|
145
|
+
define_method('league_team_matches') do |**params|
|
|
146
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
147
|
+
request('openligadb-league-team-matches', params, response_type: response_type)
|
|
148
|
+
end
|
|
149
|
+
define_method('leagues') do |**params|
|
|
150
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
151
|
+
request('openligadb-leagues', params, response_type: response_type)
|
|
152
|
+
end
|
|
153
|
+
define_method('match') do |**params|
|
|
154
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
155
|
+
request('openligadb-match', params, response_type: response_type)
|
|
156
|
+
end
|
|
157
|
+
define_method('matchday_matches') do |**params|
|
|
158
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
159
|
+
request('openligadb-matchday-matches', params, response_type: response_type)
|
|
160
|
+
end
|
|
161
|
+
define_method('league_matches') do |**params|
|
|
162
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
163
|
+
request('openligadb-league-matches', params, response_type: response_type)
|
|
164
|
+
end
|
|
165
|
+
define_method('matches_by_team') do |**params|
|
|
166
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
167
|
+
request('openligadb-matches-by-team', params, response_type: response_type)
|
|
168
|
+
end
|
|
169
|
+
define_method('matches_by_team_id') do |**params|
|
|
170
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
171
|
+
request('openligadb-matches-by-team-id', params, response_type: response_type)
|
|
172
|
+
end
|
|
173
|
+
define_method('next_match') do |**params|
|
|
174
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
175
|
+
request('openligadb-next-match', params, response_type: response_type)
|
|
176
|
+
end
|
|
177
|
+
define_method('next_team_match') do |**params|
|
|
178
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
179
|
+
request('openligadb-next-team-match', params, response_type: response_type)
|
|
180
|
+
end
|
|
181
|
+
define_method('result_infos') do |**params|
|
|
182
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
183
|
+
request('openligadb-result-infos', params, response_type: response_type)
|
|
184
|
+
end
|
|
185
|
+
define_method('result_types') do |**params|
|
|
186
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
187
|
+
request('openligadb-result-types', params, response_type: response_type)
|
|
188
|
+
end
|
|
189
|
+
define_method('sports') do |**params|
|
|
190
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
191
|
+
request('openligadb-sports', params, response_type: response_type)
|
|
192
|
+
end
|
|
193
|
+
define_method('table') do |**params|
|
|
194
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
195
|
+
request('openligadb-table', params, response_type: response_type)
|
|
196
|
+
end
|
|
197
|
+
define_method('team_pair_matches') do |**params|
|
|
198
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
199
|
+
request('openligadb-team-pair-matches', params, response_type: response_type)
|
|
200
|
+
end
|
|
201
|
+
define_method('teams') do |**params|
|
|
202
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
203
|
+
request('openligadb-teams', params, response_type: response_type)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
private
|
|
207
|
+
|
|
208
|
+
# POST operations take their JSON body under the body parameter name or "body".
|
|
209
|
+
def request_body(operation, params)
|
|
210
|
+
name = operation["bodyParam"]
|
|
211
|
+
return nil if name.nil?
|
|
212
|
+
value = params.key?(name) ? params[name] : params["body"]
|
|
213
|
+
if value.nil?
|
|
214
|
+
raise Errors::ClientError.new("missing request body: #{name}", operation_id: operation["id"]) if operation["bodyRequired"]
|
|
215
|
+
return nil
|
|
216
|
+
end
|
|
217
|
+
value.is_a?(String) ? value : JSON.generate(value)
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def build_url(operation, params)
|
|
221
|
+
known = operation["params"].map { |param| param["name"] }
|
|
222
|
+
known << "body" if operation["bodyParam"]
|
|
223
|
+
unknown = params.keys - known
|
|
224
|
+
raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
|
|
225
|
+
path = operation["path"].dup
|
|
226
|
+
operation["params"].select { |param| param["in"] == "path" }.each do |param|
|
|
227
|
+
value = params[param["name"]]
|
|
228
|
+
raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
|
|
229
|
+
path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
|
|
230
|
+
end
|
|
231
|
+
pairs = []
|
|
232
|
+
operation["queryParams"].each do |param|
|
|
233
|
+
name = param["name"]
|
|
234
|
+
value = params.key?(name) ? params[name] : param["default"]
|
|
235
|
+
if value.nil?
|
|
236
|
+
raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
|
|
237
|
+
next
|
|
238
|
+
end
|
|
239
|
+
enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
|
|
240
|
+
if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
|
|
241
|
+
raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
|
|
242
|
+
end
|
|
243
|
+
if value.is_a?(Array)
|
|
244
|
+
format = param["collectionFormat"] || "csv"
|
|
245
|
+
if format == "multi"
|
|
246
|
+
value.each { |item| pairs << [name, scalar(item)] }
|
|
247
|
+
else
|
|
248
|
+
separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
|
|
249
|
+
pairs << [name, value.map { |item| scalar(item) }.join(separator)]
|
|
250
|
+
end
|
|
251
|
+
else
|
|
252
|
+
pairs << [name, scalar(value)]
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
|
|
256
|
+
@base_url + path + (query.empty? ? "" : "?" + query)
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def scalar(value)
|
|
260
|
+
value == true ? "true" : (value == false ? "false" : value.to_s)
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def percent_encode(value)
|
|
264
|
+
URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
def parse_response(body, content_type, operation, params, response_type)
|
|
268
|
+
type = response_type.to_s
|
|
269
|
+
raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
|
|
270
|
+
format = operation["params"].find { |param| param["name"] == "format" }
|
|
271
|
+
text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
|
|
272
|
+
raw_format = params["format"] && text_formats.include?(params["format"].to_s)
|
|
273
|
+
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)
|
|
274
|
+
is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
|
|
275
|
+
return body if type == "text" || raw_format || (type == "auto" && !is_json)
|
|
276
|
+
JSON.parse(body)
|
|
277
|
+
rescue JSON::ParserError => error
|
|
278
|
+
raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
public
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: crawlora-openligadb
|
|
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-13 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Ruby client for Crawlora's hosted OpenLigaDB API. Covers sports and league
|
|
14
|
+
discovery, fixtures, match results, standings, scorers, and team match history across
|
|
15
|
+
22 endpoints.
|
|
16
|
+
email:
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- CHANGELOG.md
|
|
22
|
+
- LICENSE
|
|
23
|
+
- README.md
|
|
24
|
+
- lib/crawlora/openligadb.rb
|
|
25
|
+
- lib/crawlora/openligadb/client.rb
|
|
26
|
+
- lib/crawlora/openligadb/version.rb
|
|
27
|
+
homepage: https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=openligadb-ruby-homepage
|
|
28
|
+
licenses:
|
|
29
|
+
- MIT
|
|
30
|
+
metadata:
|
|
31
|
+
source_code_uri: https://github.com/Crawlora-org/crawlora-openligadb
|
|
32
|
+
documentation_uri: https://github.com/Crawlora-org/crawlora-openligadb/blob/main/ruby/README.md
|
|
33
|
+
rubygems_mfa_required: 'true'
|
|
34
|
+
post_install_message:
|
|
35
|
+
rdoc_options: []
|
|
36
|
+
require_paths:
|
|
37
|
+
- lib
|
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '2.6'
|
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
requirements: []
|
|
49
|
+
rubygems_version: 3.4.19
|
|
50
|
+
signing_key:
|
|
51
|
+
specification_version: 4
|
|
52
|
+
summary: OpenLigaDB API client for Crawlora (22 endpoints)
|
|
53
|
+
test_files: []
|