crawlora-cricbuzz 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 +69 -0
- data/lib/crawlora/cricbuzz/client.rb +312 -0
- data/lib/crawlora/cricbuzz/version.rb +5 -0
- data/lib/crawlora/cricbuzz.rb +2 -0
- metadata +52 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5788c73cdf038a7dcb1f1a73b577034a62538fb2e12294f92f460d17384ef1c8
|
|
4
|
+
data.tar.gz: d76cbd60ea7d1db6d92731162687f8562a84949fc47efd83353b0bfb5d95e370
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: cd003ba9667f50defb9f191427165814c8b652067ee463c50f929615ca9a004d8695b9bb1614d5b20a7c6fdd5291ce3d14ba02ccf908acb3f9399e96ad39081c
|
|
7
|
+
data.tar.gz: '080d716de6ae56ba38cd113d595c5d32a83c91a2d5515a81cf1770e05a84e430516feacba109da0bd1b8ddd64be3c7d4e0be9f516e55c1d36cbc081a067acf60'
|
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,69 @@
|
|
|
1
|
+
# Crawlora Cricbuzz API client for Ruby (`crawlora-cricbuzz`)
|
|
2
|
+
|
|
3
|
+
This Ruby gem calls Crawlora's hosted Cricbuzz API at `https://api.crawlora.net/api/v1`. It exposes 29 endpoints covering cricket matches, schedules, news, rankings, series, and records; it does not call or scrape Cricbuzz directly. Requests require your Crawlora API key and use your account's service plan.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem "crawlora-cricbuzz"
|
|
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=cricbuzz-ruby-signup), open the [Crawlora console](https://crawlora.net/app?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=cricbuzz-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/cricbuzz"
|
|
16
|
+
|
|
17
|
+
client = Crawlora::Cricbuzz::Client.new
|
|
18
|
+
result = client.request("cricbuzz-auction-player-search", JSON.parse("{\"tournament\": \"sample\", \"year\": \"sample\", \"q\": \"sample\"}"))
|
|
19
|
+
puts result
|
|
20
|
+
client.close
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Use an operation-specific method for normal calls. `request(operation_id, params = {}, response_type: :auto)` is available for every operation. `response_type: :text` returns raw response text. This gem includes 29 API operations.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
client = Crawlora::Cricbuzz::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 Cricbuzz API endpoints
|
|
34
|
+
|
|
35
|
+
Browse every route included in this gem. The [endpoint reference](https://github.com/Crawlora-org/crawlora-cricbuzz/blob/main/docs/usage.md) includes parameter and response details.
|
|
36
|
+
|
|
37
|
+
| Method | Endpoint | API operation | Description |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| `GET` | `/cricbuzz/archives` | `cricbuzz-archives` | Discover Cricbuzz archive years and series |
|
|
40
|
+
| `GET` | `/cricbuzz/auction/info` | `cricbuzz-auction-info` | Get the Cricbuzz auction guide |
|
|
41
|
+
| `GET` | `/cricbuzz/auction/live` | `cricbuzz-auction-live` | Get the current Cricbuzz auction Live-tab payload |
|
|
42
|
+
| `GET` | `/cricbuzz/auction/options` | `cricbuzz-auction-options` | Discover Cricbuzz auction filters and sort values |
|
|
43
|
+
| `GET` | `/cricbuzz/auction/player` | `cricbuzz-auction-player-detail` | Get a Cricbuzz auction player profile and earnings |
|
|
44
|
+
| `GET` | `/cricbuzz/auction/player-search` | `cricbuzz-auction-player-search` | Search Cricbuzz auction players |
|
|
45
|
+
| `GET` | `/cricbuzz/auction/results` | `cricbuzz-auction-results` | Get filtered and sorted Cricbuzz completed-auction players |
|
|
46
|
+
| `GET` | `/cricbuzz/auction/seasons` | `cricbuzz-auction-seasons` | Discover Cricbuzz auction leagues, editions and currencies |
|
|
47
|
+
| `GET` | `/cricbuzz/auction/team` | `cricbuzz-auction-team-detail` | Get a Cricbuzz auction team's roster |
|
|
48
|
+
| `GET` | `/cricbuzz/auction/teams` | `cricbuzz-auction-teams` | Get Cricbuzz auction team purse and roster summaries |
|
|
49
|
+
| `GET` | `/cricbuzz/auction/teams/options` | `cricbuzz-auction-teams-options` | Discover Cricbuzz auction teams and sort values |
|
|
50
|
+
| `GET` | `/cricbuzz/auction/upcoming` | `cricbuzz-auction-upcoming` | Get filtered Cricbuzz unauctioned players |
|
|
51
|
+
| `GET` | `/cricbuzz/auction/upcoming/options` | `cricbuzz-auction-upcoming-options` | Discover Cricbuzz unauctioned-player filters |
|
|
52
|
+
| `GET` | `/cricbuzz/match-facts` | `cricbuzz-match-facts` | Get Cricbuzz match information and squads |
|
|
53
|
+
| `GET` | `/cricbuzz/match-graphs` | `cricbuzz-match-graphs` | Get numeric Cricbuzz match graphs |
|
|
54
|
+
| `GET` | `/cricbuzz/match-overs` | `cricbuzz-match-overs` | Get Cricbuzz over summaries |
|
|
55
|
+
| `GET` | `/cricbuzz/matches` | `cricbuzz-matches` | List Cricbuzz live, recent, or upcoming matches |
|
|
56
|
+
| `GET` | `/cricbuzz/navigation` | `cricbuzz-navigation` | Discover Cricbuzz top-level menus and dropdown links |
|
|
57
|
+
| `GET` | `/cricbuzz/news/topics` | `cricbuzz-news-topics` | Discover Cricbuzz News sections and topics |
|
|
58
|
+
| `GET` | `/cricbuzz/rankings` | `cricbuzz-rankings` | Get an ICC ranking table from Cricbuzz |
|
|
59
|
+
| `GET` | `/cricbuzz/records` | `cricbuzz-records` | Discover Cricbuzz record topics and filter values |
|
|
60
|
+
| `GET` | `/cricbuzz/schedule` | `cricbuzz-schedule` | List Cricbuzz matches by day |
|
|
61
|
+
| `GET` | `/cricbuzz/scorecard` | `cricbuzz-scorecard` | Get a Cricbuzz match scorecard |
|
|
62
|
+
| `GET` | `/cricbuzz/series` | `cricbuzz-series` | Discover Cricbuzz current and future series |
|
|
63
|
+
| `GET` | `/cricbuzz/series/stats` | `cricbuzz-series-stats` | Discover Cricbuzz series statistics |
|
|
64
|
+
| `GET` | `/cricbuzz/teams` | `cricbuzz-teams` | Discover Cricbuzz teams |
|
|
65
|
+
| `GET` | `/cricbuzz/videos/categories` | `cricbuzz-video-categories` | Discover Cricbuzz video categories |
|
|
66
|
+
| `GET` | `/cricbuzz/videos/playlists` | `cricbuzz-video-playlists` | Discover Cricbuzz video playlists |
|
|
67
|
+
| `GET` | `/cricbuzz/wtc` | `cricbuzz-wtc` | Get Cricbuzz World Test Championship standings |
|
|
68
|
+
|
|
69
|
+
See [Crawlora](https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=cricbuzz-ruby-homepage), the [API documentation](https://crawlora.net/docs?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=cricbuzz-ruby-api-docs), and [the package repository](https://github.com/Crawlora-org/crawlora-cricbuzz) for account setup, the API operation reference, and release history.
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Crawlora
|
|
6
|
+
module Cricbuzz
|
|
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
|
+
{"cricbuzz-archives": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-archives", "method": "GET", "params": [{"description": "Archive year from the years array in the response", "in": "query", "name": "year", "type": "integer", "x-example": 2026}, {"description": "Archive series category; omit for all categories", "enum": ["international", "league", "domestic", "women"], "in": "query", "name": "category", "type": "string", "x-example": "international"}, {"description": "Optional local case-insensitive substring search over selected-year series, up to 100 characters", "in": "query", "name": "q", "type": "string", "x-example": "india"}], "path": "/cricbuzz/archives", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "year", "type": "integer"}, {"enum": ["international", "league", "domestic", "women"], "in": "query", "name": "category", "type": "string"}, {"in": "query", "name": "q", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-auction-info": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-auction-info", "method": "GET", "params": [{"description": "Tournament identifier from cricbuzz/auction/seasons: ipl, wpl, sa20, hunm, hunw; defaults to ipl when both tournament/year are omitted", "in": "query", "name": "tournament", "type": "string", "x-example": "sa20"}, {"description": "Edition from cricbuzz/auction/seasons: IPL 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026; WPL 2023, 2024, 2025, 2026, 2027; SA20 2027; HUNM 2026; HUNW 2026; defaults to 2026 when both tournament/year are omitted", "in": "query", "name": "year", "type": "string", "x-example": "2027"}], "path": "/cricbuzz/auction/info", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "tournament", "type": "string"}, {"in": "query", "name": "year", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-auction-live": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-auction-live", "method": "GET", "params": [{"description": "Tournament identifier from cricbuzz/auction/seasons: ipl, wpl, sa20, hunm, hunw", "in": "query", "name": "tournament", "required": true, "type": "string", "x-example": "sa20"}, {"description": "Edition from cricbuzz/auction/seasons: IPL 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026; WPL 2023, 2024, 2025, 2026, 2027; SA20 2027; HUNM 2026; HUNW 2026", "in": "query", "name": "year", "required": true, "type": "string", "x-example": "2027"}, {"description": "Currency accepted by the selected edition: INR, USD, EUR, GBP, AUD, CAD, NZD, AED, ZAR, PKR, LKR, BDT, NPR", "in": "query", "name": "currency", "required": true, "type": "string", "x-example": "ZAR"}], "path": "/cricbuzz/auction/live", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "tournament", "required": true, "type": "string"}, {"in": "query", "name": "year", "required": true, "type": "string"}, {"in": "query", "name": "currency", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-auction-options": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-auction-options", "method": "GET", "params": [{"description": "Tournament identifier from cricbuzz/auction/seasons; current values: ipl, wpl, sa20, hunm, hunw", "in": "query", "name": "tournament", "type": "string", "x-example": "ipl"}, {"description": "Edition from cricbuzz/auction/seasons: ipl 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026; wpl 2023, 2024, 2025, 2026, 2027; sa20 2027; hunm 2026; hunw 2026", "in": "query", "name": "year", "type": "string", "x-example": "2026"}], "path": "/cricbuzz/auction/options", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "tournament", "type": "string"}, {"in": "query", "name": "year", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-auction-player-detail": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-auction-player-detail", "method": "GET", "params": [{"description": "Tournament identifier from cricbuzz/auction/seasons: ipl, wpl, sa20, hunm, hunw", "in": "query", "name": "tournament", "required": true, "type": "string", "x-example": "sa20"}, {"description": "Edition from cricbuzz/auction/seasons: IPL 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026; WPL 2023, 2024, 2025, 2026, 2027; SA20 2027; HUNM 2026; HUNW 2026", "in": "query", "name": "year", "required": true, "type": "string", "x-example": "2027"}, {"description": "Currency accepted by the selected edition: INR, USD, EUR, GBP, AUD, CAD, NZD, AED, ZAR, PKR, LKR, BDT, NPR", "in": "query", "name": "currency", "required": true, "type": "string", "x-example": "ZAR"}, {"description": "Positive Cricbuzz player ID from an auction player result or team roster", "in": "query", "name": "player_id", "required": true, "type": "integer", "x-example": 8512}], "path": "/cricbuzz/auction/player", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "tournament", "required": true, "type": "string"}, {"in": "query", "name": "year", "required": true, "type": "string"}, {"in": "query", "name": "currency", "required": true, "type": "string"}, {"in": "query", "name": "player_id", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "cricbuzz-auction-player-search": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-auction-player-search", "method": "GET", "params": [{"description": "Tournament identifier from cricbuzz/auction/seasons: ipl, wpl, sa20, hunm, hunw", "in": "query", "name": "tournament", "required": true, "type": "string", "x-example": "sa20"}, {"description": "Edition from cricbuzz/auction/seasons: IPL 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026; WPL 2023, 2024, 2025, 2026, 2027; SA20 2027; HUNM 2026; HUNW 2026", "in": "query", "name": "year", "required": true, "type": "string", "x-example": "2027"}, {"description": "3-100 ASCII English letters or spaces", "in": "query", "name": "q", "required": true, "type": "string", "x-example": "Jamie"}], "path": "/cricbuzz/auction/player-search", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "tournament", "required": true, "type": "string"}, {"in": "query", "name": "year", "required": true, "type": "string"}, {"in": "query", "name": "q", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-auction-results": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-auction-results", "method": "GET", "params": [{"description": "Tournament identifier from cricbuzz/auction/seasons; current values: ipl, wpl, sa20, hunm, hunw", "in": "query", "name": "tournament", "required": true, "type": "string", "x-example": "ipl"}, {"description": "Edition from cricbuzz/auction/seasons: ipl 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026; wpl 2023, 2024, 2025, 2026, 2027; sa20 2027; hunm 2026; hunw 2026", "in": "query", "name": "year", "required": true, "type": "string", "x-example": "2026"}, {"description": "Currency code from the selected edition: INR, USD, EUR, GBP, AUD, CAD, NZD, AED, ZAR, PKR, LKR, BDT, NPR", "in": "query", "name": "currency", "required": true, "type": "string", "x-example": "INR"}, {"description": "One-based page number; defaults to 1", "in": "query", "name": "page", "type": "integer", "x-example": 1}, {"description": "Comma-separated Country IDs from cricbuzz/auction/options; current IPL 2026 values: 96, 4, 6, 26, 9, 8, 2, 27, 527, 303, 14, 161, 72, 24, 13, 3, 23, 190, 11, 5, 384, 7, 15, 10, 12", "in": "query", "name": "country_ids", "type": "string", "x-example": "2,4"}, {"description": "Comma-separated Status values from cricbuzz/auction/options; current IPL 2026 values: Sold, Unsold, Retained, RTM, Drafted, Replacement, Traded, Wild Card", "in": "query", "name": "statuses", "type": "string", "x-example": "Sold,Unsold"}, {"description": "One Team ID from cricbuzz/auction/options; current IPL 2026 values: 58, 59, 61, 62, 63, 64, 65, 255, 966, 971", "in": "query", "name": "team_id", "type": "string", "x-example": "59"}, {"description": "One Role from cricbuzz/auction/options; current values: Batter, Bowler, Allrounder, WK-Batter", "in": "query", "name": "role", "type": "string", "x-example": "Allrounder"}, {"description": "One Cap value from cricbuzz/auction/options; current values: Capped, Uncapped", "in": "query", "name": "cap", "type": "string", "x-example": "Uncapped"}, {"description": "Displayed Sort label from cricbuzz/auction/options; current values: Recent, Featured, Base Price: High to Low, Base Price: Low to High, Final Price: High to Low, Final Price: Low to High", "in": "query", "name": "sort", "type": "string", "x-example": "Recent"}], "path": "/cricbuzz/auction/results", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "tournament", "required": true, "type": "string"}, {"in": "query", "name": "year", "required": true, "type": "string"}, {"in": "query", "name": "currency", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "country_ids", "type": "string"}, {"in": "query", "name": "statuses", "type": "string"}, {"in": "query", "name": "team_id", "type": "string"}, {"in": "query", "name": "role", "type": "string"}, {"in": "query", "name": "cap", "type": "string"}, {"in": "query", "name": "sort", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-auction-seasons": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-auction-seasons", "method": "GET", "params": [], "path": "/cricbuzz/auction/seasons", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "cricbuzz-auction-team-detail": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-auction-team-detail", "method": "GET", "params": [{"description": "Tournament identifier from cricbuzz/auction/seasons: ipl, wpl, sa20, hunm, hunw", "in": "query", "name": "tournament", "required": true, "type": "string", "x-example": "sa20"}, {"description": "Edition from cricbuzz/auction/seasons: IPL 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026; WPL 2023, 2024, 2025, 2026, 2027; SA20 2027; HUNM 2026; HUNW 2026", "in": "query", "name": "year", "required": true, "type": "string", "x-example": "2027"}, {"description": "Currency accepted by the selected edition: INR, USD, EUR, GBP, AUD, CAD, NZD, AED, ZAR, PKR, LKR, BDT, NPR", "in": "query", "name": "currency", "required": true, "type": "string", "x-example": "ZAR"}, {"description": "Team ID returned by auction/teams/options for the selected edition", "in": "query", "name": "team_id", "required": true, "type": "integer", "x-example": 1242}], "path": "/cricbuzz/auction/team", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "tournament", "required": true, "type": "string"}, {"in": "query", "name": "year", "required": true, "type": "string"}, {"in": "query", "name": "currency", "required": true, "type": "string"}, {"in": "query", "name": "team_id", "required": true, "type": "integer"}], "security": ["ApiKeyAuth"]}, "cricbuzz-auction-teams": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-auction-teams", "method": "GET", "params": [{"description": "Tournament identifier from cricbuzz/auction/seasons: ipl, wpl, sa20, hunm, hunw", "in": "query", "name": "tournament", "required": true, "type": "string", "x-example": "sa20"}, {"description": "Edition from cricbuzz/auction/seasons: IPL 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026; WPL 2023, 2024, 2025, 2026, 2027; SA20 2027; HUNM 2026; HUNW 2026", "in": "query", "name": "year", "required": true, "type": "string", "x-example": "2027"}, {"description": "Currency accepted by the selected edition: INR, USD, EUR, GBP, AUD, CAD, NZD, AED, ZAR, PKR, LKR, BDT, NPR", "in": "query", "name": "currency", "required": true, "type": "string", "x-example": "ZAR"}, {"description": "Sort label from auction/teams/options: Alphabetical, Spent: High to Low, Spent: Low to High, Remaining: High to Low, Remaining: Low to High, Players: High to Low, Players: Low to High; defaults to the upstream default", "in": "query", "name": "sort", "type": "string", "x-example": "Spent: High to Low"}], "path": "/cricbuzz/auction/teams", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "tournament", "required": true, "type": "string"}, {"in": "query", "name": "year", "required": true, "type": "string"}, {"in": "query", "name": "currency", "required": true, "type": "string"}, {"in": "query", "name": "sort", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-auction-teams-options": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-auction-teams-options", "method": "GET", "params": [{"description": "Tournament identifier from cricbuzz/auction/seasons: ipl, wpl, sa20, hunm, hunw; defaults to ipl when both tournament/year are omitted", "in": "query", "name": "tournament", "type": "string", "x-example": "sa20"}, {"description": "Edition from cricbuzz/auction/seasons: IPL 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026; WPL 2023, 2024, 2025, 2026, 2027; SA20 2027; HUNM 2026; HUNW 2026; defaults to 2026 when both tournament/year are omitted", "in": "query", "name": "year", "type": "string", "x-example": "2027"}], "path": "/cricbuzz/auction/teams/options", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "tournament", "type": "string"}, {"in": "query", "name": "year", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-auction-upcoming": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-auction-upcoming", "method": "GET", "params": [{"description": "Tournament identifier from cricbuzz/auction/seasons: ipl, wpl, sa20, hunm, hunw", "in": "query", "name": "tournament", "required": true, "type": "string", "x-example": "sa20"}, {"description": "Edition from cricbuzz/auction/seasons: IPL 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026; WPL 2023, 2024, 2025, 2026, 2027; SA20 2027; HUNM 2026; HUNW 2026", "in": "query", "name": "year", "required": true, "type": "string", "x-example": "2027"}, {"description": "Currency accepted by the selected edition: INR, USD, EUR, GBP, AUD, CAD, NZD, AED, ZAR, PKR, LKR, BDT, NPR", "in": "query", "name": "currency", "required": true, "type": "string", "x-example": "ZAR"}, {"description": "One-based page number; defaults to 1", "in": "query", "name": "page", "type": "integer", "x-example": 1}, {"description": "Comma-separated exact Country option values from auction/upcoming/options; SA20 2027 labels: Afghanistan, Australia, Bangladesh, Canada, England, Hong Kong China, India, Ireland, Italy, Jersey, Kenya, Namibia, Nepal, Netherlands, New Zealand, Pakistan, Scotland, Singapore, South Africa, Sri Lanka, Thailand, United Arab Emirates, United States of America, West Indies, Zimbabwe", "in": "query", "name": "country_ids", "type": "string", "x-example": "9"}, {"description": "Exact Role option value from auction/upcoming/options; SA20 2027 labels: All, Batter, Bowler, All Rounder, WK Batter", "in": "query", "name": "role", "type": "string", "x-example": "Allrounder"}, {"description": "Exact Cap option value from auction/upcoming/options; values: Capped, Uncapped", "in": "query", "name": "cap", "type": "string", "x-example": "Uncapped"}, {"description": "Sort label from auction/upcoming/options: Base Price: High to Low, Base Price: Low to High", "in": "query", "name": "sort", "type": "string", "x-example": "Base Price: High to Low"}], "path": "/cricbuzz/auction/upcoming", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "tournament", "required": true, "type": "string"}, {"in": "query", "name": "year", "required": true, "type": "string"}, {"in": "query", "name": "currency", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "country_ids", "type": "string"}, {"in": "query", "name": "role", "type": "string"}, {"in": "query", "name": "cap", "type": "string"}, {"in": "query", "name": "sort", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-auction-upcoming-options": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-auction-upcoming-options", "method": "GET", "params": [{"description": "Tournament identifier from cricbuzz/auction/seasons: ipl, wpl, sa20, hunm, hunw; defaults to ipl when both tournament/year are omitted", "in": "query", "name": "tournament", "type": "string", "x-example": "sa20"}, {"description": "Edition from cricbuzz/auction/seasons: IPL 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026; WPL 2023, 2024, 2025, 2026, 2027; SA20 2027; HUNM 2026; HUNW 2026; defaults to 2026 when both tournament/year are omitted", "in": "query", "name": "year", "type": "string", "x-example": "2027"}], "path": "/cricbuzz/auction/upcoming/options", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "tournament", "type": "string"}, {"in": "query", "name": "year", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-match-facts": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-match-facts", "method": "GET", "params": [{"description": "Canonical Cricbuzz live-cricket-scores URL returned by /cricbuzz/matches", "in": "query", "name": "match_url", "required": true, "type": "string", "x-example": "https://www.cricbuzz.com/live-cricket-scores/172701/afg-vs-zim-1st-t20i-afghanistan-vs-zimbabwe-in-uae-2026"}], "path": "/cricbuzz/match-facts", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "match_url", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-match-graphs": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-match-graphs", "method": "GET", "params": [{"description": "Canonical Cricbuzz live-cricket-scores URL returned by /cricbuzz/matches", "in": "query", "name": "match_url", "required": true, "type": "string", "x-example": "https://www.cricbuzz.com/live-cricket-scores/172701/afg-vs-zim-1st-t20i-afghanistan-vs-zimbabwe-in-uae-2026"}], "path": "/cricbuzz/match-graphs", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "match_url", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-match-overs": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-match-overs", "method": "GET", "params": [{"description": "Canonical Cricbuzz live-cricket-scores URL returned by /cricbuzz/matches", "in": "query", "name": "match_url", "required": true, "type": "string", "x-example": "https://www.cricbuzz.com/live-cricket-scores/172701/afg-vs-zim-1st-t20i-afghanistan-vs-zimbabwe-in-uae-2026"}], "path": "/cricbuzz/match-overs", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "match_url", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-matches": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-matches", "method": "GET", "params": [{"description": "Match-list status; defaults to live", "enum": ["live", "recent", "upcoming"], "in": "query", "name": "status", "type": "string", "x-example": "live"}, {"description": "Match category; defaults to all", "enum": ["all", "international", "league", "domestic", "women"], "in": "query", "name": "category", "type": "string", "x-example": "international"}], "path": "/cricbuzz/matches", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["live", "recent", "upcoming"], "in": "query", "name": "status", "type": "string"}, {"enum": ["all", "international", "league", "domestic", "women"], "in": "query", "name": "category", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-navigation": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-navigation", "method": "GET", "params": [], "path": "/cricbuzz/navigation", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "cricbuzz-news-topics": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-news-topics", "method": "GET", "params": [{"description": "Optional case-insensitive substring search over topic title, description, and slug, up to 100 characters", "in": "query", "name": "q", "type": "string", "x-example": "auction"}], "path": "/cricbuzz/news/topics", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "q", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-rankings": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-rankings", "method": "GET", "params": [{"description": "Ranking gender; defaults to men", "enum": ["men", "women"], "in": "query", "name": "gender", "type": "string", "x-example": "men"}, {"description": "Ranking table type; defaults to batting", "enum": ["batting", "bowling", "all-rounder", "teams"], "in": "query", "name": "type", "type": "string", "x-example": "batting"}, {"description": "Ranking format; defaults to the page's selected format. The valid set depends on gender.", "enum": ["test", "odi", "t20"], "in": "query", "name": "format", "type": "string", "x-example": "odi"}], "path": "/cricbuzz/rankings", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["men", "women"], "in": "query", "name": "gender", "type": "string"}, {"enum": ["batting", "bowling", "all-rounder", "teams"], "in": "query", "name": "type", "type": "string"}, {"enum": ["test", "odi", "t20"], "in": "query", "name": "format", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-records": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-records", "method": "GET", "params": [{"description": "Record topic; defaults to mostRuns", "enum": ["mostRuns", "highestScore", "highestAvg", "highestSr", "mostHundreds", "mostFifties", "mostFours", "mostSixes", "mostNineties", "mostWickets", "lowestAvg", "bestBowlingInnings", "mostFiveWickets", "lowestEcon", "lowestSr"], "in": "query", "name": "stat", "type": "string", "x-example": "mostRuns"}, {"description": "Match format label; defaults to the current table format", "enum": ["test", "odi", "t20"], "in": "query", "name": "format", "type": "string", "x-example": "test"}, {"description": "Year value from the page's dynamically discovered Year options", "in": "query", "name": "year", "type": "string", "x-example": "2026"}, {"description": "Team ID from the page's dynamically discovered Team options", "in": "query", "name": "team", "type": "string", "x-example": "2"}, {"description": "Opponent ID from the page's dynamically discovered Oppn options", "in": "query", "name": "opponent", "type": "string", "x-example": "4"}], "path": "/cricbuzz/records", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["mostRuns", "highestScore", "highestAvg", "highestSr", "mostHundreds", "mostFifties", "mostFours", "mostSixes", "mostNineties", "mostWickets", "lowestAvg", "bestBowlingInnings", "mostFiveWickets", "lowestEcon", "lowestSr"], "in": "query", "name": "stat", "type": "string"}, {"enum": ["test", "odi", "t20"], "in": "query", "name": "format", "type": "string"}, {"in": "query", "name": "year", "type": "string"}, {"in": "query", "name": "team", "type": "string"}, {"in": "query", "name": "opponent", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-schedule": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-schedule", "method": "GET", "params": [{"description": "Schedule category; defaults to all", "enum": ["all", "international", "league", "domestic", "women"], "in": "query", "name": "category", "type": "string", "x-example": "all"}, {"description": "Optional case-insensitive substring search over series, match descriptions, and team names, up to 100 characters", "in": "query", "name": "q", "type": "string", "x-example": "wellington"}], "path": "/cricbuzz/schedule", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["all", "international", "league", "domestic", "women"], "in": "query", "name": "category", "type": "string"}, {"in": "query", "name": "q", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-scorecard": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-scorecard", "method": "GET", "params": [{"description": "Canonical Cricbuzz live-cricket-scores URL returned by /cricbuzz/matches", "in": "query", "name": "match_url", "required": true, "type": "string", "x-example": "https://www.cricbuzz.com/live-cricket-scores/172701/afg-vs-zim-1st-t20i-afghanistan-vs-zimbabwe-in-uae-2026"}], "path": "/cricbuzz/scorecard", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "match_url", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-series": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-series", "method": "GET", "params": [{"description": "Series category; defaults to all", "enum": ["all", "international", "domestic", "league", "women"], "in": "query", "name": "category", "type": "string", "x-example": "all"}, {"description": "Restrict to Cricbuzz's Live Streaming page filter", "in": "query", "name": "live_stream", "type": "boolean", "x-example": false}, {"description": "Optional local substring search over series names, up to 100 characters", "in": "query", "name": "q", "type": "string", "x-example": "ashes"}], "path": "/cricbuzz/series", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["all", "international", "domestic", "league", "women"], "in": "query", "name": "category", "type": "string"}, {"in": "query", "name": "live_stream", "type": "boolean"}, {"in": "query", "name": "q", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-series-stats": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-series-stats", "method": "GET", "params": [{"description": "Canonical series URL returned by /cricbuzz/series", "in": "query", "name": "series_url", "required": true, "type": "string"}, {"description": "Stat topic; defaults to the currently selected topic", "enum": ["mostRuns", "highestScore", "highestAvg", "highestSr", "mostHundreds", "mostFifties", "mostFours", "mostSixes", "mostNineties", "mostWickets", "lowestAvg", "bestBowlingInnings", "mostFiveWickets", "lowestEcon", "lowestSr"], "in": "query", "name": "stat", "type": "string", "x-example": "mostRuns"}, {"description": "Format ID from the response's dynamic formats list; defaults to the current page selection", "in": "query", "name": "format", "type": "string", "x-example": "1"}], "path": "/cricbuzz/series/stats", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "series_url", "required": true, "type": "string"}, {"enum": ["mostRuns", "highestScore", "highestAvg", "highestSr", "mostHundreds", "mostFifties", "mostFours", "mostSixes", "mostNineties", "mostWickets", "lowestAvg", "bestBowlingInnings", "mostFiveWickets", "lowestEcon", "lowestSr"], "in": "query", "name": "stat", "type": "string"}, {"in": "query", "name": "format", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-teams": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-teams", "method": "GET", "params": [{"description": "Team directory category; defaults to international", "enum": ["international", "domestic", "league", "women"], "in": "query", "name": "category", "type": "string", "x-example": "international"}, {"description": "Optional local substring search over team names, up to 100 characters", "in": "query", "name": "q", "type": "string", "x-example": "india"}], "path": "/cricbuzz/teams", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["international", "domestic", "league", "women"], "in": "query", "name": "category", "type": "string"}, {"in": "query", "name": "q", "type": "string"}], "security": ["ApiKeyAuth"]}, "cricbuzz-video-categories": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-video-categories", "method": "GET", "params": [], "path": "/cricbuzz/videos/categories", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "cricbuzz-video-playlists": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-video-playlists", "method": "GET", "params": [], "path": "/cricbuzz/videos/playlists", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "cricbuzz-wtc": {"bodyParam": null, "bodyRequired": false, "id": "cricbuzz-wtc", "method": "GET", "params": [], "path": "/cricbuzz/wtc", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}}
|
|
23
|
+
JSON
|
|
24
|
+
OPERATION_IDS = JSON.parse(<<~'JSON').freeze
|
|
25
|
+
["cricbuzz-archives", "cricbuzz-auction-info", "cricbuzz-auction-live", "cricbuzz-auction-options", "cricbuzz-auction-player-detail", "cricbuzz-auction-player-search", "cricbuzz-auction-results", "cricbuzz-auction-seasons", "cricbuzz-auction-team-detail", "cricbuzz-auction-teams", "cricbuzz-auction-teams-options", "cricbuzz-auction-upcoming", "cricbuzz-auction-upcoming-options", "cricbuzz-match-facts", "cricbuzz-match-graphs", "cricbuzz-match-overs", "cricbuzz-matches", "cricbuzz-navigation", "cricbuzz-news-topics", "cricbuzz-rankings", "cricbuzz-records", "cricbuzz-schedule", "cricbuzz-scorecard", "cricbuzz-series", "cricbuzz-series-stats", "cricbuzz-teams", "cricbuzz-video-categories", "cricbuzz-video-playlists", "cricbuzz-wtc"]
|
|
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-cricbuzz-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('archives') do |**params|
|
|
118
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
119
|
+
request('cricbuzz-archives', params, response_type: response_type)
|
|
120
|
+
end
|
|
121
|
+
define_method('auction_info') do |**params|
|
|
122
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
123
|
+
request('cricbuzz-auction-info', params, response_type: response_type)
|
|
124
|
+
end
|
|
125
|
+
define_method('auction_live') do |**params|
|
|
126
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
127
|
+
request('cricbuzz-auction-live', params, response_type: response_type)
|
|
128
|
+
end
|
|
129
|
+
define_method('auction_options') do |**params|
|
|
130
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
131
|
+
request('cricbuzz-auction-options', params, response_type: response_type)
|
|
132
|
+
end
|
|
133
|
+
define_method('auction_player_detail') do |**params|
|
|
134
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
135
|
+
request('cricbuzz-auction-player-detail', params, response_type: response_type)
|
|
136
|
+
end
|
|
137
|
+
define_method('auction_player_search') do |**params|
|
|
138
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
139
|
+
request('cricbuzz-auction-player-search', params, response_type: response_type)
|
|
140
|
+
end
|
|
141
|
+
define_method('auction_results') do |**params|
|
|
142
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
143
|
+
request('cricbuzz-auction-results', params, response_type: response_type)
|
|
144
|
+
end
|
|
145
|
+
define_method('auction_seasons') do |**params|
|
|
146
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
147
|
+
request('cricbuzz-auction-seasons', params, response_type: response_type)
|
|
148
|
+
end
|
|
149
|
+
define_method('auction_team_detail') do |**params|
|
|
150
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
151
|
+
request('cricbuzz-auction-team-detail', params, response_type: response_type)
|
|
152
|
+
end
|
|
153
|
+
define_method('auction_teams') do |**params|
|
|
154
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
155
|
+
request('cricbuzz-auction-teams', params, response_type: response_type)
|
|
156
|
+
end
|
|
157
|
+
define_method('auction_teams_options') do |**params|
|
|
158
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
159
|
+
request('cricbuzz-auction-teams-options', params, response_type: response_type)
|
|
160
|
+
end
|
|
161
|
+
define_method('auction_upcoming') do |**params|
|
|
162
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
163
|
+
request('cricbuzz-auction-upcoming', params, response_type: response_type)
|
|
164
|
+
end
|
|
165
|
+
define_method('auction_upcoming_options') do |**params|
|
|
166
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
167
|
+
request('cricbuzz-auction-upcoming-options', params, response_type: response_type)
|
|
168
|
+
end
|
|
169
|
+
define_method('match_facts') do |**params|
|
|
170
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
171
|
+
request('cricbuzz-match-facts', params, response_type: response_type)
|
|
172
|
+
end
|
|
173
|
+
define_method('match_graphs') do |**params|
|
|
174
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
175
|
+
request('cricbuzz-match-graphs', params, response_type: response_type)
|
|
176
|
+
end
|
|
177
|
+
define_method('match_overs') do |**params|
|
|
178
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
179
|
+
request('cricbuzz-match-overs', params, response_type: response_type)
|
|
180
|
+
end
|
|
181
|
+
define_method('matches') do |**params|
|
|
182
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
183
|
+
request('cricbuzz-matches', params, response_type: response_type)
|
|
184
|
+
end
|
|
185
|
+
define_method('navigation') do |**params|
|
|
186
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
187
|
+
request('cricbuzz-navigation', params, response_type: response_type)
|
|
188
|
+
end
|
|
189
|
+
define_method('news_topics') do |**params|
|
|
190
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
191
|
+
request('cricbuzz-news-topics', params, response_type: response_type)
|
|
192
|
+
end
|
|
193
|
+
define_method('rankings') do |**params|
|
|
194
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
195
|
+
request('cricbuzz-rankings', params, response_type: response_type)
|
|
196
|
+
end
|
|
197
|
+
define_method('records') do |**params|
|
|
198
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
199
|
+
request('cricbuzz-records', params, response_type: response_type)
|
|
200
|
+
end
|
|
201
|
+
define_method('schedule') do |**params|
|
|
202
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
203
|
+
request('cricbuzz-schedule', params, response_type: response_type)
|
|
204
|
+
end
|
|
205
|
+
define_method('scorecard') do |**params|
|
|
206
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
207
|
+
request('cricbuzz-scorecard', params, response_type: response_type)
|
|
208
|
+
end
|
|
209
|
+
define_method('series') do |**params|
|
|
210
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
211
|
+
request('cricbuzz-series', params, response_type: response_type)
|
|
212
|
+
end
|
|
213
|
+
define_method('series_stats') do |**params|
|
|
214
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
215
|
+
request('cricbuzz-series-stats', params, response_type: response_type)
|
|
216
|
+
end
|
|
217
|
+
define_method('teams') do |**params|
|
|
218
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
219
|
+
request('cricbuzz-teams', params, response_type: response_type)
|
|
220
|
+
end
|
|
221
|
+
define_method('video_categories') do |**params|
|
|
222
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
223
|
+
request('cricbuzz-video-categories', params, response_type: response_type)
|
|
224
|
+
end
|
|
225
|
+
define_method('video_playlists') do |**params|
|
|
226
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
227
|
+
request('cricbuzz-video-playlists', params, response_type: response_type)
|
|
228
|
+
end
|
|
229
|
+
define_method('wtc') do |**params|
|
|
230
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
231
|
+
request('cricbuzz-wtc', params, response_type: response_type)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
private
|
|
235
|
+
|
|
236
|
+
# POST operations take their JSON body under the body parameter name or "body".
|
|
237
|
+
def request_body(operation, params)
|
|
238
|
+
name = operation["bodyParam"]
|
|
239
|
+
return nil if name.nil?
|
|
240
|
+
value = params.key?(name) ? params[name] : params["body"]
|
|
241
|
+
if value.nil?
|
|
242
|
+
raise Errors::ClientError.new("missing request body: #{name}", operation_id: operation["id"]) if operation["bodyRequired"]
|
|
243
|
+
return nil
|
|
244
|
+
end
|
|
245
|
+
value.is_a?(String) ? value : JSON.generate(value)
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def build_url(operation, params)
|
|
249
|
+
known = operation["params"].map { |param| param["name"] }
|
|
250
|
+
known << "body" if operation["bodyParam"]
|
|
251
|
+
unknown = params.keys - known
|
|
252
|
+
raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
|
|
253
|
+
path = operation["path"].dup
|
|
254
|
+
operation["params"].select { |param| param["in"] == "path" }.each do |param|
|
|
255
|
+
value = params[param["name"]]
|
|
256
|
+
raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
|
|
257
|
+
path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
|
|
258
|
+
end
|
|
259
|
+
pairs = []
|
|
260
|
+
operation["queryParams"].each do |param|
|
|
261
|
+
name = param["name"]
|
|
262
|
+
value = params.key?(name) ? params[name] : param["default"]
|
|
263
|
+
if value.nil?
|
|
264
|
+
raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
|
|
265
|
+
next
|
|
266
|
+
end
|
|
267
|
+
enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
|
|
268
|
+
if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
|
|
269
|
+
raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
|
|
270
|
+
end
|
|
271
|
+
if value.is_a?(Array)
|
|
272
|
+
format = param["collectionFormat"] || "csv"
|
|
273
|
+
if format == "multi"
|
|
274
|
+
value.each { |item| pairs << [name, scalar(item)] }
|
|
275
|
+
else
|
|
276
|
+
separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
|
|
277
|
+
pairs << [name, value.map { |item| scalar(item) }.join(separator)]
|
|
278
|
+
end
|
|
279
|
+
else
|
|
280
|
+
pairs << [name, scalar(value)]
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
|
|
284
|
+
@base_url + path + (query.empty? ? "" : "?" + query)
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def scalar(value)
|
|
288
|
+
value == true ? "true" : (value == false ? "false" : value.to_s)
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def percent_encode(value)
|
|
292
|
+
URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
def parse_response(body, content_type, operation, params, response_type)
|
|
296
|
+
type = response_type.to_s
|
|
297
|
+
raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
|
|
298
|
+
format = operation["params"].find { |param| param["name"] == "format" }
|
|
299
|
+
text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
|
|
300
|
+
raw_format = params["format"] && text_formats.include?(params["format"].to_s)
|
|
301
|
+
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)
|
|
302
|
+
is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
|
|
303
|
+
return body if type == "text" || raw_format || (type == "auto" && !is_json)
|
|
304
|
+
JSON.parse(body)
|
|
305
|
+
rescue JSON::ParserError => error
|
|
306
|
+
raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
public
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: crawlora-cricbuzz
|
|
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-02 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Ruby client for Crawlora's hosted Cricbuzz API. Covers cricket matches,
|
|
14
|
+
schedules, news, rankings, series, and records across 29 endpoints.
|
|
15
|
+
email:
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- CHANGELOG.md
|
|
21
|
+
- LICENSE
|
|
22
|
+
- README.md
|
|
23
|
+
- lib/crawlora/cricbuzz.rb
|
|
24
|
+
- lib/crawlora/cricbuzz/client.rb
|
|
25
|
+
- lib/crawlora/cricbuzz/version.rb
|
|
26
|
+
homepage: https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=cricbuzz-ruby-homepage
|
|
27
|
+
licenses:
|
|
28
|
+
- MIT
|
|
29
|
+
metadata:
|
|
30
|
+
source_code_uri: https://github.com/Crawlora-org/crawlora-cricbuzz
|
|
31
|
+
documentation_uri: https://github.com/Crawlora-org/crawlora-cricbuzz/blob/main/ruby/README.md
|
|
32
|
+
rubygems_mfa_required: 'true'
|
|
33
|
+
post_install_message:
|
|
34
|
+
rdoc_options: []
|
|
35
|
+
require_paths:
|
|
36
|
+
- lib
|
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '2.6'
|
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
requirements: []
|
|
48
|
+
rubygems_version: 3.4.19
|
|
49
|
+
signing_key:
|
|
50
|
+
specification_version: 4
|
|
51
|
+
summary: Cricbuzz API client for Crawlora (29 endpoints)
|
|
52
|
+
test_files: []
|