crawlora-dramabox 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 +56 -0
- data/lib/crawlora/dramabox/client.rb +260 -0
- data/lib/crawlora/dramabox/version.rb +5 -0
- data/lib/crawlora/dramabox.rb +2 -0
- metadata +53 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 84160d922e5b7ceab55d843d66ed41b6a7c204793b1e682d6376c2d61494d187
|
|
4
|
+
data.tar.gz: d1da97bf517cb16607a84c521a4902331084b2d994ffd3973ee78de5d724d6e7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d2d59ce3d7796c3c1c12d8e0b8aabfbc5ddf4ba2a10a33d5baf4a627360038961e5ce062fdfa959b6a31a17b04e9454227b676d48c83a2f1503b79e8c1ba9466
|
|
7
|
+
data.tar.gz: 42d15e1ebc3886e4c802b2a88171105e865067882c26f640c7aed75bb59a1c3124d4c9633c4f3d19079da2a3e62120f5b4344f4263fefb1f4680bdd16d6ab31f
|
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,56 @@
|
|
|
1
|
+
# Crawlora DramaBox API client for Ruby (`crawlora-dramabox`)
|
|
2
|
+
|
|
3
|
+
This Ruby gem calls Crawlora's hosted DramaBox API at `https://api.crawlora.net/api/v1`. It exposes 16 endpoints covering title discovery, categories, search, rankings, recommendations, and public title details; it does not call or scrape DramaBox directly. Requests require your Crawlora API key and use your account's service plan.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem "crawlora-dramabox"
|
|
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=dramabox-ruby-signup), open the [Crawlora console](https://crawlora.net/app?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=dramabox-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/dramabox"
|
|
16
|
+
|
|
17
|
+
client = Crawlora::Dramabox::Client.new
|
|
18
|
+
result = client.request("dramabox-search", JSON.parse("{\"keyword\": \"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 16 API operations.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
client = Crawlora::Dramabox::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 DramaBox API endpoints
|
|
34
|
+
|
|
35
|
+
Browse every route included in this gem. The [endpoint reference](https://github.com/Crawlora-org/crawlora-dramabox/blob/main/docs/usage.md) includes parameter and response details.
|
|
36
|
+
|
|
37
|
+
| Method | Endpoint | API operation | Description |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| `GET` | `/dramabox/browse` | `dramabox-browse` | Browse DramaBox short dramas by genre |
|
|
40
|
+
| `GET` | `/dramabox/categories` | `dramabox-categories` | List DramaBox category filters |
|
|
41
|
+
| `GET` | `/dramabox/category-books` | `dramabox-category-books` | Browse DramaBox titles by category |
|
|
42
|
+
| `GET` | `/dramabox/channels` | `dramabox-channels` | List DramaBox theater channels |
|
|
43
|
+
| `GET` | `/dramabox/drama` | `dramabox-drama` | Get a DramaBox short drama and its episodes |
|
|
44
|
+
| `GET` | `/dramabox/genres` | `dramabox-genres` | List DramaBox genres |
|
|
45
|
+
| `GET` | `/dramabox/home` | `dramabox-home` | List DramaBox's featured titles and shelves |
|
|
46
|
+
| `GET` | `/dramabox/more` | `dramabox-more` | Get a whole DramaBox curated shelf |
|
|
47
|
+
| `GET` | `/dramabox/performer` | `dramabox-performer` | Get a DramaBox performer and their titles |
|
|
48
|
+
| `GET` | `/dramabox/rank` | `dramabox-rank` | Get a DramaBox ranking list |
|
|
49
|
+
| `GET` | `/dramabox/recommend` | `dramabox-recommend` | Get a page of DramaBox's recommendation feed |
|
|
50
|
+
| `GET` | `/dramabox/search` | `dramabox-search` | Search DramaBox titles and performers |
|
|
51
|
+
| `GET` | `/dramabox/suggest` | `dramabox-suggest` | Get DramaBox search-box suggestions |
|
|
52
|
+
| `GET` | `/dramabox/tag` | `dramabox-tag` | List the DramaBox titles carrying a tag |
|
|
53
|
+
| `GET` | `/dramabox/theater` | `dramabox-theater` | Get a DramaBox theater channel feed |
|
|
54
|
+
| `GET` | `/dramabox/trending` | `dramabox-trending` | Get DramaBox's search landing feeds |
|
|
55
|
+
|
|
56
|
+
See [Crawlora](https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=dramabox-ruby-homepage), the [API documentation](https://crawlora.net/docs?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=dramabox-ruby-api-docs), and [the package repository](https://github.com/Crawlora-org/crawlora-dramabox) for account setup, the API operation reference, and release history.
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Crawlora
|
|
6
|
+
module Dramabox
|
|
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
|
+
{"dramabox-browse": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-browse", "method": "GET", "params": [{"description": "Genre id from dramabox-genres; 0 or omitted browses all titles", "in": "query", "name": "genre_id", "type": "integer", "x-example": 161}, {"description": "Page number, 1 to 1000; defaults to 1. Each page holds 12 titles", "in": "query", "name": "page", "type": "integer", "x-example": 2}, {"description": "Site locale, one of: en, ko, zhHans, zh, es, ja, de, in, th, tl, pt, fr, ar, it (in is Indonesian); defaults to en. Each locale has its own title library", "enum": ["en", "ko", "zhHans", "zh", "es", "ja", "de", "in", "th", "tl", "pt", "fr", "ar", "it"], "in": "query", "name": "language", "type": "string", "x-example": "ja"}], "path": "/dramabox/browse", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "genre_id", "type": "integer"}, {"in": "query", "name": "page", "type": "integer"}, {"enum": ["en", "ko", "zhHans", "zh", "es", "ja", "de", "in", "th", "tl", "pt", "fr", "ar", "it"], "in": "query", "name": "language", "type": "string"}], "security": ["ApiKeyAuth"]}, "dramabox-categories": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-categories", "method": "GET", "params": [], "path": "/dramabox/categories", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "dramabox-category-books": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-category-books", "method": "GET", "params": [{"description": "Language/origin value from dramabox-categories' language group, e.g. 美国 (Local) or 中国 (Chinese)", "in": "query", "name": "language", "type": "string", "x-example": "美国"}, {"description": "Production-type value from dramabox-categories' production group: 3 (AI Drama), 1 (Live-Action), 2 (Anime)", "enum": ["3", "1", "2"], "in": "query", "name": "production", "type": "string", "x-example": "1"}, {"description": "Dub-mode value from dramabox-categories' dub group: 1 (Dubbed), 0 (Subtitles Only)", "enum": ["1", "0"], "in": "query", "name": "dub", "type": "string", "x-example": "1"}, {"description": "Genre value from dramabox-categories' genre_1 group, e.g. 1357 (Romance) or 1361 (Strong Heroine)", "in": "query", "name": "genre", "type": "string", "x-example": "1357"}, {"description": "Genre value from dramabox-categories' genre_2 group, e.g. 1392 (Second Chance) or 1359 (BL); multi-tag values such as 1324,1362 are one value", "in": "query", "name": "genre_2", "type": "string", "x-example": "1392"}, {"description": "Sort value from dramabox-categories' sort group: 1 (Trending), 2 (Latest), 3 (Unwatched)", "enum": ["1", "2", "3"], "in": "query", "name": "sort", "type": "string", "x-example": "1"}, {"description": "Page number, 1 to 1000; defaults to 1", "in": "query", "name": "page", "type": "integer", "x-example": 1}, {"description": "Titles per page, 1 to 50; defaults to 20", "in": "query", "name": "limit", "type": "integer", "x-example": 20}], "path": "/dramabox/category-books", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "language", "type": "string"}, {"enum": ["3", "1", "2"], "in": "query", "name": "production", "type": "string"}, {"enum": ["1", "0"], "in": "query", "name": "dub", "type": "string"}, {"in": "query", "name": "genre", "type": "string"}, {"in": "query", "name": "genre_2", "type": "string"}, {"enum": ["1", "2", "3"], "in": "query", "name": "sort", "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "dramabox-channels": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-channels", "method": "GET", "params": [], "path": "/dramabox/channels", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "dramabox-drama": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-drama", "method": "GET", "params": [{"description": "Title id (digits) from any DramaBox list, or a dramabox.com drama URL", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "42000028173"}], "path": "/dramabox/drama", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "dramabox-genres": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-genres", "method": "GET", "params": [{"description": "Site locale, one of: en, ko, zhHans, zh, es, ja, de, in, th, tl, pt, fr, ar, it (in is Indonesian); defaults to en. Each locale has its own title library", "enum": ["en", "ko", "zhHans", "zh", "es", "ja", "de", "in", "th", "tl", "pt", "fr", "ar", "it"], "in": "query", "name": "language", "type": "string", "x-example": "ja"}], "path": "/dramabox/genres", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["en", "ko", "zhHans", "zh", "es", "ja", "de", "in", "th", "tl", "pt", "fr", "ar", "it"], "in": "query", "name": "language", "type": "string"}], "security": ["ApiKeyAuth"]}, "dramabox-home": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-home", "method": "GET", "params": [{"description": "Site locale, one of: en, ko, zhHans, zh, es, ja, de, in, th, tl, pt, fr, ar, it (in is Indonesian); defaults to en. Each locale has its own title library", "enum": ["en", "ko", "zhHans", "zh", "es", "ja", "de", "in", "th", "tl", "pt", "fr", "ar", "it"], "in": "query", "name": "language", "type": "string", "x-example": "ja"}], "path": "/dramabox/home", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["en", "ko", "zhHans", "zh", "es", "ja", "de", "in", "th", "tl", "pt", "fr", "ar", "it"], "in": "query", "name": "language", "type": "string"}], "security": ["ApiKeyAuth"]}, "dramabox-more": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-more", "method": "GET", "params": [{"description": "Curated shelf: trending, must-sees or hidden-gems", "enum": ["trending", "must-sees", "hidden-gems"], "in": "query", "name": "position", "required": true, "type": "string", "x-example": "trending"}, {"description": "Page number, 1 to 1000; defaults to 1. Each page holds 18 titles", "in": "query", "name": "page", "type": "integer", "x-example": 2}, {"description": "Site locale, one of: en, ko, zhHans, zh, es, ja, de, in, th, tl, pt, fr, ar, it (in is Indonesian); defaults to en. Each locale has its own title library", "enum": ["en", "ko", "zhHans", "zh", "es", "ja", "de", "in", "th", "tl", "pt", "fr", "ar", "it"], "in": "query", "name": "language", "type": "string", "x-example": "ja"}], "path": "/dramabox/more", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["trending", "must-sees", "hidden-gems"], "in": "query", "name": "position", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"enum": ["en", "ko", "zhHans", "zh", "es", "ja", "de", "in", "th", "tl", "pt", "fr", "ar", "it"], "in": "query", "name": "language", "type": "string"}], "security": ["ApiKeyAuth"]}, "dramabox-performer": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-performer", "method": "GET", "params": [{"description": "Performer id from dramabox-search or dramabox-suggest's people results", "in": "query", "name": "performer_id", "required": true, "type": "integer", "x-example": 29450}, {"description": "Page number, 1 to 1000; defaults to 1", "in": "query", "name": "page", "type": "integer", "x-example": 1}, {"description": "Page size, 1 to 20; defaults to 10", "in": "query", "name": "limit", "type": "integer", "x-example": 10}], "path": "/dramabox/performer", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "performer_id", "required": true, "type": "integer"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "dramabox-rank": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-rank", "method": "GET", "params": [{"description": "Ranking tab: 1 (Most Trending), 2 (Top Searched), 3 (New Releases); omit for the default tab", "enum": [1, 2, 3], "in": "query", "name": "rank_type", "type": "integer", "x-example": 2}], "path": "/dramabox/rank", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["1", "2", "3"], "in": "query", "name": "rank_type", "type": "integer"}], "security": ["ApiKeyAuth"]}, "dramabox-recommend": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-recommend", "method": "GET", "params": [{"description": "Page number, 1 to 1000; defaults to 1", "in": "query", "name": "page", "type": "integer", "x-example": 1}], "path": "/dramabox/recommend", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "dramabox-search": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-search", "method": "GET", "params": [{"description": "Search text, trimmed and truncated to 80 characters", "in": "query", "name": "keyword", "required": true, "type": "string", "x-example": "love"}, {"default": 1, "description": "One-based result page", "in": "query", "maximum": 1000, "minimum": 1, "name": "page", "type": "integer"}, {"default": 20, "description": "Results per page", "in": "query", "maximum": 50, "minimum": 1, "name": "limit", "type": "integer"}, {"description": "Upstream result ordering mode; omit for the app default", "enum": [1, 2, 3], "in": "query", "name": "sort", "type": "integer", "x-example": 1}], "path": "/dramabox/search", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "keyword", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "limit", "type": "integer"}, {"enum": ["1", "2", "3"], "in": "query", "name": "sort", "type": "integer"}], "security": ["ApiKeyAuth"]}, "dramabox-suggest": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-suggest", "method": "GET", "params": [{"description": "Partial search text, trimmed and truncated to 80 characters", "in": "query", "name": "keyword", "required": true, "type": "string", "x-example": "lov"}], "path": "/dramabox/suggest", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "keyword", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "dramabox-tag": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-tag", "method": "GET", "params": [{"description": "Tag id from any title result's tag_refs", "in": "query", "name": "tag_id", "required": true, "type": "integer", "x-example": 1379}, {"description": "Page number, 1 to 1000; defaults to 1", "in": "query", "name": "page", "type": "integer", "x-example": 1}, {"description": "Page size, 1 to 50; defaults to 20", "in": "query", "name": "limit", "type": "integer", "x-example": 20}], "path": "/dramabox/tag", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "tag_id", "required": true, "type": "integer"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "dramabox-theater": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-theater", "method": "GET", "params": [{"description": "Theater channel: popular, new, rankings, categories, anime, live-action, vip or original", "enum": ["popular", "new", "rankings", "categories", "anime", "live-action", "vip", "original"], "in": "query", "name": "channel", "required": true, "type": "string", "x-example": "popular"}, {"description": "Page number, 1 to 1000; defaults to 1", "in": "query", "name": "page", "type": "integer", "x-example": 1}, {"description": "Titles per paged block, 1 to 20; defaults to 10", "in": "query", "name": "limit", "type": "integer", "x-example": 10}], "path": "/dramabox/theater", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["popular", "new", "rankings", "categories", "anime", "live-action", "vip", "original"], "in": "query", "name": "channel", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "dramabox-trending": {"bodyParam": null, "bodyRequired": false, "id": "dramabox-trending", "method": "GET", "params": [], "path": "/dramabox/trending", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}}
|
|
23
|
+
JSON
|
|
24
|
+
OPERATION_IDS = JSON.parse(<<~'JSON').freeze
|
|
25
|
+
["dramabox-browse", "dramabox-categories", "dramabox-category-books", "dramabox-channels", "dramabox-drama", "dramabox-genres", "dramabox-home", "dramabox-more", "dramabox-performer", "dramabox-rank", "dramabox-recommend", "dramabox-search", "dramabox-suggest", "dramabox-tag", "dramabox-theater", "dramabox-trending"]
|
|
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-dramabox-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('browse') do |**params|
|
|
118
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
119
|
+
request('dramabox-browse', params, response_type: response_type)
|
|
120
|
+
end
|
|
121
|
+
define_method('categories') do |**params|
|
|
122
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
123
|
+
request('dramabox-categories', params, response_type: response_type)
|
|
124
|
+
end
|
|
125
|
+
define_method('category_books') do |**params|
|
|
126
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
127
|
+
request('dramabox-category-books', params, response_type: response_type)
|
|
128
|
+
end
|
|
129
|
+
define_method('channels') do |**params|
|
|
130
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
131
|
+
request('dramabox-channels', params, response_type: response_type)
|
|
132
|
+
end
|
|
133
|
+
define_method('drama') do |**params|
|
|
134
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
135
|
+
request('dramabox-drama', params, response_type: response_type)
|
|
136
|
+
end
|
|
137
|
+
define_method('genres') do |**params|
|
|
138
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
139
|
+
request('dramabox-genres', params, response_type: response_type)
|
|
140
|
+
end
|
|
141
|
+
define_method('home') do |**params|
|
|
142
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
143
|
+
request('dramabox-home', params, response_type: response_type)
|
|
144
|
+
end
|
|
145
|
+
define_method('more') do |**params|
|
|
146
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
147
|
+
request('dramabox-more', params, response_type: response_type)
|
|
148
|
+
end
|
|
149
|
+
define_method('performer') do |**params|
|
|
150
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
151
|
+
request('dramabox-performer', params, response_type: response_type)
|
|
152
|
+
end
|
|
153
|
+
define_method('rank') do |**params|
|
|
154
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
155
|
+
request('dramabox-rank', params, response_type: response_type)
|
|
156
|
+
end
|
|
157
|
+
define_method('recommend') do |**params|
|
|
158
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
159
|
+
request('dramabox-recommend', params, response_type: response_type)
|
|
160
|
+
end
|
|
161
|
+
define_method('search') do |**params|
|
|
162
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
163
|
+
request('dramabox-search', params, response_type: response_type)
|
|
164
|
+
end
|
|
165
|
+
define_method('suggest') do |**params|
|
|
166
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
167
|
+
request('dramabox-suggest', params, response_type: response_type)
|
|
168
|
+
end
|
|
169
|
+
define_method('tag') do |**params|
|
|
170
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
171
|
+
request('dramabox-tag', params, response_type: response_type)
|
|
172
|
+
end
|
|
173
|
+
define_method('theater') do |**params|
|
|
174
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
175
|
+
request('dramabox-theater', params, response_type: response_type)
|
|
176
|
+
end
|
|
177
|
+
define_method('trending') do |**params|
|
|
178
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
179
|
+
request('dramabox-trending', params, response_type: response_type)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
private
|
|
183
|
+
|
|
184
|
+
# POST operations take their JSON body under the body parameter name or "body".
|
|
185
|
+
def request_body(operation, params)
|
|
186
|
+
name = operation["bodyParam"]
|
|
187
|
+
return nil if name.nil?
|
|
188
|
+
value = params.key?(name) ? params[name] : params["body"]
|
|
189
|
+
if value.nil?
|
|
190
|
+
raise Errors::ClientError.new("missing request body: #{name}", operation_id: operation["id"]) if operation["bodyRequired"]
|
|
191
|
+
return nil
|
|
192
|
+
end
|
|
193
|
+
value.is_a?(String) ? value : JSON.generate(value)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def build_url(operation, params)
|
|
197
|
+
known = operation["params"].map { |param| param["name"] }
|
|
198
|
+
known << "body" if operation["bodyParam"]
|
|
199
|
+
unknown = params.keys - known
|
|
200
|
+
raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
|
|
201
|
+
path = operation["path"].dup
|
|
202
|
+
operation["params"].select { |param| param["in"] == "path" }.each do |param|
|
|
203
|
+
value = params[param["name"]]
|
|
204
|
+
raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
|
|
205
|
+
path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
|
|
206
|
+
end
|
|
207
|
+
pairs = []
|
|
208
|
+
operation["queryParams"].each do |param|
|
|
209
|
+
name = param["name"]
|
|
210
|
+
value = params.key?(name) ? params[name] : param["default"]
|
|
211
|
+
if value.nil?
|
|
212
|
+
raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
|
|
213
|
+
next
|
|
214
|
+
end
|
|
215
|
+
enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
|
|
216
|
+
if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
|
|
217
|
+
raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
|
|
218
|
+
end
|
|
219
|
+
if value.is_a?(Array)
|
|
220
|
+
format = param["collectionFormat"] || "csv"
|
|
221
|
+
if format == "multi"
|
|
222
|
+
value.each { |item| pairs << [name, scalar(item)] }
|
|
223
|
+
else
|
|
224
|
+
separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
|
|
225
|
+
pairs << [name, value.map { |item| scalar(item) }.join(separator)]
|
|
226
|
+
end
|
|
227
|
+
else
|
|
228
|
+
pairs << [name, scalar(value)]
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
|
|
232
|
+
@base_url + path + (query.empty? ? "" : "?" + query)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
def scalar(value)
|
|
236
|
+
value == true ? "true" : (value == false ? "false" : value.to_s)
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def percent_encode(value)
|
|
240
|
+
URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def parse_response(body, content_type, operation, params, response_type)
|
|
244
|
+
type = response_type.to_s
|
|
245
|
+
raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
|
|
246
|
+
format = operation["params"].find { |param| param["name"] == "format" }
|
|
247
|
+
text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
|
|
248
|
+
raw_format = params["format"] && text_formats.include?(params["format"].to_s)
|
|
249
|
+
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)
|
|
250
|
+
is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
|
|
251
|
+
return body if type == "text" || raw_format || (type == "auto" && !is_json)
|
|
252
|
+
JSON.parse(body)
|
|
253
|
+
rescue JSON::ParserError => error
|
|
254
|
+
raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
public
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: crawlora-dramabox
|
|
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-10-30 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Ruby client for Crawlora's hosted DramaBox API. Covers title discovery,
|
|
14
|
+
categories, search, rankings, recommendations, and public title details across 16
|
|
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/dramabox.rb
|
|
25
|
+
- lib/crawlora/dramabox/client.rb
|
|
26
|
+
- lib/crawlora/dramabox/version.rb
|
|
27
|
+
homepage: https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=dramabox-ruby-homepage
|
|
28
|
+
licenses:
|
|
29
|
+
- MIT
|
|
30
|
+
metadata:
|
|
31
|
+
source_code_uri: https://github.com/Crawlora-org/crawlora-dramabox
|
|
32
|
+
documentation_uri: https://github.com/Crawlora-org/crawlora-dramabox/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: DramaBox API client for Crawlora (16 endpoints)
|
|
53
|
+
test_files: []
|