crawlora-draftkings 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 +71 -0
- data/lib/crawlora/draftkings/client.rb +320 -0
- data/lib/crawlora/draftkings/version.rb +5 -0
- data/lib/crawlora/draftkings.rb +2 -0
- metadata +53 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f6e40e9420922c008203f368c3bb9383d31940a814286238914085c4c2a4156f
|
|
4
|
+
data.tar.gz: 7f22d92dccfbc2664df60ed4f23fe4dfc15a23956a8283ad98f5064028661526
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 54440c0ab27dd7fd71450a9ef866da8d6cbbe143b0c87c7186b6c7b62b2dff8ae981cd21fb62ef0db0bc13b35dd05ae1302af0bab1a265d91db709ed13b104bc
|
|
7
|
+
data.tar.gz: 3fb6bd3169b6860d6eb5e3bf11405ff1b8f8a02bd9028f0ca02c1de7f5d1c85adbc3df54d5e2c8342c4d83ec3d2cae0935144a0acf356c7d641fe56784e4d5a3
|
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,71 @@
|
|
|
1
|
+
# Crawlora DraftKings API client for Ruby (`crawlora-draftkings`)
|
|
2
|
+
|
|
3
|
+
This Ruby gem calls Crawlora's hosted DraftKings API at `https://api.crawlora.net/api/v1`. It exposes 31 endpoints covering public sportsbook, racing, daily fantasy, Pick6, casino, and prediction-market catalogues; it does not call or scrape DraftKings directly. Requests require your Crawlora API key and use your account's service plan.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem "crawlora-draftkings"
|
|
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=draftkings-ruby-signup), open the [Crawlora console](https://crawlora.net/app?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=draftkings-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/draftkings"
|
|
16
|
+
|
|
17
|
+
client = Crawlora::Draftkings::Client.new
|
|
18
|
+
result = client.request("draftkings-casino-directory", JSON.parse("{}"))
|
|
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 31 API operations.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
client = Crawlora::Draftkings::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 DraftKings API endpoints
|
|
34
|
+
|
|
35
|
+
Browse every route included in this gem. The [endpoint reference](https://github.com/Crawlora-org/crawlora-draftkings/blob/main/docs/usage.md) includes parameter and response details.
|
|
36
|
+
|
|
37
|
+
| Method | Endpoint | API operation | Description |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| `GET` | `/draftkings/casino/directory` | `draftkings-casino-directory` | DraftKings Casino slots directory |
|
|
40
|
+
| `GET` | `/draftkings/casino/slots-guide` | `draftkings-casino-slots-guide` | DraftKings Casino slots guide |
|
|
41
|
+
| `GET` | `/draftkings/casino/slots/categories` | `draftkings-casino-slots-categories` | DraftKings Casino slot categories |
|
|
42
|
+
| `GET` | `/draftkings/casino/slots/cleopatra-guide` | `draftkings-casino-cleopatra-guide` | DraftKings Cleopatra slot guide |
|
|
43
|
+
| `GET` | `/draftkings/casino/slots/wheel-of-fortune-guide` | `draftkings-casino-wheel-of-fortune-guide` | DraftKings Wheel of Fortune slot guide |
|
|
44
|
+
| `GET` | `/draftkings/dfs/glossary` | `draftkings-dfs-glossary` | DraftKings Daily Fantasy glossary |
|
|
45
|
+
| `GET` | `/draftkings/dfs/guide` | `draftkings-dfs-guide` | DraftKings Daily Fantasy guide |
|
|
46
|
+
| `GET` | `/draftkings/dfs/nfl-best-ball/featured-contests` | `draftkings-dfs-nfl-best-ball-featured-contests` | DraftKings NFL Best Ball featured contests |
|
|
47
|
+
| `GET` | `/draftkings/dfs/rules-and-scoring` | `draftkings-dfs-rules-and-scoring` | DraftKings DFS Rules & Scoring |
|
|
48
|
+
| `GET` | `/draftkings/dfs/sports` | `draftkings-dfs-sports` | DraftKings Daily Fantasy sports catalog |
|
|
49
|
+
| `GET` | `/draftkings/pick6/rules` | `draftkings-pick6-rules` | DraftKings Pick6 rules |
|
|
50
|
+
| `GET` | `/draftkings/pick6/rules/{slug}` | `draftkings-pick6-rule-page` | DraftKings Pick6 sport-specific rules |
|
|
51
|
+
| `GET` | `/draftkings/pick6/sports` | `draftkings-pick6-sports` | DraftKings Pick6 sport directory |
|
|
52
|
+
| `GET` | `/draftkings/predictions/availability` | `draftkings-predictions-availability` | DraftKings Predictions availability map |
|
|
53
|
+
| `GET` | `/draftkings/predictions/categories` | `draftkings-predictions-categories` | DraftKings Predictions categories |
|
|
54
|
+
| `GET` | `/draftkings/predictions/rules` | `draftkings-predictions-rules` | DraftKings Predictions rules and settlement sources |
|
|
55
|
+
| `GET` | `/draftkings/racing/race/{race_id}` | `draftkings-racing-race-info` | DraftKings Racing race card and results |
|
|
56
|
+
| `GET` | `/draftkings/racing/schedule` | `draftkings-racing-schedule` | DraftKings Racing schedule |
|
|
57
|
+
| `GET` | `/draftkings/racing/tracks` | `draftkings-racing-tracks` | DraftKings Racing tracks |
|
|
58
|
+
| `GET` | `/draftkings/sportsbook/event` | `draftkings-event` | DraftKings Sportsbook event |
|
|
59
|
+
| `GET` | `/draftkings/sportsbook/event-context` | `draftkings-event-context` | DraftKings Sportsbook event context |
|
|
60
|
+
| `GET` | `/draftkings/sportsbook/event-markets` | `draftkings-event-markets` | DraftKings Sportsbook event markets |
|
|
61
|
+
| `GET` | `/draftkings/sportsbook/featured-leagues` | `draftkings-featured-leagues` | DraftKings Sportsbook featured leagues |
|
|
62
|
+
| `GET` | `/draftkings/sportsbook/futures` | `draftkings-futures` | DraftKings Sportsbook futures |
|
|
63
|
+
| `GET` | `/draftkings/sportsbook/league-events` | `draftkings-league-events` | DraftKings Sportsbook league event directory |
|
|
64
|
+
| `GET` | `/draftkings/sportsbook/leagues` | `draftkings-leagues` | DraftKings Sportsbook sports and leagues |
|
|
65
|
+
| `GET` | `/draftkings/sportsbook/live` | `draftkings-live` | DraftKings Sportsbook live events |
|
|
66
|
+
| `GET` | `/draftkings/sportsbook/odds` | `draftkings-odds` | DraftKings Sportsbook odds |
|
|
67
|
+
| `GET` | `/draftkings/sportsbook/quick-links` | `draftkings-quick-links` | DraftKings Sportsbook quick links |
|
|
68
|
+
| `GET` | `/draftkings/sportsbook/team` | `draftkings-team` | DraftKings Sportsbook team |
|
|
69
|
+
| `GET` | `/draftkings/sportsbook/teams` | `draftkings-teams` | DraftKings Sportsbook league teams |
|
|
70
|
+
|
|
71
|
+
See [Crawlora](https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=draftkings-ruby-homepage), the [API documentation](https://crawlora.net/docs?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=draftkings-ruby-api-docs), and [the package repository](https://github.com/Crawlora-org/crawlora-draftkings) for account setup, the API operation reference, and release history.
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Crawlora
|
|
6
|
+
module Draftkings
|
|
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
|
+
{"draftkings-casino-cleopatra-guide": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-casino-cleopatra-guide", "method": "GET", "params": [], "path": "/draftkings/casino/slots/cleopatra-guide", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-casino-directory": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-casino-directory", "method": "GET", "params": [], "path": "/draftkings/casino/directory", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-casino-slots-categories": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-casino-slots-categories", "method": "GET", "params": [], "path": "/draftkings/casino/slots/categories", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-casino-slots-guide": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-casino-slots-guide", "method": "GET", "params": [], "path": "/draftkings/casino/slots-guide", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-casino-wheel-of-fortune-guide": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-casino-wheel-of-fortune-guide", "method": "GET", "params": [], "path": "/draftkings/casino/slots/wheel-of-fortune-guide", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-dfs-glossary": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-dfs-glossary", "method": "GET", "params": [], "path": "/draftkings/dfs/glossary", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-dfs-guide": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-dfs-guide", "method": "GET", "params": [], "path": "/draftkings/dfs/guide", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-dfs-nfl-best-ball-featured-contests": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-dfs-nfl-best-ball-featured-contests", "method": "GET", "params": [], "path": "/draftkings/dfs/nfl-best-ball/featured-contests", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-dfs-rules-and-scoring": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-dfs-rules-and-scoring", "method": "GET", "params": [], "path": "/draftkings/dfs/rules-and-scoring", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-dfs-sports": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-dfs-sports", "method": "GET", "params": [], "path": "/draftkings/dfs/sports", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-event": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-event", "method": "GET", "params": [{"description": "Numeric DraftKings event id", "in": "query", "name": "event_id", "required": true, "type": "string", "x-example": "34240140"}], "path": "/draftkings/sportsbook/event", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "event_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "draftkings-event-context": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-event-context", "method": "GET", "params": [{"description": "Numeric DraftKings event id", "in": "query", "name": "event_id", "required": true, "type": "string", "x-example": "34522271"}], "path": "/draftkings/sportsbook/event-context", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "event_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "draftkings-event-markets": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-event-markets", "method": "GET", "params": [{"description": "Numeric DraftKings event id", "in": "query", "name": "event_id", "required": true, "type": "string", "x-example": "34497667"}, {"description": "Numeric DraftKings market subcategory id", "in": "query", "name": "subcategory_id", "required": true, "type": "string", "x-example": "6354"}], "path": "/draftkings/sportsbook/event-markets", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "event_id", "required": true, "type": "string"}, {"in": "query", "name": "subcategory_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "draftkings-featured-leagues": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-featured-leagues", "method": "GET", "params": [], "path": "/draftkings/sportsbook/featured-leagues", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-futures": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-futures", "method": "GET", "params": [{"description": "Numeric DraftKings league id", "in": "query", "name": "league_id", "required": true, "type": "string", "x-example": "84240"}, {"description": "Numeric DraftKings futures market subcategory id", "in": "query", "name": "subcategory_id", "required": true, "type": "string", "x-example": "17279"}], "path": "/draftkings/sportsbook/futures", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_id", "required": true, "type": "string"}, {"in": "query", "name": "subcategory_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "draftkings-league-events": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-league-events", "method": "GET", "params": [{"description": "Numeric DraftKings league id", "in": "query", "name": "league_id", "required": true, "type": "string", "x-example": "84240"}], "path": "/draftkings/sportsbook/league-events", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "draftkings-leagues": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-leagues", "method": "GET", "params": [], "path": "/draftkings/sportsbook/leagues", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-live": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-live", "method": "GET", "params": [], "path": "/draftkings/sportsbook/live", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-odds": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-odds", "method": "GET", "params": [{"description": "Numeric DraftKings league id", "in": "query", "name": "league_id", "required": true, "type": "string", "x-example": "84240"}], "path": "/draftkings/sportsbook/odds", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "league_id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "draftkings-pick6-rule-page": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-pick6-rule-page", "method": "GET", "params": [{"description": "Sport/format slug listed by draftkings_pick6_rules", "enum": ["nfl", "nba", "nhl", "pga-full-tournament", "pga-single-round", "mlb", "wnba", "nascar", "cfb", "cbb", "soccer", "valorant", "miscellaneous", "league-of-legends", "counter-strike", "call-of-duty", "nfl-season-long", "nba-season-long"], "in": "path", "name": "slug", "required": true, "type": "string", "x-example": "pga-single-round"}], "path": "/draftkings/pick6/rules/{slug}", "pathParams": ["slug"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-pick6-rules": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-pick6-rules", "method": "GET", "params": [], "path": "/draftkings/pick6/rules", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-pick6-sports": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-pick6-sports", "method": "GET", "params": [], "path": "/draftkings/pick6/sports", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-predictions-availability": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-predictions-availability", "method": "GET", "params": [], "path": "/draftkings/predictions/availability", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-predictions-categories": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-predictions-categories", "method": "GET", "params": [], "path": "/draftkings/predictions/categories", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-predictions-rules": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-predictions-rules", "method": "GET", "params": [], "path": "/draftkings/predictions/rules", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-quick-links": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-quick-links", "method": "GET", "params": [], "path": "/draftkings/sportsbook/quick-links", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-racing-race-info": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-racing-race-info", "method": "GET", "params": [{"description": "Race ID from the public Racing schedule", "in": "path", "name": "race_id", "required": true, "type": "integer", "x-example": 381519098}], "path": "/draftkings/racing/race/{race_id}", "pathParams": ["race_id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-racing-schedule": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-racing-schedule", "method": "GET", "params": [], "path": "/draftkings/racing/schedule", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-racing-tracks": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-racing-tracks", "method": "GET", "params": [], "path": "/draftkings/racing/tracks", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "draftkings-team": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-team", "method": "GET", "params": [{"description": "Numeric DraftKings team id", "in": "query", "name": "team_id", "required": true, "type": "string", "x-example": "18454"}, {"description": "Sport: football, hockey, basketball, baseball", "enum": ["football", "hockey", "basketball", "baseball"], "in": "query", "name": "sport", "required": true, "type": "string", "x-example": "football"}, {"description": "Lowercase DraftKings team slug", "in": "query", "name": "slug", "required": true, "type": "string", "x-example": "arizona-cardinals"}], "path": "/draftkings/sportsbook/team", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "team_id", "required": true, "type": "string"}, {"enum": ["football", "hockey", "basketball", "baseball"], "in": "query", "name": "sport", "required": true, "type": "string"}, {"in": "query", "name": "slug", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "draftkings-teams": {"bodyParam": null, "bodyRequired": false, "id": "draftkings-teams", "method": "GET", "params": [{"description": "League: nfl, nhl, nba, cbb, mlb, cfb", "enum": ["nfl", "nhl", "nba", "cbb", "mlb", "cfb"], "in": "query", "name": "league", "required": true, "type": "string", "x-example": "nfl"}], "path": "/draftkings/sportsbook/teams", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["nfl", "nhl", "nba", "cbb", "mlb", "cfb"], "in": "query", "name": "league", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}}
|
|
23
|
+
JSON
|
|
24
|
+
OPERATION_IDS = JSON.parse(<<~'JSON').freeze
|
|
25
|
+
["draftkings-casino-cleopatra-guide", "draftkings-casino-directory", "draftkings-casino-slots-categories", "draftkings-casino-slots-guide", "draftkings-casino-wheel-of-fortune-guide", "draftkings-dfs-glossary", "draftkings-dfs-guide", "draftkings-dfs-nfl-best-ball-featured-contests", "draftkings-dfs-rules-and-scoring", "draftkings-dfs-sports", "draftkings-event", "draftkings-event-context", "draftkings-event-markets", "draftkings-featured-leagues", "draftkings-futures", "draftkings-league-events", "draftkings-leagues", "draftkings-live", "draftkings-odds", "draftkings-pick6-rule-page", "draftkings-pick6-rules", "draftkings-pick6-sports", "draftkings-predictions-availability", "draftkings-predictions-categories", "draftkings-predictions-rules", "draftkings-quick-links", "draftkings-racing-race-info", "draftkings-racing-schedule", "draftkings-racing-tracks", "draftkings-team", "draftkings-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-draftkings-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('casino_directory') do |**params|
|
|
118
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
119
|
+
request('draftkings-casino-directory', params, response_type: response_type)
|
|
120
|
+
end
|
|
121
|
+
define_method('casino_slots_guide') do |**params|
|
|
122
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
123
|
+
request('draftkings-casino-slots-guide', params, response_type: response_type)
|
|
124
|
+
end
|
|
125
|
+
define_method('casino_slots_categories') do |**params|
|
|
126
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
127
|
+
request('draftkings-casino-slots-categories', params, response_type: response_type)
|
|
128
|
+
end
|
|
129
|
+
define_method('casino_cleopatra_guide') do |**params|
|
|
130
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
131
|
+
request('draftkings-casino-cleopatra-guide', params, response_type: response_type)
|
|
132
|
+
end
|
|
133
|
+
define_method('casino_wheel_of_fortune_guide') do |**params|
|
|
134
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
135
|
+
request('draftkings-casino-wheel-of-fortune-guide', params, response_type: response_type)
|
|
136
|
+
end
|
|
137
|
+
define_method('dfs_glossary') do |**params|
|
|
138
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
139
|
+
request('draftkings-dfs-glossary', params, response_type: response_type)
|
|
140
|
+
end
|
|
141
|
+
define_method('dfs_guide') do |**params|
|
|
142
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
143
|
+
request('draftkings-dfs-guide', params, response_type: response_type)
|
|
144
|
+
end
|
|
145
|
+
define_method('dfs_nfl_best_ball_featured_contests') do |**params|
|
|
146
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
147
|
+
request('draftkings-dfs-nfl-best-ball-featured-contests', params, response_type: response_type)
|
|
148
|
+
end
|
|
149
|
+
define_method('dfs_rules_and_scoring') do |**params|
|
|
150
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
151
|
+
request('draftkings-dfs-rules-and-scoring', params, response_type: response_type)
|
|
152
|
+
end
|
|
153
|
+
define_method('dfs_sports') do |**params|
|
|
154
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
155
|
+
request('draftkings-dfs-sports', params, response_type: response_type)
|
|
156
|
+
end
|
|
157
|
+
define_method('pick6_rules') do |**params|
|
|
158
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
159
|
+
request('draftkings-pick6-rules', params, response_type: response_type)
|
|
160
|
+
end
|
|
161
|
+
define_method('pick6_rule_page') do |**params|
|
|
162
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
163
|
+
request('draftkings-pick6-rule-page', params, response_type: response_type)
|
|
164
|
+
end
|
|
165
|
+
define_method('pick6_sports') do |**params|
|
|
166
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
167
|
+
request('draftkings-pick6-sports', params, response_type: response_type)
|
|
168
|
+
end
|
|
169
|
+
define_method('predictions_availability') do |**params|
|
|
170
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
171
|
+
request('draftkings-predictions-availability', params, response_type: response_type)
|
|
172
|
+
end
|
|
173
|
+
define_method('predictions_categories') do |**params|
|
|
174
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
175
|
+
request('draftkings-predictions-categories', params, response_type: response_type)
|
|
176
|
+
end
|
|
177
|
+
define_method('predictions_rules') do |**params|
|
|
178
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
179
|
+
request('draftkings-predictions-rules', params, response_type: response_type)
|
|
180
|
+
end
|
|
181
|
+
define_method('racing_race_info') do |**params|
|
|
182
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
183
|
+
request('draftkings-racing-race-info', params, response_type: response_type)
|
|
184
|
+
end
|
|
185
|
+
define_method('racing_schedule') do |**params|
|
|
186
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
187
|
+
request('draftkings-racing-schedule', params, response_type: response_type)
|
|
188
|
+
end
|
|
189
|
+
define_method('racing_tracks') do |**params|
|
|
190
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
191
|
+
request('draftkings-racing-tracks', params, response_type: response_type)
|
|
192
|
+
end
|
|
193
|
+
define_method('event') do |**params|
|
|
194
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
195
|
+
request('draftkings-event', params, response_type: response_type)
|
|
196
|
+
end
|
|
197
|
+
define_method('event_context') do |**params|
|
|
198
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
199
|
+
request('draftkings-event-context', params, response_type: response_type)
|
|
200
|
+
end
|
|
201
|
+
define_method('event_markets') do |**params|
|
|
202
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
203
|
+
request('draftkings-event-markets', params, response_type: response_type)
|
|
204
|
+
end
|
|
205
|
+
define_method('featured_leagues') do |**params|
|
|
206
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
207
|
+
request('draftkings-featured-leagues', params, response_type: response_type)
|
|
208
|
+
end
|
|
209
|
+
define_method('futures') do |**params|
|
|
210
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
211
|
+
request('draftkings-futures', params, response_type: response_type)
|
|
212
|
+
end
|
|
213
|
+
define_method('league_events') do |**params|
|
|
214
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
215
|
+
request('draftkings-league-events', params, response_type: response_type)
|
|
216
|
+
end
|
|
217
|
+
define_method('leagues') do |**params|
|
|
218
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
219
|
+
request('draftkings-leagues', params, response_type: response_type)
|
|
220
|
+
end
|
|
221
|
+
define_method('live') do |**params|
|
|
222
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
223
|
+
request('draftkings-live', params, response_type: response_type)
|
|
224
|
+
end
|
|
225
|
+
define_method('odds') do |**params|
|
|
226
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
227
|
+
request('draftkings-odds', params, response_type: response_type)
|
|
228
|
+
end
|
|
229
|
+
define_method('quick_links') do |**params|
|
|
230
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
231
|
+
request('draftkings-quick-links', params, response_type: response_type)
|
|
232
|
+
end
|
|
233
|
+
define_method('team') do |**params|
|
|
234
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
235
|
+
request('draftkings-team', params, response_type: response_type)
|
|
236
|
+
end
|
|
237
|
+
define_method('teams') do |**params|
|
|
238
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
239
|
+
request('draftkings-teams', params, response_type: response_type)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
private
|
|
243
|
+
|
|
244
|
+
# POST operations take their JSON body under the body parameter name or "body".
|
|
245
|
+
def request_body(operation, params)
|
|
246
|
+
name = operation["bodyParam"]
|
|
247
|
+
return nil if name.nil?
|
|
248
|
+
value = params.key?(name) ? params[name] : params["body"]
|
|
249
|
+
if value.nil?
|
|
250
|
+
raise Errors::ClientError.new("missing request body: #{name}", operation_id: operation["id"]) if operation["bodyRequired"]
|
|
251
|
+
return nil
|
|
252
|
+
end
|
|
253
|
+
value.is_a?(String) ? value : JSON.generate(value)
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def build_url(operation, params)
|
|
257
|
+
known = operation["params"].map { |param| param["name"] }
|
|
258
|
+
known << "body" if operation["bodyParam"]
|
|
259
|
+
unknown = params.keys - known
|
|
260
|
+
raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
|
|
261
|
+
path = operation["path"].dup
|
|
262
|
+
operation["params"].select { |param| param["in"] == "path" }.each do |param|
|
|
263
|
+
value = params[param["name"]]
|
|
264
|
+
raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
|
|
265
|
+
path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
|
|
266
|
+
end
|
|
267
|
+
pairs = []
|
|
268
|
+
operation["queryParams"].each do |param|
|
|
269
|
+
name = param["name"]
|
|
270
|
+
value = params.key?(name) ? params[name] : param["default"]
|
|
271
|
+
if value.nil?
|
|
272
|
+
raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
|
|
273
|
+
next
|
|
274
|
+
end
|
|
275
|
+
enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
|
|
276
|
+
if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
|
|
277
|
+
raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
|
|
278
|
+
end
|
|
279
|
+
if value.is_a?(Array)
|
|
280
|
+
format = param["collectionFormat"] || "csv"
|
|
281
|
+
if format == "multi"
|
|
282
|
+
value.each { |item| pairs << [name, scalar(item)] }
|
|
283
|
+
else
|
|
284
|
+
separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
|
|
285
|
+
pairs << [name, value.map { |item| scalar(item) }.join(separator)]
|
|
286
|
+
end
|
|
287
|
+
else
|
|
288
|
+
pairs << [name, scalar(value)]
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
|
|
292
|
+
@base_url + path + (query.empty? ? "" : "?" + query)
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
def scalar(value)
|
|
296
|
+
value == true ? "true" : (value == false ? "false" : value.to_s)
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
def percent_encode(value)
|
|
300
|
+
URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
def parse_response(body, content_type, operation, params, response_type)
|
|
304
|
+
type = response_type.to_s
|
|
305
|
+
raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
|
|
306
|
+
format = operation["params"].find { |param| param["name"] == "format" }
|
|
307
|
+
text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
|
|
308
|
+
raw_format = params["format"] && text_formats.include?(params["format"].to_s)
|
|
309
|
+
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)
|
|
310
|
+
is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
|
|
311
|
+
return body if type == "text" || raw_format || (type == "auto" && !is_json)
|
|
312
|
+
JSON.parse(body)
|
|
313
|
+
rescue JSON::ParserError => error
|
|
314
|
+
raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
public
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: crawlora-draftkings
|
|
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-29 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Ruby client for Crawlora's hosted DraftKings API. Covers public sportsbook,
|
|
14
|
+
racing, daily fantasy, Pick6, casino, and prediction-market catalogues across 31
|
|
15
|
+
endpoints.
|
|
16
|
+
email:
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- CHANGELOG.md
|
|
22
|
+
- LICENSE
|
|
23
|
+
- README.md
|
|
24
|
+
- lib/crawlora/draftkings.rb
|
|
25
|
+
- lib/crawlora/draftkings/client.rb
|
|
26
|
+
- lib/crawlora/draftkings/version.rb
|
|
27
|
+
homepage: https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=draftkings-ruby-homepage
|
|
28
|
+
licenses:
|
|
29
|
+
- MIT
|
|
30
|
+
metadata:
|
|
31
|
+
source_code_uri: https://github.com/Crawlora-org/crawlora-draftkings
|
|
32
|
+
documentation_uri: https://github.com/Crawlora-org/crawlora-draftkings/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: DraftKings API client for Crawlora (31 endpoints)
|
|
53
|
+
test_files: []
|