Class: SavvyOpenrouter::Resources::Videos
- Inherits:
-
Base
- Object
- Base
- SavvyOpenrouter::Resources::Videos
show all
- Defined in:
- lib/savvy_openrouter/resources/videos.rb
Constant Summary
collapse
- TERMINAL_STATUSES =
%w[completed failed cancelled expired].freeze
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#create(**params) ⇒ Object
Also known as:
submit
10
11
12
13
|
# File 'lib/savvy_openrouter/resources/videos.rb', line 10
def create(**params)
body = config.merge_video_body(params)
conn.post("/videos", body: body)
end
|
#download(job_id, index: 0) ⇒ Object
24
25
26
|
# File 'lib/savvy_openrouter/resources/videos.rb', line 24
def download(job_id, index: 0)
conn.get_raw("/videos/#{job_id}/content", params: { index: index })
end
|
#get(job_id) ⇒ Object
Also known as:
retrieve, poll
17
18
19
|
# File 'lib/savvy_openrouter/resources/videos.rb', line 17
def get(job_id)
conn.get("/videos/#{job_id}")
end
|
#models ⇒ Object
48
49
50
|
# File 'lib/savvy_openrouter/resources/videos.rb', line 48
def models
conn.get("/videos/models")
end
|
#poll_until(job_id, interval: 2, timeout: 600) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/savvy_openrouter/resources/videos.rb', line 34
def poll_until(job_id, interval: 2, timeout: 600)
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout
loop do
res = get(job_id)
st = res[:status].to_s
return res if TERMINAL_STATUSES.include?(st)
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
raise TimeoutPollError, "Timed out waiting for video job #{job_id}" if now > deadline
sleep(interval)
end
end
|
#stream(job_id, index: 0, &block) ⇒ Object
28
29
30
31
32
|
# File 'lib/savvy_openrouter/resources/videos.rb', line 28
def stream(job_id, index: 0, &block)
raise ArgumentError, "block required" unless block
conn.stream_get("/videos/#{job_id}/content", params: { index: index }, &block)
end
|