crawlora-youtube 0.1.4

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 94bbd8217994ca38ba670d25ee69f863210f6912c1f4ee55c55304f304079ff0
4
+ data.tar.gz: 88bc680c457c0f07a886640b29bda88cd17c25e4f5ae6e8cb25011c528c2f1d2
5
+ SHA512:
6
+ metadata.gz: 8a06e7bf21d1598eca4f411187fc86c8f831c9252df0283499571d5222c3dedbbba6a0e0daaf7c959049c6e6e51594d6f94a857ecdae981cb634a70c49ca0b36
7
+ data.tar.gz: fe0bc8efe6d74deec9ad29e33655068a1ffe33635dc842c66af974bd7f440bf765006cf2a0a8bbbcfa1ead62b679ddb1c93fb5f06a991a5c09428d7582857b40
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.4
4
+
5
+ - Initial focused YouTube Ruby client for Crawlora's hosted API.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Crawlora
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Crawlora YouTube Ruby client
2
+
3
+ This gem calls the Crawlora hosted API at `https://api.crawlora.net/api/v1`. It does not call or scrape YouTube directly. Requests require your Crawlora API key and use your account's service plan.
4
+
5
+ ## Install
6
+
7
+ ```ruby
8
+ gem "crawlora-youtube"
9
+ ```
10
+
11
+ Create an account at [crawlora.net](https://crawlora.net/signup), open the [Crawlora console](https://crawlora.net/app) to get an API key, and set `CRAWLORA_API_KEY` before running the client:
12
+
13
+ ```ruby
14
+ require "json"
15
+ require "crawlora/youtube"
16
+
17
+ client = Crawlora::Youtube::Client.new
18
+ result = client.request("youtube-channel-search", JSON.parse("{\"id\": \"sample-id\", \"q\": \"science explainers\"}"))
19
+ puts result
20
+ client.close
21
+ ```
22
+
23
+ Use a generated operation method for normal calls. `request(operation_id, params = {}, response_type: :auto)` is available for every operation. `response_type: :text` returns raw response text. This gem contains 14 operations and follows contract revision `sha256:677d4bc412f42cf0083135b32bf36b478ab37efbea5f35fc5e8b6e86caaf6a68`.
24
+
25
+ ```ruby
26
+ client = Crawlora::Youtube::Client.new(api_key: ENV.fetch("CRAWLORA_API_KEY"), timeout: 30)
27
+ # client.<operation_method>(<contract parameters>)
28
+ client.close
29
+ ```
30
+
31
+ Client options include `api_key`, `base_url`, and `timeout`. Ruby stdlib provides the HTTP and JSON transport. The gem follows contract revision `sha256:677d4bc412f42cf0083135b32bf36b478ab37efbea5f35fc5e8b6e86caaf6a68` and contains 14 operations.
32
+
33
+ See [Crawlora](https://crawlora.net/), the [API documentation](https://crawlora.net/docs), and [the package repository](https://github.com/Crawlora-org/crawlora-youtube) for account setup, the generated operation reference, and release history.
@@ -0,0 +1,230 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ module Crawlora
6
+ module Youtube
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
+ {"youtube-captions": {"id": "youtube-captions", "method": "GET", "params": [{"description": "YouTube video ID (11-character code)", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "YbJOTdZBX1g"}, {"default": "en", "description": "Caption language code (ISO 639-1), defaults to **en**", "in": "query", "name": "lang", "type": "string"}], "path": "/youtube/captions/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "lang", "type": "string"}], "security": ["ApiKeyAuth"]}, "youtube-channel-playlists": {"id": "youtube-channel-playlists", "method": "GET", "params": [{"description": "Channel ID, @handle, /c path, /user path, or full YouTube channel URL", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "UCXZCJLdBC09xxGZ6gcdrc6A"}, {"description": "Pagination token returned by a previous request", "in": "query", "name": "continuation_token", "type": "string"}], "path": "/youtube/channel/{id}/playlists", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "continuation_token", "type": "string"}], "security": ["ApiKeyAuth"]}, "youtube-channel-search": {"id": "youtube-channel-search", "method": "GET", "params": [{"description": "Channel ID, @handle, /c path, /user path, or full YouTube channel URL", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "UCXZCJLdBC09xxGZ6gcdrc6A"}, {"description": "Search query", "in": "query", "name": "q", "required": true, "type": "string", "x-example": "gpt"}, {"description": "Pagination token returned by a previous request", "in": "query", "name": "continuation_token", "type": "string"}], "path": "/youtube/channel/{id}/search", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "q", "required": true, "type": "string"}, {"in": "query", "name": "continuation_token", "type": "string"}], "security": ["ApiKeyAuth"]}, "youtube-channel-shorts": {"id": "youtube-channel-shorts", "method": "GET", "params": [{"description": "Channel ID, @handle, /c path, /user path, or full YouTube channel URL", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "UCXZCJLdBC09xxGZ6gcdrc6A"}], "path": "/youtube/channel/{id}/shorts", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "youtube-channel-videos": {"id": "youtube-channel-videos", "method": "GET", "params": [{"description": "Channel ID, @handle, /c path, /user path, or full YouTube channel URL", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "UCXZCJLdBC09xxGZ6gcdrc6A"}, {"description": "Pagination token returned by a previous request", "in": "query", "name": "continuation_token", "type": "string"}], "path": "/youtube/channel/{id}/videos", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "continuation_token", "type": "string"}], "security": ["ApiKeyAuth"]}, "youtube-comments": {"id": "youtube-comments", "method": "GET", "params": [{"description": "YouTube video ID (11-character code)", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "YbJOTdZBX1g"}, {"description": "Pagination token returned by a previous request, first page if empty", "in": "query", "name": "continuation_token", "type": "string"}], "path": "/youtube/comments/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "continuation_token", "type": "string"}], "security": ["ApiKeyAuth"]}, "youtube-playlist": {"id": "youtube-playlist", "method": "GET", "params": [{"description": "YouTube playlist ID or full playlist URL", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "PL-szjqIBRvM_aWOj-uXCVm28l-ZZFa4D2"}, {"description": "Pagination token returned by a previous request", "in": "query", "name": "continuation_token", "type": "string"}], "path": "/youtube/playlist/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "continuation_token", "type": "string"}], "security": ["ApiKeyAuth"]}, "youtube-profile": {"id": "youtube-profile", "method": "GET", "params": [{"description": "Channel ID, @handle, /c path, /user path, bare username, or full YouTube channel URL", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "UCXZCJLdBC09xxGZ6gcdrc6A"}], "path": "/youtube/profile/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "youtube-search": {"id": "youtube-search", "method": "GET", "params": [{"description": "Search query", "in": "query", "name": "q", "type": "string", "x-example": "gpt"}, {"description": "Alias for q", "in": "query", "name": "search_query", "type": "string", "x-example": "gpt"}, {"description": "Pagination token returned by a previous request", "in": "query", "name": "continuation_token", "type": "string"}, {"description": "Filter by type", "enum": ["video", "shorts", "channel", "playlist", "movie"], "in": "query", "name": "type", "type": "string"}, {"description": "Sort results", "enum": ["relevance", "upload_date", "view_count", "popularity", "rating"], "in": "query", "name": "sort_by", "type": "string"}, {"description": "Filter by upload date", "enum": ["last_hour", "today", "this_week", "this_month", "this_year"], "in": "query", "name": "upload_date", "type": "string"}, {"description": "Filter by duration; short, medium, and long preserve their previous upstream encodings", "enum": ["under_3_minutes", "three_to_20_minutes", "over_20_minutes", "under_3", "three_to_20", "over_20", "short", "medium", "long"], "in": "query", "name": "duration", "type": "string"}, {"description": "Comma-separated feature filters. Allowed values: live, 4k, hd, subtitles, cc, creative_commons, 360, vr180, 3d, hdr, location, purchased", "in": "query", "name": "features", "type": "string", "x-example": "hd,subtitles"}, {"description": "YouTube interface language", "in": "query", "name": "hl", "type": "string", "x-example": "en"}, {"description": "Two-letter YouTube region code", "in": "query", "name": "gl", "type": "string", "x-example": "US"}, {"description": "Raw protobuf-encoded search filter (base64)", "in": "query", "name": "params", "type": "string"}], "path": "/youtube/search", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "q", "type": "string"}, {"in": "query", "name": "search_query", "type": "string"}, {"in": "query", "name": "continuation_token", "type": "string"}, {"enum": ["video", "shorts", "channel", "playlist", "movie"], "in": "query", "name": "type", "type": "string"}, {"enum": ["relevance", "upload_date", "view_count", "popularity", "rating"], "in": "query", "name": "sort_by", "type": "string"}, {"enum": ["last_hour", "today", "this_week", "this_month", "this_year"], "in": "query", "name": "upload_date", "type": "string"}, {"enum": ["under_3_minutes", "three_to_20_minutes", "over_20_minutes", "under_3", "three_to_20", "over_20", "short", "medium", "long"], "in": "query", "name": "duration", "type": "string"}, {"in": "query", "name": "features", "type": "string"}, {"in": "query", "name": "hl", "type": "string"}, {"in": "query", "name": "gl", "type": "string"}, {"in": "query", "name": "params", "type": "string"}], "security": ["ApiKeyAuth"]}, "youtube-suggest": {"id": "youtube-suggest", "method": "GET", "params": [{"description": "Search query prefix", "in": "query", "name": "q", "required": true, "type": "string", "x-example": "openai"}, {"description": "Suggestions to return; defaults to 10, clamped to 1..20", "in": "query", "maximum": 20, "minimum": 1, "name": "count", "type": "integer", "x-example": 10}, {"description": "YouTube interface language, such as en, de, or pt-BR; defaults to en", "in": "query", "name": "hl", "type": "string", "x-example": "en"}, {"description": "Two-letter YouTube region code; defaults to US", "in": "query", "name": "gl", "type": "string", "x-example": "US"}], "path": "/youtube/suggest", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "q", "required": true, "type": "string"}, {"in": "query", "name": "count", "type": "integer"}, {"in": "query", "name": "hl", "type": "string"}, {"in": "query", "name": "gl", "type": "string"}], "security": ["ApiKeyAuth"]}, "youtube-tag": {"id": "youtube-tag", "method": "GET", "params": [{"description": "Tag to filter videos", "in": "path", "name": "tag", "required": true, "type": "string", "x-example": "openai"}, {"default": "all", "description": "Result tab to load", "enum": ["all", "shorts"], "in": "query", "name": "type", "type": "string"}, {"description": "Continuation token for pagination, first page if empty", "in": "query", "name": "continuation_token", "type": "string"}], "path": "/youtube/tag/{tag}", "pathParams": ["tag"], "produces": ["application/json"], "queryParams": [{"enum": ["all", "shorts"], "in": "query", "name": "type", "type": "string"}, {"in": "query", "name": "continuation_token", "type": "string"}], "security": ["ApiKeyAuth"]}, "youtube-transcript": {"id": "youtube-transcript", "method": "GET", "params": [{"description": "YouTube video ID (11-character code)", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "YbJOTdZBX1g"}, {"default": "en", "description": "Preferred transcript language", "in": "query", "name": "lang", "type": "string"}, {"description": "Translate transcript to this language code", "in": "query", "name": "translate_to", "type": "string"}, {"default": "json", "description": "Response format", "enum": ["json", "text", "srt", "vtt"], "in": "query", "name": "format", "type": "string"}, {"default": true, "description": "Include timestamps in the JSON response", "in": "query", "name": "timestamps", "type": "boolean"}], "path": "/youtube/transcript/{id}", "pathParams": ["id"], "produces": ["application/json", "text/plain"], "queryParams": [{"in": "query", "name": "lang", "type": "string"}, {"in": "query", "name": "translate_to", "type": "string"}, {"enum": ["json", "text", "srt", "vtt"], "in": "query", "name": "format", "type": "string"}, {"in": "query", "name": "timestamps", "type": "boolean"}], "security": ["ApiKeyAuth"]}, "youtube-transcript-languages": {"id": "youtube-transcript-languages", "method": "GET", "params": [{"description": "YouTube video ID (11-character code)", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "YbJOTdZBX1g"}], "path": "/youtube/transcript/{id}/languages", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "youtube-video": {"id": "youtube-video", "method": "GET", "params": [{"description": "YouTube video ID (11-char code)", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "YbJOTdZBX1g"}], "path": "/youtube/video/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}}
23
+ JSON
24
+ OPERATION_IDS = JSON.parse(<<~'JSON').freeze
25
+ ["youtube-captions", "youtube-channel-playlists", "youtube-channel-search", "youtube-channel-shorts", "youtube-channel-videos", "youtube-comments", "youtube-playlist", "youtube-profile", "youtube-search", "youtube-suggest", "youtube-tag", "youtube-transcript", "youtube-transcript-languages", "youtube-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-youtube-ruby/0.1.4", transport: nil)
33
+ @api_key = api_key
34
+ @base_url = base_url.to_s.sub(%r{/+$}, "")
35
+ @timeout = Float(timeout)
36
+ @user_agent = user_agent
37
+ @transport = transport
38
+ @closed = false
39
+ end
40
+
41
+ def request(operation_id, params = {}, response_type: :auto)
42
+ raise Errors::ClientError, "client is closed" if @closed
43
+ operation_id = operation_id.to_s
44
+ operation = OPERATIONS[operation_id]
45
+ raise Errors::ClientError.new("unknown operation: #{operation_id}", operation_id: operation_id) unless operation
46
+ raise Errors::ClientError.new("Crawlora API key is required", operation_id: operation_id) if @api_key.nil? || @api_key.to_s.empty?
47
+ normalized = params.each_with_object({}) { |(key, value), out| out[key.to_s] = value }
48
+ url = build_url(operation, normalized)
49
+ uri = URI.parse(url)
50
+ request = Net::HTTP::Get.new(uri)
51
+ request["x-api-key"] = @api_key
52
+ request["User-Agent"] = @user_agent
53
+ request["Accept"] = operation["produces"].include?("text/plain") ? "application/json, text/plain" : "application/json"
54
+ begin
55
+ if @transport
56
+ response = @transport.call(url, request.to_hash, @timeout)
57
+ status = Integer(response.fetch(:status) { response.fetch("status") })
58
+ body = response.fetch(:body) { response.fetch("body", "") }
59
+ headers = response.fetch(:headers) { response.fetch("headers", {}) }
60
+ content_type = headers["content-type"] || headers["Content-Type"]
61
+ else
62
+ http = Net::HTTP.new(uri.host, uri.port)
63
+ http.use_ssl = uri.scheme == "https"
64
+ http.open_timeout = @timeout
65
+ http.read_timeout = @timeout
66
+ response = http.start { |connection| connection.request(request) }
67
+ status = response.code.to_i
68
+ body = response.body
69
+ content_type = response["content-type"]
70
+ end
71
+ rescue Timeout::Error, SocketError, SystemCallError, IOError, EOFError, Net::HTTPBadResponse, Net::ProtocolError, OpenSSL::SSL::SSLError => error
72
+ raise Errors::NetworkError.new("Crawlora request failed: #{error.message}", operation_id: operation_id)
73
+ end
74
+ unless status >= 200 && status < 300
75
+ klass = status >= 500 ? Errors::ServerError : Errors::ClientError
76
+ raise klass.new("Crawlora returned HTTP #{status}", status: status, operation_id: operation_id, body: body)
77
+ end
78
+ parse_response(body, content_type, operation, normalized, response_type)
79
+ end
80
+
81
+ def close
82
+ @closed = true
83
+ end
84
+
85
+ def closed?
86
+ @closed
87
+ end
88
+
89
+ def with
90
+ return self unless block_given?
91
+ yield self
92
+ ensure
93
+ close if block_given?
94
+ end
95
+
96
+ def self.operation_count
97
+ OPERATION_COUNT
98
+ end
99
+
100
+ def self.operation_ids
101
+ OPERATION_IDS
102
+ end
103
+
104
+ def self.operations
105
+ OPERATIONS
106
+ end
107
+
108
+ define_method('captions') do |**params|
109
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
110
+ request('youtube-captions', params, response_type: response_type)
111
+ end
112
+ define_method('channel_playlists') do |**params|
113
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
114
+ request('youtube-channel-playlists', params, response_type: response_type)
115
+ end
116
+ define_method('channel_search') do |**params|
117
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
118
+ request('youtube-channel-search', params, response_type: response_type)
119
+ end
120
+ define_method('channel_shorts') do |**params|
121
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
122
+ request('youtube-channel-shorts', params, response_type: response_type)
123
+ end
124
+ define_method('channel_videos') do |**params|
125
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
126
+ request('youtube-channel-videos', params, response_type: response_type)
127
+ end
128
+ define_method('comments') do |**params|
129
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
130
+ request('youtube-comments', params, response_type: response_type)
131
+ end
132
+ define_method('playlist') do |**params|
133
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
134
+ request('youtube-playlist', params, response_type: response_type)
135
+ end
136
+ define_method('profile') do |**params|
137
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
138
+ request('youtube-profile', params, response_type: response_type)
139
+ end
140
+ define_method('search') do |**params|
141
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
142
+ request('youtube-search', params, response_type: response_type)
143
+ end
144
+ define_method('suggest') do |**params|
145
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
146
+ request('youtube-suggest', params, response_type: response_type)
147
+ end
148
+ define_method('tag') do |**params|
149
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
150
+ request('youtube-tag', params, response_type: response_type)
151
+ end
152
+ define_method('transcript') do |**params|
153
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
154
+ request('youtube-transcript', params, response_type: response_type)
155
+ end
156
+ define_method('transcript_languages') do |**params|
157
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
158
+ request('youtube-transcript-languages', params, response_type: response_type)
159
+ end
160
+ define_method('video') do |**params|
161
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
162
+ request('youtube-video', params, response_type: response_type)
163
+ end
164
+
165
+ private
166
+
167
+ def build_url(operation, params)
168
+ known = operation["params"].map { |param| param["name"] }
169
+ unknown = params.keys - known
170
+ raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
171
+ path = operation["path"].dup
172
+ operation["params"].select { |param| param["in"] == "path" }.each do |param|
173
+ value = params[param["name"]]
174
+ raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
175
+ path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
176
+ end
177
+ pairs = []
178
+ operation["queryParams"].each do |param|
179
+ name = param["name"]
180
+ value = params.key?(name) ? params[name] : param["default"]
181
+ if value.nil?
182
+ raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
183
+ next
184
+ end
185
+ enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
186
+ if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
187
+ raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
188
+ end
189
+ if value.is_a?(Array)
190
+ format = param["collectionFormat"] || "csv"
191
+ if format == "multi"
192
+ value.each { |item| pairs << [name, scalar(item)] }
193
+ else
194
+ separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
195
+ pairs << [name, value.map { |item| scalar(item) }.join(separator)]
196
+ end
197
+ else
198
+ pairs << [name, scalar(value)]
199
+ end
200
+ end
201
+ query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
202
+ @base_url + path + (query.empty? ? "" : "?" + query)
203
+ end
204
+
205
+ def scalar(value)
206
+ value == true ? "true" : (value == false ? "false" : value.to_s)
207
+ end
208
+
209
+ def percent_encode(value)
210
+ URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
211
+ end
212
+
213
+ def parse_response(body, content_type, operation, params, response_type)
214
+ type = response_type.to_s
215
+ raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
216
+ format = operation["params"].find { |param| param["name"] == "format" }
217
+ text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
218
+ raw_format = params["format"] && text_formats.include?(params["format"].to_s)
219
+ 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)
220
+ is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
221
+ return body if type == "text" || raw_format || (type == "auto" && !is_json)
222
+ JSON.parse(body)
223
+ rescue JSON::ParserError => error
224
+ raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
225
+ end
226
+
227
+ public
228
+ end
229
+ end
230
+ end
@@ -0,0 +1,5 @@
1
+ module Crawlora
2
+ module Youtube
3
+ VERSION = "0.1.4"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require_relative "youtube/version"
2
+ require_relative "youtube/client"
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crawlora-youtube
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Crawlora
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-10-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Credential-free YouTube API access through Crawlora's hosted service.
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - CHANGELOG.md
20
+ - LICENSE
21
+ - README.md
22
+ - lib/crawlora/youtube.rb
23
+ - lib/crawlora/youtube/client.rb
24
+ - lib/crawlora/youtube/version.rb
25
+ homepage: https://github.com/Crawlora-org/crawlora-youtube
26
+ licenses:
27
+ - MIT
28
+ metadata:
29
+ source_code_uri: https://github.com/Crawlora-org/crawlora-youtube
30
+ rubygems_mfa_required: 'true'
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '2.6'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubygems_version: 3.4.19
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: YouTube client for the Crawlora hosted API
50
+ test_files: []