crawlora-kick 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 +61 -0
- data/lib/crawlora/kick/client.rb +280 -0
- data/lib/crawlora/kick/version.rb +5 -0
- data/lib/crawlora/kick.rb +2 -0
- metadata +52 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ca501940ce8ee79db069685afc97a601b9c5fbcdd2c368189e18eff8fdc9fe77
|
|
4
|
+
data.tar.gz: dbf581bda3798fb40426c35f394ef8cda364930d8b974e2c5250e8770fc9b720
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 01da32e303154d5c676be212e6d16f43f96b380bdad32becedef469ed2d8c246f98aeee4cf68254506e7ddde5c0d6b3ab0b823be04af42f255bc735a17e1b299
|
|
7
|
+
data.tar.gz: 61a96fdbe3886a995c4f220b9f3842d638dfe06eb96cf681bc327209041bc905e57c4d4ce1af8eeee73e580cb6132ebc011a82631ea0810bb0d1701a791774a5
|
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,61 @@
|
|
|
1
|
+
# Crawlora Kick API client for Ruby (`crawlora-kick`)
|
|
2
|
+
|
|
3
|
+
This Ruby gem calls Crawlora's hosted Kick API at `https://api.crawlora.net/api/v1`. It exposes 21 endpoints covering channels, livestreams, clips, categories, search, and public mobile-app catalogues; it does not call or scrape Kick directly. Requests require your Crawlora API key and use your account's service plan.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem "crawlora-kick"
|
|
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=kick-ruby-signup), open the [Crawlora console](https://crawlora.net/app?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=kick-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/kick"
|
|
16
|
+
|
|
17
|
+
client = Crawlora::Kick::Client.new
|
|
18
|
+
result = client.request("kick-categories", JSON.parse("{}"))
|
|
19
|
+
puts result
|
|
20
|
+
client.close
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Use an operation-specific method for normal calls. `request(operation_id, params = {}, response_type: :auto)` is available for every operation. `response_type: :text` returns raw response text. This gem includes 21 API operations.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
client = Crawlora::Kick::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 Kick API endpoints
|
|
34
|
+
|
|
35
|
+
Browse every route included in this gem. The [endpoint reference](https://github.com/Crawlora-org/crawlora-kick/blob/main/docs/usage.md) includes parameter and response details.
|
|
36
|
+
|
|
37
|
+
| Method | Endpoint | API operation | Description |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| `GET` | `/kick/categories` | `kick-categories` | List Kick's top-level categories |
|
|
40
|
+
| `GET` | `/kick/category-clips` | `kick-category-clips` | List the newest clips in a Kick category |
|
|
41
|
+
| `GET` | `/kick/channel` | `kick-channel` | Get a Kick channel profile and live state |
|
|
42
|
+
| `GET` | `/kick/channel-chatroom` | `kick-channel-chatroom` | Get a Kick channel's chat settings and rules |
|
|
43
|
+
| `GET` | `/kick/channel-clips` | `kick-channel-clips` | List a Kick channel's clips |
|
|
44
|
+
| `GET` | `/kick/channel-emotes` | `kick-channel-emotes` | List the chat emotes a Kick channel offers |
|
|
45
|
+
| `GET` | `/kick/channel-links` | `kick-channel-links` | List a Kick channel's link panels |
|
|
46
|
+
| `GET` | `/kick/channel-streams` | `kick-channel-streams` | List a Kick channel's recent broadcast history |
|
|
47
|
+
| `GET` | `/kick/channel-videos` | `kick-channel-videos` | List a Kick channel's recent past broadcasts |
|
|
48
|
+
| `GET` | `/kick/clip` | `kick-clip` | Get one Kick clip |
|
|
49
|
+
| `GET` | `/kick/clips` | `kick-clips` | List Kick's site-wide clips |
|
|
50
|
+
| `GET` | `/kick/drops` | `kick-drops` | List Kick Drops campaigns |
|
|
51
|
+
| `GET` | `/kick/gifts` | `kick-gifts` | List the gifts viewers can send on Kick |
|
|
52
|
+
| `GET` | `/kick/languages` | `kick-languages` | List Kick stream languages |
|
|
53
|
+
| `GET` | `/kick/livestreams` | `kick-livestreams` | List live broadcasts on Kick |
|
|
54
|
+
| `GET` | `/kick/search-categories` | `kick-search-categories` | Search Kick categories |
|
|
55
|
+
| `GET` | `/kick/search-channels` | `kick-search-channels` | Search Kick channels |
|
|
56
|
+
| `GET` | `/kick/subcategories` | `kick-subcategories` | List Kick's game and activity categories |
|
|
57
|
+
| `GET` | `/kick/subcategory` | `kick-subcategory` | Get one Kick category |
|
|
58
|
+
| `GET` | `/kick/top-channels` | `kick-top-channels` | List Kick's top channels |
|
|
59
|
+
| `GET` | `/kick/video` | `kick-video` | Get a Kick video by its uuid |
|
|
60
|
+
|
|
61
|
+
See [Crawlora](https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=kick-ruby-homepage), the [API documentation](https://crawlora.net/docs?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=kick-ruby-api-docs), and [the package repository](https://github.com/Crawlora-org/crawlora-kick) for account setup, the API operation reference, and release history.
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Crawlora
|
|
6
|
+
module Kick
|
|
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
|
+
{"kick-categories": {"bodyParam": null, "bodyRequired": false, "id": "kick-categories", "method": "GET", "params": [], "path": "/kick/categories", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "kick-category-clips": {"bodyParam": null, "bodyRequired": false, "id": "kick-category-clips", "method": "GET", "params": [{"description": "Category slug from kick-subcategories or kick-search-categories, lowercase; a kick.com/category URL is also accepted", "in": "query", "name": "slug", "required": true, "type": "string", "x-example": "just-chatting"}, {"description": "Previous response's next_cursor; omit for the newest page", "in": "query", "name": "cursor", "type": "string", "x-example": "clip_01M5TR7FRZPCDA6BS1NP7HKV4T"}], "path": "/kick/category-clips", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "slug", "required": true, "type": "string"}, {"in": "query", "name": "cursor", "type": "string"}], "security": ["ApiKeyAuth"]}, "kick-channel": {"bodyParam": null, "bodyRequired": false, "id": "kick-channel", "method": "GET", "params": [{"description": "Channel slug from kick.com/{slug}, case-insensitive; a kick.com URL is also accepted", "in": "query", "name": "slug", "required": true, "type": "string", "x-example": "xqc"}], "path": "/kick/channel", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "slug", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "kick-channel-chatroom": {"bodyParam": null, "bodyRequired": false, "id": "kick-channel-chatroom", "method": "GET", "params": [{"description": "Channel slug from kick.com/{slug}, case-insensitive; a kick.com URL is also accepted", "in": "query", "name": "slug", "required": true, "type": "string", "x-example": "xqc"}], "path": "/kick/channel-chatroom", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "slug", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "kick-channel-clips": {"bodyParam": null, "bodyRequired": false, "id": "kick-channel-clips", "method": "GET", "params": [{"description": "Channel slug from kick.com/{slug}, case-insensitive; a kick.com URL is also accepted", "in": "query", "name": "slug", "required": true, "type": "string", "x-example": "xqc"}, {"description": "Previous response's next_cursor; omit for the newest page", "in": "query", "name": "cursor", "type": "string", "x-example": "abc"}], "path": "/kick/channel-clips", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "slug", "required": true, "type": "string"}, {"in": "query", "name": "cursor", "type": "string"}], "security": ["ApiKeyAuth"]}, "kick-channel-emotes": {"bodyParam": null, "bodyRequired": false, "id": "kick-channel-emotes", "method": "GET", "params": [{"description": "Channel slug from kick.com/{slug}, case-insensitive; a kick.com URL is also accepted", "in": "query", "name": "slug", "required": true, "type": "string", "x-example": "xqc"}], "path": "/kick/channel-emotes", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "slug", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "kick-channel-links": {"bodyParam": null, "bodyRequired": false, "id": "kick-channel-links", "method": "GET", "params": [{"description": "Channel slug from kick.com/{slug}, case-insensitive; a kick.com URL is also accepted", "in": "query", "name": "slug", "required": true, "type": "string", "x-example": "xqc"}], "path": "/kick/channel-links", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "slug", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "kick-channel-streams": {"bodyParam": null, "bodyRequired": false, "id": "kick-channel-streams", "method": "GET", "params": [{"description": "Channel slug from kick.com/{slug}, case-insensitive; a kick.com URL is also accepted", "in": "query", "name": "slug", "required": true, "type": "string", "x-example": "xqc"}], "path": "/kick/channel-streams", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "slug", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "kick-channel-videos": {"bodyParam": null, "bodyRequired": false, "id": "kick-channel-videos", "method": "GET", "params": [{"description": "Channel slug from kick.com/{slug}, case-insensitive; a kick.com URL is also accepted", "in": "query", "name": "slug", "required": true, "type": "string", "x-example": "xqc"}], "path": "/kick/channel-videos", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "slug", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "kick-clip": {"bodyParam": null, "bodyRequired": false, "id": "kick-clip", "method": "GET", "params": [{"description": "Clip id from kick-clips' or kick-channel-clips' own clips[].id field", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "clip_01M5SKVA6GGAAAT5YPJ7J43WE4"}], "path": "/kick/clip", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "kick-clips": {"bodyParam": null, "bodyRequired": false, "id": "kick-clips", "method": "GET", "params": [{"description": "Ordering: date is newest first (default), views ranks by views inside the time window", "enum": ["date", "views"], "in": "query", "name": "sort", "type": "string", "x-example": "views"}, {"description": "Window that views ranks within; omit for Kick's default window", "enum": ["day", "week", "month", "all"], "in": "query", "name": "time", "type": "string", "x-example": "week"}, {"description": "Previous response's next_cursor; omit for the first page", "in": "query", "name": "cursor", "type": "string", "x-example": "abc"}], "path": "/kick/clips", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["date", "views"], "in": "query", "name": "sort", "type": "string"}, {"enum": ["day", "week", "month", "all"], "in": "query", "name": "time", "type": "string"}, {"in": "query", "name": "cursor", "type": "string"}], "security": ["ApiKeyAuth"]}, "kick-drops": {"bodyParam": null, "bodyRequired": false, "id": "kick-drops", "method": "GET", "params": [{"description": "Which campaigns to return: active (default), expired or all", "enum": ["active", "expired", "all"], "in": "query", "name": "status", "type": "string", "x-example": "active"}], "path": "/kick/drops", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["active", "expired", "all"], "in": "query", "name": "status", "type": "string"}], "security": ["ApiKeyAuth"]}, "kick-gifts": {"bodyParam": null, "bodyRequired": false, "id": "kick-gifts", "method": "GET", "params": [], "path": "/kick/gifts", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "kick-languages": {"bodyParam": null, "bodyRequired": false, "id": "kick-languages", "method": "GET", "params": [], "path": "/kick/languages", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "kick-livestreams": {"bodyParam": null, "bodyRequired": false, "id": "kick-livestreams", "method": "GET", "params": [{"description": "Ordering: viewer_count_desc is most viewers first (default), featured is Kick's featured order", "enum": ["viewer_count_desc", "featured"], "in": "query", "name": "sort", "type": "string", "x-example": "viewer_count_desc"}, {"description": "Stream language code such as en, ja, es, pt-BR, optionally with a region (2 to 3 letters, then an optional 2 to 4 letter region); see kick-languages for the codes Kick lists", "in": "query", "name": "language", "type": "string", "x-example": "ja"}, {"description": "Category id from kick-subcategories' or kick-search-categories' own id field", "in": "query", "name": "category_id", "type": "integer", "x-example": 15}, {"description": "Page size, 1 to 100; defaults to 24", "in": "query", "name": "limit", "type": "integer", "x-example": 24}, {"description": "Previous response's next_cursor; omit for the first page", "in": "query", "name": "after", "type": "string", "x-example": "eyJvIjoxfQ"}], "path": "/kick/livestreams", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["viewer_count_desc", "featured"], "in": "query", "name": "sort", "type": "string"}, {"in": "query", "name": "language", "type": "string"}, {"in": "query", "name": "category_id", "type": "integer"}, {"in": "query", "name": "limit", "type": "integer"}, {"in": "query", "name": "after", "type": "string"}], "security": ["ApiKeyAuth"]}, "kick-search-categories": {"bodyParam": null, "bodyRequired": false, "id": "kick-search-categories", "method": "GET", "params": [{"description": "Category name to search for, up to 100 characters", "in": "query", "name": "query", "required": true, "type": "string", "x-example": "chat"}, {"description": "Maximum results, 1 to 100; defaults to 10", "in": "query", "name": "limit", "type": "integer", "x-example": 10}], "path": "/kick/search-categories", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "query", "required": true, "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "kick-search-channels": {"bodyParam": null, "bodyRequired": false, "id": "kick-search-channels", "method": "GET", "params": [{"description": "Channel name to search for, up to 100 characters", "in": "query", "name": "query", "required": true, "type": "string", "x-example": "xqc"}, {"description": "Only channels live now", "in": "query", "name": "live", "type": "boolean", "x-example": true}, {"description": "Maximum results, 1 to 100; defaults to 10", "in": "query", "name": "limit", "type": "integer", "x-example": 10}], "path": "/kick/search-channels", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "query", "required": true, "type": "string"}, {"in": "query", "name": "live", "type": "boolean"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "kick-subcategories": {"bodyParam": null, "bodyRequired": false, "id": "kick-subcategories", "method": "GET", "params": [{"description": "Top-level category slug from kick-categories; a parent Kick adds later is also accepted once it appears there", "enum": ["games", "irl", "music", "gambling", "creative", "alternative", "chat-roulette"], "in": "query", "name": "category", "type": "string", "x-example": "irl"}, {"description": "Page number, 1 to 20; defaults to 1", "in": "query", "name": "page", "type": "integer", "x-example": 1}, {"description": "Page size, 1 to 32; defaults to 24", "in": "query", "name": "limit", "type": "integer", "x-example": 10}], "path": "/kick/subcategories", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["games", "irl", "music", "gambling", "creative", "alternative", "chat-roulette"], "in": "query", "name": "category", "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "kick-subcategory": {"bodyParam": null, "bodyRequired": false, "id": "kick-subcategory", "method": "GET", "params": [{"description": "Category slug from kick-subcategories' or kick-search-categories' own slug field", "in": "query", "name": "slug", "required": true, "type": "string", "x-example": "just-chatting"}], "path": "/kick/subcategory", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "slug", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "kick-top-channels": {"bodyParam": null, "bodyRequired": false, "id": "kick-top-channels", "method": "GET", "params": [], "path": "/kick/top-channels", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "kick-video": {"bodyParam": null, "bodyRequired": false, "id": "kick-video", "method": "GET", "params": [{"description": "Video uuid (36 characters) from kick-channel-videos or kick-channel-streams, or a kick.com video URL", "in": "query", "name": "id", "required": true, "type": "string", "x-example": "eb707c31-208b-4737-8bcf-a5c9fd187e82"}], "path": "/kick/video", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "id", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}}
|
|
23
|
+
JSON
|
|
24
|
+
OPERATION_IDS = JSON.parse(<<~'JSON').freeze
|
|
25
|
+
["kick-categories", "kick-category-clips", "kick-channel", "kick-channel-chatroom", "kick-channel-clips", "kick-channel-emotes", "kick-channel-links", "kick-channel-streams", "kick-channel-videos", "kick-clip", "kick-clips", "kick-drops", "kick-gifts", "kick-languages", "kick-livestreams", "kick-search-categories", "kick-search-channels", "kick-subcategories", "kick-subcategory", "kick-top-channels", "kick-video"]
|
|
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-kick-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('categories') do |**params|
|
|
118
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
119
|
+
request('kick-categories', params, response_type: response_type)
|
|
120
|
+
end
|
|
121
|
+
define_method('category_clips') do |**params|
|
|
122
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
123
|
+
request('kick-category-clips', params, response_type: response_type)
|
|
124
|
+
end
|
|
125
|
+
define_method('channel') do |**params|
|
|
126
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
127
|
+
request('kick-channel', params, response_type: response_type)
|
|
128
|
+
end
|
|
129
|
+
define_method('channel_chatroom') do |**params|
|
|
130
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
131
|
+
request('kick-channel-chatroom', params, response_type: response_type)
|
|
132
|
+
end
|
|
133
|
+
define_method('channel_clips') do |**params|
|
|
134
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
135
|
+
request('kick-channel-clips', params, response_type: response_type)
|
|
136
|
+
end
|
|
137
|
+
define_method('channel_emotes') do |**params|
|
|
138
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
139
|
+
request('kick-channel-emotes', params, response_type: response_type)
|
|
140
|
+
end
|
|
141
|
+
define_method('channel_links') do |**params|
|
|
142
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
143
|
+
request('kick-channel-links', params, response_type: response_type)
|
|
144
|
+
end
|
|
145
|
+
define_method('channel_streams') do |**params|
|
|
146
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
147
|
+
request('kick-channel-streams', params, response_type: response_type)
|
|
148
|
+
end
|
|
149
|
+
define_method('channel_videos') do |**params|
|
|
150
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
151
|
+
request('kick-channel-videos', params, response_type: response_type)
|
|
152
|
+
end
|
|
153
|
+
define_method('clip') do |**params|
|
|
154
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
155
|
+
request('kick-clip', params, response_type: response_type)
|
|
156
|
+
end
|
|
157
|
+
define_method('clips') do |**params|
|
|
158
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
159
|
+
request('kick-clips', params, response_type: response_type)
|
|
160
|
+
end
|
|
161
|
+
define_method('drops') do |**params|
|
|
162
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
163
|
+
request('kick-drops', params, response_type: response_type)
|
|
164
|
+
end
|
|
165
|
+
define_method('gifts') do |**params|
|
|
166
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
167
|
+
request('kick-gifts', params, response_type: response_type)
|
|
168
|
+
end
|
|
169
|
+
define_method('languages') do |**params|
|
|
170
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
171
|
+
request('kick-languages', params, response_type: response_type)
|
|
172
|
+
end
|
|
173
|
+
define_method('livestreams') do |**params|
|
|
174
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
175
|
+
request('kick-livestreams', params, response_type: response_type)
|
|
176
|
+
end
|
|
177
|
+
define_method('search_categories') do |**params|
|
|
178
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
179
|
+
request('kick-search-categories', params, response_type: response_type)
|
|
180
|
+
end
|
|
181
|
+
define_method('search_channels') do |**params|
|
|
182
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
183
|
+
request('kick-search-channels', params, response_type: response_type)
|
|
184
|
+
end
|
|
185
|
+
define_method('subcategories') do |**params|
|
|
186
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
187
|
+
request('kick-subcategories', params, response_type: response_type)
|
|
188
|
+
end
|
|
189
|
+
define_method('subcategory') do |**params|
|
|
190
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
191
|
+
request('kick-subcategory', params, response_type: response_type)
|
|
192
|
+
end
|
|
193
|
+
define_method('top_channels') do |**params|
|
|
194
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
195
|
+
request('kick-top-channels', params, response_type: response_type)
|
|
196
|
+
end
|
|
197
|
+
define_method('video') do |**params|
|
|
198
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
199
|
+
request('kick-video', params, response_type: response_type)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
private
|
|
203
|
+
|
|
204
|
+
# POST operations take their JSON body under the body parameter name or "body".
|
|
205
|
+
def request_body(operation, params)
|
|
206
|
+
name = operation["bodyParam"]
|
|
207
|
+
return nil if name.nil?
|
|
208
|
+
value = params.key?(name) ? params[name] : params["body"]
|
|
209
|
+
if value.nil?
|
|
210
|
+
raise Errors::ClientError.new("missing request body: #{name}", operation_id: operation["id"]) if operation["bodyRequired"]
|
|
211
|
+
return nil
|
|
212
|
+
end
|
|
213
|
+
value.is_a?(String) ? value : JSON.generate(value)
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def build_url(operation, params)
|
|
217
|
+
known = operation["params"].map { |param| param["name"] }
|
|
218
|
+
known << "body" if operation["bodyParam"]
|
|
219
|
+
unknown = params.keys - known
|
|
220
|
+
raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
|
|
221
|
+
path = operation["path"].dup
|
|
222
|
+
operation["params"].select { |param| param["in"] == "path" }.each do |param|
|
|
223
|
+
value = params[param["name"]]
|
|
224
|
+
raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
|
|
225
|
+
path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
|
|
226
|
+
end
|
|
227
|
+
pairs = []
|
|
228
|
+
operation["queryParams"].each do |param|
|
|
229
|
+
name = param["name"]
|
|
230
|
+
value = params.key?(name) ? params[name] : param["default"]
|
|
231
|
+
if value.nil?
|
|
232
|
+
raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
|
|
233
|
+
next
|
|
234
|
+
end
|
|
235
|
+
enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
|
|
236
|
+
if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
|
|
237
|
+
raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
|
|
238
|
+
end
|
|
239
|
+
if value.is_a?(Array)
|
|
240
|
+
format = param["collectionFormat"] || "csv"
|
|
241
|
+
if format == "multi"
|
|
242
|
+
value.each { |item| pairs << [name, scalar(item)] }
|
|
243
|
+
else
|
|
244
|
+
separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
|
|
245
|
+
pairs << [name, value.map { |item| scalar(item) }.join(separator)]
|
|
246
|
+
end
|
|
247
|
+
else
|
|
248
|
+
pairs << [name, scalar(value)]
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
|
|
252
|
+
@base_url + path + (query.empty? ? "" : "?" + query)
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
def scalar(value)
|
|
256
|
+
value == true ? "true" : (value == false ? "false" : value.to_s)
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def percent_encode(value)
|
|
260
|
+
URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def parse_response(body, content_type, operation, params, response_type)
|
|
264
|
+
type = response_type.to_s
|
|
265
|
+
raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
|
|
266
|
+
format = operation["params"].find { |param| param["name"] == "format" }
|
|
267
|
+
text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
|
|
268
|
+
raw_format = params["format"] && text_formats.include?(params["format"].to_s)
|
|
269
|
+
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)
|
|
270
|
+
is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
|
|
271
|
+
return body if type == "text" || raw_format || (type == "auto" && !is_json)
|
|
272
|
+
JSON.parse(body)
|
|
273
|
+
rescue JSON::ParserError => error
|
|
274
|
+
raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
public
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: crawlora-kick
|
|
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-29 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Ruby client for Crawlora's hosted Kick API. Covers channels, livestreams,
|
|
14
|
+
clips, categories, search, and public mobile-app catalogues across 21 endpoints.
|
|
15
|
+
email:
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- CHANGELOG.md
|
|
21
|
+
- LICENSE
|
|
22
|
+
- README.md
|
|
23
|
+
- lib/crawlora/kick.rb
|
|
24
|
+
- lib/crawlora/kick/client.rb
|
|
25
|
+
- lib/crawlora/kick/version.rb
|
|
26
|
+
homepage: https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=kick-ruby-homepage
|
|
27
|
+
licenses:
|
|
28
|
+
- MIT
|
|
29
|
+
metadata:
|
|
30
|
+
source_code_uri: https://github.com/Crawlora-org/crawlora-kick
|
|
31
|
+
documentation_uri: https://github.com/Crawlora-org/crawlora-kick/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: Kick API client for Crawlora (21 endpoints)
|
|
52
|
+
test_files: []
|