crawlora-flashscore 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/flashscore/client.rb +326 -0
- data/lib/crawlora/flashscore/version.rb +5 -0
- data/lib/crawlora/flashscore.rb +2 -0
- metadata +50 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6ed083c14af715544dfb70acf4f157b9e69d6de492ed410570a9b2193ebeccb3
|
|
4
|
+
data.tar.gz: 8791f6247ca96684b496587bc9ef0954a7220a18f30e4175a8f8138d2b0efb98
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6fa259086e0d32cc5e4920552de5ca64037d663184a0e3618ffcde87a34e99a861dfdf22971b4cba8ce87de92fb6bee5df23c21b1d76c3e4942e4bf2f82fb039
|
|
7
|
+
data.tar.gz: 4ce7ddfd95e84d8505d182aa9cfe1470cca9440b3f465fdef2477509a9fc63da22753ee8f8fe8a218bc69626373605db17a8adc2a16f8a562c576ec13a165562
|
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 Flashscore Ruby client
|
|
2
|
+
|
|
3
|
+
This gem calls the Crawlora hosted API at `https://api.crawlora.net/api/v1`. It does not call or scrape Flashscore directly. Requests require your Crawlora API key and use your account's service plan.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem "crawlora-flashscore"
|
|
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/flashscore"
|
|
16
|
+
|
|
17
|
+
client = Crawlora::Flashscore::Client.new
|
|
18
|
+
result = client.request("flashscore-search", JSON.parse("{\"q\": \"football\"}"))
|
|
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 38 operations and follows contract revision `sha256:fcaf7e58d82dcbe73e54cddcffc79511b5d01e2c25d511531656862dfe91fb3e`.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
client = Crawlora::Flashscore::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:fcaf7e58d82dcbe73e54cddcffc79511b5d01e2c25d511531656862dfe91fb3e` and contains 38 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-flashscore) for account setup, the generated operation reference, and release history.
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Crawlora
|
|
6
|
+
module Flashscore
|
|
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
|
+
{"flashscore-calendar": {"id": "flashscore-calendar", "method": "GET", "params": [{"description": "Calendar category from flashscore-calendar-categories", "enum": ["tennis-atp", "tennis-wta", "golf-pga", "golf-dp-world", "badminton-bwf", "motorsport-f1"], "in": "query", "name": "category", "required": true, "type": "string", "x-example": "tennis-atp"}], "path": "/flashscore/calendar", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["tennis-atp", "tennis-wta", "golf-pga", "golf-dp-world", "badminton-bwf", "motorsport-f1"], "in": "query", "name": "category", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-calendar-categories": {"id": "flashscore-calendar-categories", "method": "GET", "params": [], "path": "/flashscore/calendar-categories", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "flashscore-competitions": {"id": "flashscore-competitions", "method": "GET", "params": [{"description": "Sport key", "enum": ["football", "tennis", "basketball", "hockey", "golf", "formula-1", "baseball", "snooker", "american-football", "aussie-rules", "badminton", "bandy", "beach-soccer", "beach-volleyball", "boxing", "cricket", "cycling", "darts", "esports", "field-hockey", "floorball", "futsal", "handball", "horse-racing", "kabaddi", "mma", "motorsport", "netball", "pesapallo", "rugby-league", "rugby-union", "table-tennis", "volleyball", "water-polo", "winter-sports"], "in": "query", "name": "sport", "required": true, "type": "string", "x-example": "football"}, {"description": "Days from today; -7 to 7; defaults to 0", "in": "query", "maximum": 7, "minimum": -7, "name": "day_offset", "type": "integer", "x-example": 0}], "path": "/flashscore/competitions", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["football", "tennis", "basketball", "hockey", "golf", "formula-1", "baseball", "snooker", "american-football", "aussie-rules", "badminton", "bandy", "beach-soccer", "beach-volleyball", "boxing", "cricket", "cycling", "darts", "esports", "field-hockey", "floorball", "futsal", "handball", "horse-racing", "kabaddi", "mma", "motorsport", "netball", "pesapallo", "rugby-league", "rugby-union", "table-tennis", "volleyball", "water-polo", "winter-sports"], "in": "query", "name": "sport", "required": true, "type": "string"}, {"in": "query", "name": "day_offset", "type": "integer"}], "security": ["ApiKeyAuth"]}, "flashscore-match-h2h": {"id": "flashscore-match-h2h", "method": "GET", "params": [{"description": "Eight-character Flashscore match id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "xtmHKGT0"}], "path": "/flashscore/match-h2h", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-match-highlights": {"id": "flashscore-match-highlights", "method": "GET", "params": [{"description": "Eight-character Flashscore match id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "j52jHsN8"}], "path": "/flashscore/match-highlights", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-match-info": {"id": "flashscore-match-info", "method": "GET", "params": [{"description": "Eight-character Flashscore match id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "xtmHKGT0"}], "path": "/flashscore/match-info", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-match-lineups": {"id": "flashscore-match-lineups", "method": "GET", "params": [{"description": "Eight-character Flashscore match id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "j52jHsN8"}], "path": "/flashscore/match-lineups", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-match-missing-players": {"id": "flashscore-match-missing-players", "method": "GET", "params": [{"description": "Eight-character Flashscore match id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "f75igXFG"}], "path": "/flashscore/match-missing-players", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-match-news": {"id": "flashscore-match-news", "method": "GET", "params": [{"description": "Eight-character Flashscore match id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "xtmHKGT0"}], "path": "/flashscore/match-news", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-match-odds": {"id": "flashscore-match-odds", "method": "GET", "params": [{"description": "Eight-character Flashscore match id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "p0aFxkkn"}, {"description": "Viewer market country code from flashscore-odds-geos; defaults to GB", "enum": ["AE", "AL", "AM", "AO", "AR", "AT", "AU", "AZ", "BA", "BD", "BE", "BG", "BO", "BR", "BY", "CA", "CH", "CI", "CL", "CM", "CN", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "DZ", "EC", "EE", "EG", "ES", "ET", "FI", "FR", "GB", "GE", "GH", "GR", "GT", "HK", "HN", "HR", "HU", "ID", "IE", "IL", "IN", "IQ", "IR", "IS", "IT", "JO", "JP", "KE", "KG", "KH", "KR", "KW", "KZ", "LA", "LB", "LK", "LT", "LU", "LV", "LY", "MA", "MD", "ME", "MK", "MM", "MN", "MT", "MX", "MY", "NG", "NI", "NL", "NO", "NP", "NZ", "PA", "PE", "PH", "PK", "PL", "PT", "PY", "QA", "RO", "RS", "RU", "SA", "SD", "SE", "SG", "SI", "SK", "SN", "SV", "TH", "TN", "TR", "TW", "TZ", "UA", "UG", "US", "UY", "UZ", "VE", "VN", "XK", "ZA", "ZM", "ZW"], "in": "query", "name": "geo", "type": "string", "x-example": "GB"}, {"description": "US state (with geo US) or Canadian province (with geo CA) code from flashscore-odds-geos; rejected with any other geo", "enum": ["AB", "AK", "AL", "AR", "AZ", "BC", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MB", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NB", "NC", "ND", "NE", "NH", "NJ", "NL", "NM", "NS", "NT", "NU", "NV", "NY", "OH", "OK", "ON", "OR", "PA", "PE", "QC", "RI", "SC", "SD", "SK", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", "WY", "YT"], "in": "query", "name": "subdivision", "type": "string", "x-example": "NJ"}, {"description": "Optional filter to one betting type", "enum": ["HOME_DRAW_AWAY", "HOME_AWAY", "DRAW_NO_BET", "DOUBLE_CHANCE", "ASIAN_HANDICAP", "EUROPEAN_HANDICAP", "OVER_UNDER", "BOTH_TEAMS_TO_SCORE", "CORRECT_SCORE", "HALF_FULL_TIME", "ODD_OR_EVEN", "TO_QUALIFY", "NEXT_GOAL", "TOP_POSITION_MERGED", "TO_WIN_AND_TOP_POSITION", "WIN_EACH_WAY"], "in": "query", "name": "betting_type", "type": "string", "x-example": "HOME_DRAW_AWAY"}, {"description": "Optional filter to one scope", "enum": ["FULL_TIME", "FULL_TIME_OVER_TIME", "FIRST_HALF", "SECOND_HALF", "FIRST_PERIOD", "FIRST_QUARTER", "FIRST_SET", "SECOND_SET"], "in": "query", "name": "scope", "type": "string", "x-example": "FULL_TIME"}], "path": "/flashscore/match-odds", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"enum": ["AE", "AL", "AM", "AO", "AR", "AT", "AU", "AZ", "BA", "BD", "BE", "BG", "BO", "BR", "BY", "CA", "CH", "CI", "CL", "CM", "CN", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "DZ", "EC", "EE", "EG", "ES", "ET", "FI", "FR", "GB", "GE", "GH", "GR", "GT", "HK", "HN", "HR", "HU", "ID", "IE", "IL", "IN", "IQ", "IR", "IS", "IT", "JO", "JP", "KE", "KG", "KH", "KR", "KW", "KZ", "LA", "LB", "LK", "LT", "LU", "LV", "LY", "MA", "MD", "ME", "MK", "MM", "MN", "MT", "MX", "MY", "NG", "NI", "NL", "NO", "NP", "NZ", "PA", "PE", "PH", "PK", "PL", "PT", "PY", "QA", "RO", "RS", "RU", "SA", "SD", "SE", "SG", "SI", "SK", "SN", "SV", "TH", "TN", "TR", "TW", "TZ", "UA", "UG", "US", "UY", "UZ", "VE", "VN", "XK", "ZA", "ZM", "ZW"], "in": "query", "name": "geo", "type": "string"}, {"enum": ["AB", "AK", "AL", "AR", "AZ", "BC", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MB", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NB", "NC", "ND", "NE", "NH", "NJ", "NL", "NM", "NS", "NT", "NU", "NV", "NY", "OH", "OK", "ON", "OR", "PA", "PE", "QC", "RI", "SC", "SD", "SK", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", "WY", "YT"], "in": "query", "name": "subdivision", "type": "string"}, {"enum": ["HOME_DRAW_AWAY", "HOME_AWAY", "DRAW_NO_BET", "DOUBLE_CHANCE", "ASIAN_HANDICAP", "EUROPEAN_HANDICAP", "OVER_UNDER", "BOTH_TEAMS_TO_SCORE", "CORRECT_SCORE", "HALF_FULL_TIME", "ODD_OR_EVEN", "TO_QUALIFY", "NEXT_GOAL", "TOP_POSITION_MERGED", "TO_WIN_AND_TOP_POSITION", "WIN_EACH_WAY"], "in": "query", "name": "betting_type", "type": "string"}, {"enum": ["FULL_TIME", "FULL_TIME_OVER_TIME", "FIRST_HALF", "SECOND_HALF", "FIRST_PERIOD", "FIRST_QUARTER", "FIRST_SET", "SECOND_SET"], "in": "query", "name": "scope", "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-match-predicted-lineups": {"id": "flashscore-match-predicted-lineups", "method": "GET", "params": [{"description": "Eight-character Flashscore match id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "f75igXFG"}], "path": "/flashscore/match-predicted-lineups", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-match-standings": {"id": "flashscore-match-standings", "method": "GET", "params": [{"description": "Eight-character Flashscore match id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "xtmHKGT0"}, {"description": "Standings/table view; defaults to overall", "enum": ["overall", "home", "away", "form_overall", "overunder_overall", "form_home", "form_away", "top_scorers", "htft_overall", "htft_home", "htft_away", "live_overall", "overunder_home", "overunder_away"], "in": "query", "name": "view", "type": "string", "x-example": "overall"}], "path": "/flashscore/match-standings", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"enum": ["overall", "home", "away", "form_overall", "overunder_overall", "form_home", "form_away", "top_scorers", "htft_overall", "htft_home", "htft_away", "live_overall", "overunder_home", "overunder_away"], "in": "query", "name": "view", "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-match-stats": {"id": "flashscore-match-stats", "method": "GET", "params": [{"description": "Eight-character Flashscore match id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "xtmHKGT0"}], "path": "/flashscore/match-stats", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-match-tv": {"id": "flashscore-match-tv", "method": "GET", "params": [{"description": "Eight-character Flashscore match id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "p0aFxkkn"}, {"description": "Viewer market country code from flashscore-odds-geos; defaults to GB", "enum": ["AE", "AL", "AM", "AO", "AR", "AT", "AU", "AZ", "BA", "BD", "BE", "BG", "BO", "BR", "BY", "CA", "CH", "CI", "CL", "CM", "CN", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "DZ", "EC", "EE", "EG", "ES", "ET", "FI", "FR", "GB", "GE", "GH", "GR", "GT", "HK", "HN", "HR", "HU", "ID", "IE", "IL", "IN", "IQ", "IR", "IS", "IT", "JO", "JP", "KE", "KG", "KH", "KR", "KW", "KZ", "LA", "LB", "LK", "LT", "LU", "LV", "LY", "MA", "MD", "ME", "MK", "MM", "MN", "MT", "MX", "MY", "NG", "NI", "NL", "NO", "NP", "NZ", "PA", "PE", "PH", "PK", "PL", "PT", "PY", "QA", "RO", "RS", "RU", "SA", "SD", "SE", "SG", "SI", "SK", "SN", "SV", "TH", "TN", "TR", "TW", "TZ", "UA", "UG", "US", "UY", "UZ", "VE", "VN", "XK", "ZA", "ZM", "ZW"], "in": "query", "name": "geo", "type": "string", "x-example": "GB"}], "path": "/flashscore/match-tv", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"enum": ["AE", "AL", "AM", "AO", "AR", "AT", "AU", "AZ", "BA", "BD", "BE", "BG", "BO", "BR", "BY", "CA", "CH", "CI", "CL", "CM", "CN", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "DZ", "EC", "EE", "EG", "ES", "ET", "FI", "FR", "GB", "GE", "GH", "GR", "GT", "HK", "HN", "HR", "HU", "ID", "IE", "IL", "IN", "IQ", "IR", "IS", "IT", "JO", "JP", "KE", "KG", "KH", "KR", "KW", "KZ", "LA", "LB", "LK", "LT", "LU", "LV", "LY", "MA", "MD", "ME", "MK", "MM", "MN", "MT", "MX", "MY", "NG", "NI", "NL", "NO", "NP", "NZ", "PA", "PE", "PH", "PK", "PL", "PT", "PY", "QA", "RO", "RS", "RU", "SA", "SD", "SE", "SG", "SI", "SK", "SN", "SV", "TH", "TN", "TR", "TW", "TZ", "UA", "UG", "US", "UY", "UZ", "VE", "VN", "XK", "ZA", "ZM", "ZW"], "in": "query", "name": "geo", "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-navigation": {"id": "flashscore-navigation", "method": "GET", "params": [{"description": "Relative Flashscore navigation path; defaults to /. Use a path returned by flashscore-sports or flashscore-navigation.", "in": "query", "name": "path", "type": "string", "x-example": "/basketball/usa/"}], "path": "/flashscore/navigation", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "path", "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-news": {"id": "flashscore-news", "method": "GET", "params": [{"description": "News section key; defaults to all", "enum": ["all", "football", "uefa-nations-league", "tennis", "features", "premier-league", "nfl", "mlb", "nba", "nhl", "formula-1", "champions-league", "europa-league", "conference-league", "darts", "snooker", "golf", "road-cycling", "laliga", "bundesliga", "serie-a", "ligue-1", "badminton", "handball", "hockey", "basketball", "cricket", "rugby-union", "athletics", "baseball", "fifa", "rugby-league", "motorsport", "aussie-rules", "flashscore-ratings", "american-sports", "african-football", "combat-sports", "winter-sports", "transfer-news"], "in": "query", "name": "category", "type": "string", "x-example": "football"}, {"description": "1-based page, 1 to 100; defaults to 1", "in": "query", "maximum": 100, "minimum": 1, "name": "page", "type": "integer", "x-example": 1}], "path": "/flashscore/news", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["all", "football", "uefa-nations-league", "tennis", "features", "premier-league", "nfl", "mlb", "nba", "nhl", "formula-1", "champions-league", "europa-league", "conference-league", "darts", "snooker", "golf", "road-cycling", "laliga", "bundesliga", "serie-a", "ligue-1", "badminton", "handball", "hockey", "basketball", "cricket", "rugby-union", "athletics", "baseball", "fifa", "rugby-league", "motorsport", "aussie-rules", "flashscore-ratings", "american-sports", "african-football", "combat-sports", "winter-sports", "transfer-news"], "in": "query", "name": "category", "type": "string"}, {"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "flashscore-news-article": {"id": "flashscore-news-article", "method": "GET", "params": [{"description": "Eight-character Flashscore article id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "GYDHQ2yR"}], "path": "/flashscore/news-article", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-news-categories": {"id": "flashscore-news-categories", "method": "GET", "params": [], "path": "/flashscore/news-categories", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "flashscore-odds-geos": {"id": "flashscore-odds-geos", "method": "GET", "params": [], "path": "/flashscore/odds-geos", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "flashscore-player": {"id": "flashscore-player", "method": "GET", "params": [{"description": "Eight-character Flashscore player id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "UmV9iQmE"}, {"description": "Optional player slug; must match the id when supplied", "in": "query", "name": "slug", "type": "string", "x-example": "haaland-erling"}], "path": "/flashscore/player", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "slug", "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-player-injuries": {"id": "flashscore-player-injuries", "method": "GET", "params": [{"description": "Eight-character Flashscore player id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "UmV9iQmE"}, {"description": "Optional player slug; must match the id when supplied", "in": "query", "name": "slug", "type": "string", "x-example": "haaland-erling"}], "path": "/flashscore/player-injuries", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "slug", "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-player-transfers": {"id": "flashscore-player-transfers", "method": "GET", "params": [{"description": "Eight-character Flashscore player id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "UmV9iQmE"}, {"description": "Optional player slug; must match the id when supplied", "in": "query", "name": "slug", "type": "string", "x-example": "haaland-erling"}], "path": "/flashscore/player-transfers", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "slug", "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-ranking-categories": {"id": "flashscore-ranking-categories", "method": "GET", "params": [], "path": "/flashscore/ranking-categories", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "flashscore-rankings": {"id": "flashscore-rankings", "method": "GET", "params": [{"description": "Ranking category from flashscore-ranking-categories", "enum": ["fifa", "tennis-atp", "tennis-wta", "tennis-atp-race", "tennis-wta-race", "tennis-atp-doubles", "tennis-wta-doubles", "tennis-atp-doubles-race", "tennis-wta-doubles-race", "badminton-bwf-singles-men", "badminton-bwf-singles-women", "badminton-bwf-doubles-men", "badminton-bwf-doubles-women", "badminton-bwf-mixed-doubles", "golf-owgr", "golf-wwgr", "golf-pga-fedexcup", "golf-pga-money", "golf-dp-world-tour", "golf-lpga", "golf-asian-tour", "golf-japan-tour", "golf-sunshine-tour", "golf-korn-ferry", "golf-champions-tour", "darts-world-ranking", "snooker-world-ranking", "tennis-atp-live", "tennis-wta-live", "tennis-atp-race-live", "tennis-wta-race-live", "tennis-atp-doubles-live", "tennis-wta-doubles-live", "tennis-atp-doubles-race-live", "tennis-wta-doubles-race-live"], "in": "query", "name": "category", "required": true, "type": "string", "x-example": "tennis-atp"}], "path": "/flashscore/rankings", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["fifa", "tennis-atp", "tennis-wta", "tennis-atp-race", "tennis-wta-race", "tennis-atp-doubles", "tennis-wta-doubles", "tennis-atp-doubles-race", "tennis-wta-doubles-race", "badminton-bwf-singles-men", "badminton-bwf-singles-women", "badminton-bwf-doubles-men", "badminton-bwf-doubles-women", "badminton-bwf-mixed-doubles", "golf-owgr", "golf-wwgr", "golf-pga-fedexcup", "golf-pga-money", "golf-dp-world-tour", "golf-lpga", "golf-asian-tour", "golf-japan-tour", "golf-sunshine-tour", "golf-korn-ferry", "golf-champions-tour", "darts-world-ranking", "snooker-world-ranking", "tennis-atp-live", "tennis-wta-live", "tennis-atp-race-live", "tennis-wta-race-live", "tennis-atp-doubles-live", "tennis-wta-doubles-live", "tennis-atp-doubles-race-live", "tennis-wta-doubles-race-live"], "in": "query", "name": "category", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-scores": {"id": "flashscore-scores", "method": "GET", "params": [{"description": "Sport key", "enum": ["football", "tennis", "basketball", "hockey", "golf", "formula-1", "baseball", "snooker", "american-football", "aussie-rules", "badminton", "bandy", "beach-soccer", "beach-volleyball", "boxing", "cricket", "cycling", "darts", "esports", "field-hockey", "floorball", "futsal", "handball", "horse-racing", "kabaddi", "mma", "motorsport", "netball", "pesapallo", "rugby-league", "rugby-union", "table-tennis", "volleyball", "water-polo", "winter-sports"], "in": "query", "name": "sport", "required": true, "type": "string", "x-example": "football"}, {"description": "Days from today; -7 to 7; defaults to 0", "in": "query", "maximum": 7, "minimum": -7, "name": "day_offset", "type": "integer", "x-example": 0}], "path": "/flashscore/scores", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["football", "tennis", "basketball", "hockey", "golf", "formula-1", "baseball", "snooker", "american-football", "aussie-rules", "badminton", "bandy", "beach-soccer", "beach-volleyball", "boxing", "cricket", "cycling", "darts", "esports", "field-hockey", "floorball", "futsal", "handball", "horse-racing", "kabaddi", "mma", "motorsport", "netball", "pesapallo", "rugby-league", "rugby-union", "table-tennis", "volleyball", "water-polo", "winter-sports"], "in": "query", "name": "sport", "required": true, "type": "string"}, {"in": "query", "name": "day_offset", "type": "integer"}], "security": ["ApiKeyAuth"]}, "flashscore-search": {"id": "flashscore-search", "method": "GET", "params": [{"description": "Search phrase (2 to 80 characters)", "in": "query", "maxLength": 80, "minLength": 2, "name": "q", "required": true, "type": "string", "x-example": "Champions League"}], "path": "/flashscore/search", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "q", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-sports": {"id": "flashscore-sports", "method": "GET", "params": [], "path": "/flashscore/sports", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "flashscore-team": {"id": "flashscore-team", "method": "GET", "params": [{"description": "Eight-character Flashscore team id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "Wtn9Stg0"}], "path": "/flashscore/team", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-team-fixtures": {"id": "flashscore-team-fixtures", "method": "GET", "params": [{"description": "Eight-character Flashscore team id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "Wtn9Stg0"}, {"description": "1-based page from 1 to 300; defaults to 1", "in": "query", "maximum": 300, "minimum": 1, "name": "page", "type": "integer", "x-example": 1}], "path": "/flashscore/team-fixtures", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "flashscore-team-news": {"id": "flashscore-team-news", "method": "GET", "params": [{"description": "Eight-character Flashscore team id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "Wtn9Stg0"}], "path": "/flashscore/team-news", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-team-results": {"id": "flashscore-team-results", "method": "GET", "params": [{"description": "Eight-character Flashscore team id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "Wtn9Stg0"}, {"description": "1-based page from 1 to 300; defaults to 1", "in": "query", "maximum": 300, "minimum": 1, "name": "page", "type": "integer", "x-example": 1}], "path": "/flashscore/team-results", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "flashscore-team-squad": {"id": "flashscore-team-squad", "method": "GET", "params": [{"description": "Eight-character Flashscore team id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "Wtn9Stg0"}, {"description": "Optional team slug; must match the id when supplied", "in": "query", "name": "slug", "type": "string", "x-example": "manchester-city"}, {"description": "Squad statistics scope key from the scopes list of a previous response (for example overall-all or league-SY30SsKF); defaults to overall-all", "in": "query", "name": "scope", "type": "string", "x-example": "overall-all"}], "path": "/flashscore/team-squad", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"in": "query", "name": "slug", "type": "string"}, {"in": "query", "name": "scope", "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-team-transfers": {"id": "flashscore-team-transfers", "method": "GET", "params": [{"description": "Eight-character Flashscore team id", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "Wtn9Stg0"}, {"description": "Transfer direction filter; defaults to all", "enum": ["all", "arrivals", "departures"], "in": "query", "name": "type", "type": "string", "x-example": "all"}, {"description": "1-based page from 1 to 300; defaults to 1", "in": "query", "maximum": 300, "minimum": 1, "name": "page", "type": "integer", "x-example": 1}], "path": "/flashscore/team-transfers", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}, {"enum": ["all", "arrivals", "departures"], "in": "query", "name": "type", "type": "string"}, {"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "flashscore-top-search": {"id": "flashscore-top-search", "method": "GET", "params": [], "path": "/flashscore/top-search", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "flashscore-tournament-events": {"id": "flashscore-tournament-events", "method": "GET", "params": [{"description": "Relative Flashscore competition season results or fixtures path", "in": "query", "name": "path", "required": true, "type": "string", "x-example": "/football/england/premier-league-2026-2027/fixtures/"}, {"description": "1-based page; defaults to 1", "in": "query", "maximum": 100, "minimum": 1, "name": "page", "type": "integer", "x-example": 1}], "path": "/flashscore/tournament-events", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "path", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "flashscore-tournament-seasons": {"id": "flashscore-tournament-seasons", "method": "GET", "params": [{"description": "Relative Flashscore competition archive path ending in /archive/", "in": "query", "name": "path", "required": true, "type": "string", "x-example": "/football/europe/champions-league/archive/"}], "path": "/flashscore/tournament-seasons", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "path", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-tournament-standings": {"id": "flashscore-tournament-standings", "method": "GET", "params": [{"description": "Relative Flashscore competition path from flashscore-navigation or flashscore-competitions; omit /standings/", "in": "query", "name": "path", "required": true, "type": "string", "x-example": "/football/england/premier-league/"}, {"description": "View returned by flashscore-tournament-standings-views; defaults to overall", "enum": ["overall", "home", "away", "form_overall", "form_home", "form_away", "overunder_overall", "overunder_home", "overunder_away", "htft_overall", "htft_home", "htft_away", "top_scorers"], "in": "query", "name": "view", "type": "string", "x-example": "overall"}], "path": "/flashscore/tournament-standings", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "path", "required": true, "type": "string"}, {"enum": ["overall", "home", "away", "form_overall", "form_home", "form_away", "overunder_overall", "overunder_home", "overunder_away", "htft_overall", "htft_home", "htft_away", "top_scorers"], "in": "query", "name": "view", "type": "string"}], "security": ["ApiKeyAuth"]}, "flashscore-tournament-standings-views": {"id": "flashscore-tournament-standings-views", "method": "GET", "params": [{"description": "Relative Flashscore competition path from flashscore-navigation or flashscore-competitions; omit /standings/", "in": "query", "name": "path", "required": true, "type": "string", "x-example": "/football/england/premier-league/"}], "path": "/flashscore/tournament-standings-views", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "path", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}}
|
|
23
|
+
JSON
|
|
24
|
+
OPERATION_IDS = JSON.parse(<<~'JSON').freeze
|
|
25
|
+
["flashscore-calendar", "flashscore-calendar-categories", "flashscore-competitions", "flashscore-match-h2h", "flashscore-match-highlights", "flashscore-match-info", "flashscore-match-lineups", "flashscore-match-missing-players", "flashscore-match-news", "flashscore-match-odds", "flashscore-match-predicted-lineups", "flashscore-match-standings", "flashscore-match-stats", "flashscore-match-tv", "flashscore-navigation", "flashscore-news", "flashscore-news-article", "flashscore-news-categories", "flashscore-odds-geos", "flashscore-player", "flashscore-player-injuries", "flashscore-player-transfers", "flashscore-ranking-categories", "flashscore-rankings", "flashscore-scores", "flashscore-search", "flashscore-sports", "flashscore-team", "flashscore-team-fixtures", "flashscore-team-news", "flashscore-team-results", "flashscore-team-squad", "flashscore-team-transfers", "flashscore-top-search", "flashscore-tournament-events", "flashscore-tournament-seasons", "flashscore-tournament-standings", "flashscore-tournament-standings-views"]
|
|
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-flashscore-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('calendar') do |**params|
|
|
109
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
110
|
+
request('flashscore-calendar', params, response_type: response_type)
|
|
111
|
+
end
|
|
112
|
+
define_method('calendar_categories') do |**params|
|
|
113
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
114
|
+
request('flashscore-calendar-categories', params, response_type: response_type)
|
|
115
|
+
end
|
|
116
|
+
define_method('competitions') do |**params|
|
|
117
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
118
|
+
request('flashscore-competitions', params, response_type: response_type)
|
|
119
|
+
end
|
|
120
|
+
define_method('match_h2h') do |**params|
|
|
121
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
122
|
+
request('flashscore-match-h2h', params, response_type: response_type)
|
|
123
|
+
end
|
|
124
|
+
define_method('match_highlights') do |**params|
|
|
125
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
126
|
+
request('flashscore-match-highlights', params, response_type: response_type)
|
|
127
|
+
end
|
|
128
|
+
define_method('match_info') do |**params|
|
|
129
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
130
|
+
request('flashscore-match-info', params, response_type: response_type)
|
|
131
|
+
end
|
|
132
|
+
define_method('match_lineups') do |**params|
|
|
133
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
134
|
+
request('flashscore-match-lineups', params, response_type: response_type)
|
|
135
|
+
end
|
|
136
|
+
define_method('match_missing_players') do |**params|
|
|
137
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
138
|
+
request('flashscore-match-missing-players', params, response_type: response_type)
|
|
139
|
+
end
|
|
140
|
+
define_method('match_news') do |**params|
|
|
141
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
142
|
+
request('flashscore-match-news', params, response_type: response_type)
|
|
143
|
+
end
|
|
144
|
+
define_method('match_odds') do |**params|
|
|
145
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
146
|
+
request('flashscore-match-odds', params, response_type: response_type)
|
|
147
|
+
end
|
|
148
|
+
define_method('match_predicted_lineups') do |**params|
|
|
149
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
150
|
+
request('flashscore-match-predicted-lineups', params, response_type: response_type)
|
|
151
|
+
end
|
|
152
|
+
define_method('match_standings') do |**params|
|
|
153
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
154
|
+
request('flashscore-match-standings', params, response_type: response_type)
|
|
155
|
+
end
|
|
156
|
+
define_method('match_stats') do |**params|
|
|
157
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
158
|
+
request('flashscore-match-stats', params, response_type: response_type)
|
|
159
|
+
end
|
|
160
|
+
define_method('match_tv') do |**params|
|
|
161
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
162
|
+
request('flashscore-match-tv', params, response_type: response_type)
|
|
163
|
+
end
|
|
164
|
+
define_method('navigation') do |**params|
|
|
165
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
166
|
+
request('flashscore-navigation', params, response_type: response_type)
|
|
167
|
+
end
|
|
168
|
+
define_method('news') do |**params|
|
|
169
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
170
|
+
request('flashscore-news', params, response_type: response_type)
|
|
171
|
+
end
|
|
172
|
+
define_method('news_article') do |**params|
|
|
173
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
174
|
+
request('flashscore-news-article', params, response_type: response_type)
|
|
175
|
+
end
|
|
176
|
+
define_method('news_categories') do |**params|
|
|
177
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
178
|
+
request('flashscore-news-categories', params, response_type: response_type)
|
|
179
|
+
end
|
|
180
|
+
define_method('odds_geos') do |**params|
|
|
181
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
182
|
+
request('flashscore-odds-geos', params, response_type: response_type)
|
|
183
|
+
end
|
|
184
|
+
define_method('player') do |**params|
|
|
185
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
186
|
+
request('flashscore-player', params, response_type: response_type)
|
|
187
|
+
end
|
|
188
|
+
define_method('player_injuries') do |**params|
|
|
189
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
190
|
+
request('flashscore-player-injuries', params, response_type: response_type)
|
|
191
|
+
end
|
|
192
|
+
define_method('player_transfers') do |**params|
|
|
193
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
194
|
+
request('flashscore-player-transfers', params, response_type: response_type)
|
|
195
|
+
end
|
|
196
|
+
define_method('ranking_categories') do |**params|
|
|
197
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
198
|
+
request('flashscore-ranking-categories', params, response_type: response_type)
|
|
199
|
+
end
|
|
200
|
+
define_method('rankings') do |**params|
|
|
201
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
202
|
+
request('flashscore-rankings', params, response_type: response_type)
|
|
203
|
+
end
|
|
204
|
+
define_method('scores') do |**params|
|
|
205
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
206
|
+
request('flashscore-scores', 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('flashscore-search', params, response_type: response_type)
|
|
211
|
+
end
|
|
212
|
+
define_method('sports') do |**params|
|
|
213
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
214
|
+
request('flashscore-sports', params, response_type: response_type)
|
|
215
|
+
end
|
|
216
|
+
define_method('team') do |**params|
|
|
217
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
218
|
+
request('flashscore-team', params, response_type: response_type)
|
|
219
|
+
end
|
|
220
|
+
define_method('team_fixtures') do |**params|
|
|
221
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
222
|
+
request('flashscore-team-fixtures', params, response_type: response_type)
|
|
223
|
+
end
|
|
224
|
+
define_method('team_news') do |**params|
|
|
225
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
226
|
+
request('flashscore-team-news', params, response_type: response_type)
|
|
227
|
+
end
|
|
228
|
+
define_method('team_results') do |**params|
|
|
229
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
230
|
+
request('flashscore-team-results', params, response_type: response_type)
|
|
231
|
+
end
|
|
232
|
+
define_method('team_squad') do |**params|
|
|
233
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
234
|
+
request('flashscore-team-squad', params, response_type: response_type)
|
|
235
|
+
end
|
|
236
|
+
define_method('team_transfers') do |**params|
|
|
237
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
238
|
+
request('flashscore-team-transfers', params, response_type: response_type)
|
|
239
|
+
end
|
|
240
|
+
define_method('top_search') do |**params|
|
|
241
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
242
|
+
request('flashscore-top-search', params, response_type: response_type)
|
|
243
|
+
end
|
|
244
|
+
define_method('tournament_events') do |**params|
|
|
245
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
246
|
+
request('flashscore-tournament-events', params, response_type: response_type)
|
|
247
|
+
end
|
|
248
|
+
define_method('tournament_seasons') do |**params|
|
|
249
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
250
|
+
request('flashscore-tournament-seasons', params, response_type: response_type)
|
|
251
|
+
end
|
|
252
|
+
define_method('tournament_standings') do |**params|
|
|
253
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
254
|
+
request('flashscore-tournament-standings', params, response_type: response_type)
|
|
255
|
+
end
|
|
256
|
+
define_method('tournament_standings_views') do |**params|
|
|
257
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
258
|
+
request('flashscore-tournament-standings-views', params, response_type: response_type)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
private
|
|
262
|
+
|
|
263
|
+
def build_url(operation, params)
|
|
264
|
+
known = operation["params"].map { |param| param["name"] }
|
|
265
|
+
unknown = params.keys - known
|
|
266
|
+
raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
|
|
267
|
+
path = operation["path"].dup
|
|
268
|
+
operation["params"].select { |param| param["in"] == "path" }.each do |param|
|
|
269
|
+
value = params[param["name"]]
|
|
270
|
+
raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
|
|
271
|
+
path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
|
|
272
|
+
end
|
|
273
|
+
pairs = []
|
|
274
|
+
operation["queryParams"].each do |param|
|
|
275
|
+
name = param["name"]
|
|
276
|
+
value = params.key?(name) ? params[name] : param["default"]
|
|
277
|
+
if value.nil?
|
|
278
|
+
raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
|
|
279
|
+
next
|
|
280
|
+
end
|
|
281
|
+
enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
|
|
282
|
+
if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
|
|
283
|
+
raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
|
|
284
|
+
end
|
|
285
|
+
if value.is_a?(Array)
|
|
286
|
+
format = param["collectionFormat"] || "csv"
|
|
287
|
+
if format == "multi"
|
|
288
|
+
value.each { |item| pairs << [name, scalar(item)] }
|
|
289
|
+
else
|
|
290
|
+
separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
|
|
291
|
+
pairs << [name, value.map { |item| scalar(item) }.join(separator)]
|
|
292
|
+
end
|
|
293
|
+
else
|
|
294
|
+
pairs << [name, scalar(value)]
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
|
|
298
|
+
@base_url + path + (query.empty? ? "" : "?" + query)
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
def scalar(value)
|
|
302
|
+
value == true ? "true" : (value == false ? "false" : value.to_s)
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def percent_encode(value)
|
|
306
|
+
URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
def parse_response(body, content_type, operation, params, response_type)
|
|
310
|
+
type = response_type.to_s
|
|
311
|
+
raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
|
|
312
|
+
format = operation["params"].find { |param| param["name"] == "format" }
|
|
313
|
+
text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
|
|
314
|
+
raw_format = params["format"] && text_formats.include?(params["format"].to_s)
|
|
315
|
+
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)
|
|
316
|
+
is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
|
|
317
|
+
return body if type == "text" || raw_format || (type == "auto" && !is_json)
|
|
318
|
+
JSON.parse(body)
|
|
319
|
+
rescue JSON::ParserError => error
|
|
320
|
+
raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
public
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: crawlora-flashscore
|
|
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 Flashscore 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/flashscore.rb
|
|
23
|
+
- lib/crawlora/flashscore/client.rb
|
|
24
|
+
- lib/crawlora/flashscore/version.rb
|
|
25
|
+
homepage: https://github.com/Crawlora-org/crawlora-flashscore
|
|
26
|
+
licenses:
|
|
27
|
+
- MIT
|
|
28
|
+
metadata:
|
|
29
|
+
source_code_uri: https://github.com/Crawlora-org/crawlora-flashscore
|
|
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: Flashscore client for the Crawlora hosted API
|
|
50
|
+
test_files: []
|