From 4626684d543661ab54ecb8e037912ce2b81e7748 Mon Sep 17 00:00:00 2001 From: jsneedles Date: Wed, 25 Nov 2026 14:21:35 -0500 Subject: [PATCH 1/2] Add recording audio support in 1.1.0 --- Gemfile.lock | 2 +- README.md | 5 +- docs/HTMLCSSToImage.html | 85 ++--- docs/HTMLCSSToImage/RecordingAudio.html | 400 ++++++++++++++++++++++++ docs/_index.html | 9 +- docs/class_list.html | 2 +- docs/file.README.html | 27 +- docs/index.html | 27 +- docs/method_list.html | 24 +- lib/htmlcsstoimage.rb | 1 + lib/htmlcsstoimage/recording_audio.rb | 31 ++ lib/htmlcsstoimage/recordings.rb | 25 +- lib/htmlcsstoimage/version.rb | 2 +- spec/recordings_spec.rb | 29 ++ 14 files changed, 602 insertions(+), 67 deletions(-) create mode 100644 docs/HTMLCSSToImage/RecordingAudio.html create mode 100644 lib/htmlcsstoimage/recording_audio.rb diff --git a/Gemfile.lock b/Gemfile.lock index 38304a1..4d8dfde 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - htmlcsstoimage-api (1.0.0) + htmlcsstoimage-api (1.1.0) addressable (> 2.5.0) httparty (> 0.10) diff --git a/README.md b/README.md index 1a6656e..86e98fc 100644 --- a/README.md +++ b/README.md @@ -142,8 +142,9 @@ animation = client.create_html_css_recording( ``` Both methods accept browser, timeline, and output options as hashes, following -the image methods. Options pass through to the API without local validation. -Omitted settings use API defaults. Recordings do not include audio. +the image methods. Omitted settings use API defaults. + +To add a soundtrack to MP4 or WebM, pass `audio: { asset_id: "YOUR_ASSET_ID", delay_ms: 500 }` or `audio: { url: "https://cdn.example.com/audio/intro.mp3" }` to either recording method. You can also reuse an `HTMLCSSToImage::RecordingAudio` instance with the same keyword arguments. [Audio sources and playback options](https://docs.htmlcsstoimage.com/parameters/audio/). Triggers and actions use a `type` discriminator. For example, wait until an element is visible, click a button, and hold the result: diff --git a/docs/HTMLCSSToImage.html b/docs/HTMLCSSToImage.html index 274e89b..32b7844 100644 --- a/docs/HTMLCSSToImage.html +++ b/docs/HTMLCSSToImage.html @@ -102,7 +102,7 @@
Defined in:
lib/htmlcsstoimage/client.rb,
- lib/htmlcsstoimage/images.rb,
lib/htmlcsstoimage/version.rb,
lib/htmlcsstoimage/templates.rb,
lib/htmlcsstoimage/recordings.rb,
lib/htmlcsstoimage/signed_urls.rb,
lib/htmlcsstoimage/request_override_resource_type.rb
+ lib/htmlcsstoimage/images.rb,
lib/htmlcsstoimage/version.rb,
lib/htmlcsstoimage/templates.rb,
lib/htmlcsstoimage/recordings.rb,
lib/htmlcsstoimage/signed_urls.rb,
lib/htmlcsstoimage/recording_audio.rb,
lib/htmlcsstoimage/request_override_resource_type.rb
@@ -124,7 +124,7 @@

Overview

- Classes: ApiResponse, RequestOverrideResourceType + Classes: ApiResponse, RecordingAudio, RequestOverrideResourceType

@@ -149,7 +149,7 @@

-
"1.0.0"
+
"1.1.0"
@@ -743,8 +743,9 @@

Records an HTML document or fragment with optional CSS and Google Fonts. -Returns the recording ID, status URL, and media URL while rendering can -continue in the background. Optional settings use the API defaults.

+Returns the recording ID, status URL, and media URL. The recording_url can +be embedded or requested directly; a request waits until the recording is +ready, so checking status is optional. Optional settings use the API defaults.

@@ -997,7 +998,7 @@

- —

Ordered timeline interactions: simple_scroll, scroll, stall, click, locate_selector, execute_javascript, or error. Each action has a type discriminator. Omit or use an empty array to record without interactions.

+ —

Ordered timeline interactions: simple_scroll, scroll, stall, click, locate_selector, execute_javascript, or error. Each action has a type discriminator. Each scroll action step requires duration_ms of at least 1. Omit or use an empty array to record without interactions.

@@ -1008,7 +1009,18 @@

- —

Media format (mp4, webm, or gif), fps, and pixel scale. Defaults to MP4 at 30 fps; GIF defaults to 15 fps. Recordings have no audio.

+ —

Media format (mp4, webm, or gif), fps, and pixel scale. Defaults to MP4 at 30 fps; GIF defaults to 15 fps.

+ + + +
  • + :audio + (RecordingAudio, Hash) + + + + + —

    Optional MP4 or WebM soundtrack. Supply one Asset Library asset_id or public url. See HTMLCSSToImage::RecordingAudio#initialize for playback options.

  • @@ -1076,6 +1088,8 @@

  • https://docs.htmlcsstoimage.com/parameters/output/
  • +
  • https://docs.htmlcsstoimage.com/parameters/audio/
  • + @@ -1084,19 +1098,15 @@

     
     
    -37
    -38
    -39
     40
    -41
    +41 +42

    @@ -2736,19 +2746,15 @@

     
     
    -59
     60
     61
    -62
    -63
    +62

    @@ -3001,14 +3007,14 @@

     
     
    -82
    -83
     84
     85
    -86
    +86 +87 +88

    @@ -2746,15 +2753,19 @@

     
     
    -60
    -61
    -62
    +65 +66 +67 +68 +69

    @@ -3007,14 +3018,14 @@

     
     
    -84
    -85
    -86
    -87
    -88
    +91 +92 +93 +94 +95

    -
    # File 'lib/htmlcsstoimage/recordings.rb', line 37
    +      
    # File 'lib/htmlcsstoimage/recordings.rb', line 40
     
     def create_html_css_recording(html, params = {})
    -  body = { html: html }.merge(params).to_json
    -
    -  self.class.post("/v1/recording", basic_auth: @auth, body: body)
    +  post_recording({ html: html }, params)
     end
    -
    # File 'lib/htmlcsstoimage/recordings.rb', line 59
    +      
    # File 'lib/htmlcsstoimage/recordings.rb', line 60
     
     def create_url_recording(url, params = {})
    -  body = { url: url }.merge(params).to_json
    -
    -  self.class.post("/v1/recording", basic_auth: @auth, body: body)
    +  post_recording({ url: url }, params)
     end
    -
    # File 'lib/htmlcsstoimage/recordings.rb', line 82
    +      
    # File 'lib/htmlcsstoimage/recordings.rb', line 84
     
     def delete_recording(recording_id)
       response = self.class.delete("/v1/recordings/#{recording_id}", basic_auth: @auth)
    @@ -3079,8 +3085,6 @@ 

     
     
    -93
    -94
     95
     96
     97
    @@ -3089,10 +3093,12 @@ 

    100 101 102 -103

    +103 +104 +105

    -
    # File 'lib/htmlcsstoimage/recordings.rb', line 93
    +      
    # File 'lib/htmlcsstoimage/recordings.rb', line 95
     
     def delete_recording_batch(recording_ids)
       return true if recording_ids.empty?
    @@ -3121,10 +3127,13 @@ 

    -

    Fetches a recording's current lifecycle state once. +

    Fetches a recording's current lifecycle state once. Checking status is +optional: requesting the recording_url directly waits until it is ready. HTTP 200 and 202 both return status information. The states ready, failed, and cancelled are terminal; an error can also describe an -earlier, retryable attempt. Requesting the media URL waits for processing.

    +earlier, retryable attempt. .status is the raw API string: treat values +not listed here, which newer API versions may add, as unknown; the client +passes them through as-is.

    @@ -3159,7 +3168,7 @@

    — -

    .status, .attempt_count, .status_entered_at, .stored_duration_ms, .recording_url, and optional .error

    +

    .id, .status, .attempt_count, .status_entered_at, .stored_duration_ms, .storage_destination_hcti_storage_disabled, .recording_url, and optional .error

    @@ -3178,12 +3187,12 @@

     
     
    -74
    -75
    -76
    +76 +77 +78

    -
    # File 'lib/htmlcsstoimage/recordings.rb', line 74
    +      
    # File 'lib/htmlcsstoimage/recordings.rb', line 76
     
     def fetch_recording_status(recording_id)
       self.class.get("/v1/recordings/#{recording_id}/status", basic_auth: @auth)
    @@ -4332,7 +4341,7 @@ 

    diff --git a/docs/HTMLCSSToImage/RecordingAudio.html b/docs/HTMLCSSToImage/RecordingAudio.html new file mode 100644 index 0000000..3f0e842 --- /dev/null +++ b/docs/HTMLCSSToImage/RecordingAudio.html @@ -0,0 +1,400 @@ + + + + + + + Class: HTMLCSSToImage::RecordingAudio + + — Documentation by YARD 0.9.45 + + + + + + + + + + + + + + + + + + + + + +
    + + +

    Class: HTMLCSSToImage::RecordingAudio + + + +

    +
    + +
    +
    Inherits:
    +
    + Object + +
      +
    • Object
    • + + + +
    + show all + +
    +
    + + + + + + + + + + + +
    +
    Defined in:
    +
    lib/htmlcsstoimage/recording_audio.rb +
    +
    + +
    + +

    Overview

    +
    +

    One soundtrack for an MP4 or WebM recording.

    + +
    +
    + + + + + + + + +

    + Instance Method Summary + collapse +

    + + + + + +
    +

    Constructor Details

    + +
    +

    + + #initialize(asset_id: nil, url: nil, source_start_ms: nil, delay_ms: nil, when_audio_ends: nil, error_on_source_invalid: nil) ⇒ RecordingAudio + + + + + +

    +
    +

    Returns a new instance of RecordingAudio.

    + +
    +
    +
    +

    Parameters:

    +
      + +
    • + + asset_id + + + (String, nil) + + + (defaults to: nil) + + + — +

      ID of a completed audio upload in your organization, which may be private

      + +
    • + +
    • + + url + + + (String, nil) + + + (defaults to: nil) + + + — +

      public HTTP or HTTPS URL serving the audio file at render time

      + +
    • + +
    • + + source_start_ms + + + (Integer, nil) + + + (defaults to: nil) + + + — +

      offset into the source file in milliseconds (default 0)

      + +
    • + +
    • + + delay_ms + + + (Integer, nil) + + + (defaults to: nil) + + + — +

      delay from the start of the finished video in milliseconds (default 0)

      + +
    • + +
    • + + when_audio_ends + + + (String, nil) + + + (defaults to: nil) + + + — +

      "silence" (default), "loop" from the source offset, or "trim_video"

      + +
    • + +
    • + + error_on_source_invalid + + + (Boolean, nil) + + + (defaults to: nil) + + + — +

      defaults to true; set false to return the full silent +video if the track cannot play at render time

      + +
    • + +
    + + +
    + + + + +
    +
    +
    +
    +12
    +13
    +14
    +15
    +16
    +17
    +18
    +19
    +20
    +21
    +22
    +23
    +24
    +25
    +
    +
    # File 'lib/htmlcsstoimage/recording_audio.rb', line 12
    +
    +def initialize(asset_id: nil, url: nil, source_start_ms: nil, delay_ms: nil,
    +               when_audio_ends: nil, error_on_source_invalid: nil)
    +  if asset_id.nil? == url.nil?
    +    raise ArgumentError, "Supply exactly one recording audio source: asset_id or url"
    +  end
    +  if !when_audio_ends.nil? && !%w[silence loop trim_video].include?(when_audio_ends)
    +    raise ArgumentError, "when_audio_ends must be silence, loop, or trim_video"
    +  end
    +
    +  @options = {
    +    asset_id: asset_id, url: url, source_start_ms: source_start_ms, delay_ms: delay_ms,
    +    when_audio_ends: when_audio_ends, error_on_source_invalid: error_on_source_invalid
    +  }.compact
    +end
    +
    +
    + +
    + + +
    +

    Instance Method Details

    + + +
    +

    + + #to_json(*args) ⇒ Object + + + + + +

    + + + + +
    +
    +
    +
    +27
    +28
    +29
    +
    +
    # File 'lib/htmlcsstoimage/recording_audio.rb', line 27
    +
    +def to_json(*args)
    +  @options.to_json(*args)
    +end
    +
    +
    + +
    + +
    + + + +
    + + diff --git a/docs/_index.html b/docs/_index.html index 43d1563..cfce845 100644 --- a/docs/_index.html +++ b/docs/_index.html @@ -110,6 +110,13 @@

    Namespace Listing A-Z

  • R
  • Both methods accept browser, timeline, and output options as hashes, following -the image methods. Options pass through to the API without local validation. -Omitted settings use API defaults. Recordings do not include audio.

    +the image methods. Omitted settings use API defaults.

    +

    To add a soundtrack to MP4 or WebM, pass audio: { asset_id: "YOUR_ASSET_ID", delay_ms: 500 } or audio: { url: "https://cdn.example.com/audio/intro.mp3" } to either recording method. You can also reuse an HTMLCSSToImage::RecordingAudio instance with the same keyword arguments. Audio sources and playback options.

    Triggers and actions use a type discriminator. For example, wait until an element is visible, click a button, and hold the result:

    demo = client.create_url_recording(
    @@ -176,9 +176,22 @@ 

    Recordings

    Nested branches run on the API. For JavaScript actions, omitting if_error or setting it to nil fails on a script error; if_error: [] ignores errors. Empty arrays, explicit nil, false, and zero values are preserved in JSON.

    -

    Creation returns the recording URLs while rendering can continue in the -background. Requesting recording_url waits for processing. Fetch the current -status once with:

    +

    A scroll action moves through ordered steps. Each step's duration_ms is +required and must be at least 1:

    +
    client.create_url_recording(
    +  "https://example.com",
    +  duration_ms: 6000,
    +  actions: [
    +    { type: "scroll", steps: [
    +      { to: { type: "selector", selector: "#pricing" }, duration_ms: 1200, easing: "ease_in_out_cubic" },
    +      { to: { type: "position", position: "bottom" }, duration_ms: 1500 }
    +    ] }
    +  ]
    +)
    +
    +

    Embed or request recording_url directly; the request waits until the +recording is ready, so checking status is optional. To inspect progress, fetch +the current status once with:

    status = client.fetch_recording_status(recording.id)
     puts status.status
     puts status.attempt_count
    @@ -186,6 +199,8 @@ 

    Recordings

    HTTP 200 and 202 both return status information. The states ready, failed, and cancelled are terminal. A successful status fetch can report a failed recording, and status.error can describe an earlier, retryable attempt. +status.status is the raw API string. Treat values not listed here, which +newer API versions may add, as unknown; the client passes them through as-is. API errors and transport failures follow the existing image-method behavior.

    Delete recordings individually or in a batch:

    client.delete_recording("recording-id")
    @@ -339,7 +354,7 @@ 

    Templated image batches

    See the API reference for plan limits and examples.

    diff --git a/docs/index.html b/docs/index.html index b31a8f1..87ebe07 100644 --- a/docs/index.html +++ b/docs/index.html @@ -158,8 +158,8 @@

    Recordings

    )

    Both methods accept browser, timeline, and output options as hashes, following -the image methods. Options pass through to the API without local validation. -Omitted settings use API defaults. Recordings do not include audio.

    +the image methods. Omitted settings use API defaults.

    +

    To add a soundtrack to MP4 or WebM, pass audio: { asset_id: "YOUR_ASSET_ID", delay_ms: 500 } or audio: { url: "https://cdn.example.com/audio/intro.mp3" } to either recording method. You can also reuse an HTMLCSSToImage::RecordingAudio instance with the same keyword arguments. Audio sources and playback options.

    Triggers and actions use a type discriminator. For example, wait until an element is visible, click a button, and hold the result:

    demo = client.create_url_recording(
    @@ -176,9 +176,22 @@ 

    Recordings

    Nested branches run on the API. For JavaScript actions, omitting if_error or setting it to nil fails on a script error; if_error: [] ignores errors. Empty arrays, explicit nil, false, and zero values are preserved in JSON.

    -

    Creation returns the recording URLs while rendering can continue in the -background. Requesting recording_url waits for processing. Fetch the current -status once with:

    +

    A scroll action moves through ordered steps. Each step's duration_ms is +required and must be at least 1:

    +
    client.create_url_recording(
    +  "https://example.com",
    +  duration_ms: 6000,
    +  actions: [
    +    { type: "scroll", steps: [
    +      { to: { type: "selector", selector: "#pricing" }, duration_ms: 1200, easing: "ease_in_out_cubic" },
    +      { to: { type: "position", position: "bottom" }, duration_ms: 1500 }
    +    ] }
    +  ]
    +)
    +
    +

    Embed or request recording_url directly; the request waits until the +recording is ready, so checking status is optional. To inspect progress, fetch +the current status once with:

    status = client.fetch_recording_status(recording.id)
     puts status.status
     puts status.attempt_count
    @@ -186,6 +199,8 @@ 

    Recordings

    HTTP 200 and 202 both return status information. The states ready, failed, and cancelled are terminal. A successful status fetch can report a failed recording, and status.error can describe an earlier, retryable attempt. +status.status is the raw API string. Treat values not listed here, which +newer API versions may add, as unknown; the client passes them through as-is. API errors and transport failures follow the existing image-method behavior.

    Delete recordings individually or in a batch:

    client.delete_recording("recording-id")
    @@ -339,7 +354,7 @@ 

    Templated image batches

    See the API reference for plan limits and examples.

    diff --git a/docs/method_list.html b/docs/method_list.html index f4720d7..ed1fc5e 100644 --- a/docs/method_list.html +++ b/docs/method_list.html @@ -184,6 +184,14 @@

    Method List

  • +
    + #initialize + HTMLCSSToImage::RecordingAudio +
    +
  • + + +
  • #initialize HTMLCSSToImage::RequestOverrideResourceType @@ -191,7 +199,7 @@

    Method List

  • -
  • +
  • #list_template_versions HTMLCSSToImage @@ -199,7 +207,7 @@

    Method List

  • -
  • +
  • #list_templates HTMLCSSToImage @@ -207,7 +215,7 @@

    Method List

  • -
  • +
  • #templates HTMLCSSToImage @@ -215,7 +223,7 @@

    Method List

  • -
  • +
  • #to_json HTMLCSSToImage::RequestOverrideResourceType @@ -223,6 +231,14 @@

    Method List

  • +
  • +
    + #to_json + HTMLCSSToImage::RecordingAudio +
    +
  • + +
  • #url_to_image diff --git a/lib/htmlcsstoimage.rb b/lib/htmlcsstoimage.rb index fd61ec5..b27bc8b 100644 --- a/lib/htmlcsstoimage.rb +++ b/lib/htmlcsstoimage.rb @@ -8,6 +8,7 @@ require "htmlcsstoimage/client" require "htmlcsstoimage/request_override_resource_type" require "htmlcsstoimage/images" +require "htmlcsstoimage/recording_audio" require "htmlcsstoimage/recordings" require "htmlcsstoimage/signed_urls" require "htmlcsstoimage/templates" diff --git a/lib/htmlcsstoimage/recording_audio.rb b/lib/htmlcsstoimage/recording_audio.rb new file mode 100644 index 0000000..aa15813 --- /dev/null +++ b/lib/htmlcsstoimage/recording_audio.rb @@ -0,0 +1,31 @@ +class HTMLCSSToImage + # One soundtrack for an MP4 or WebM recording. + # @see https://docs.htmlcsstoimage.com/parameters/audio/ + class RecordingAudio + # @param asset_id [String, nil] ID of a completed audio upload in your organization, which may be private + # @param url [String, nil] public HTTP or HTTPS URL serving the audio file at render time + # @param source_start_ms [Integer, nil] offset into the source file in milliseconds (default 0) + # @param delay_ms [Integer, nil] delay from the start of the finished video in milliseconds (default 0) + # @param when_audio_ends [String, nil] "silence" (default), "loop" from the source offset, or "trim_video" + # @param error_on_source_invalid [Boolean, nil] defaults to true; set false to return the full silent + # video if the track cannot play at render time + def initialize(asset_id: nil, url: nil, source_start_ms: nil, delay_ms: nil, + when_audio_ends: nil, error_on_source_invalid: nil) + if asset_id.nil? == url.nil? + raise ArgumentError, "Supply exactly one recording audio source: asset_id or url" + end + if !when_audio_ends.nil? && !%w[silence loop trim_video].include?(when_audio_ends) + raise ArgumentError, "when_audio_ends must be silence, loop, or trim_video" + end + + @options = { + asset_id: asset_id, url: url, source_start_ms: source_start_ms, delay_ms: delay_ms, + when_audio_ends: when_audio_ends, error_on_source_invalid: error_on_source_invalid + }.compact + end + + def to_json(*args) + @options.to_json(*args) + end + end +end diff --git a/lib/htmlcsstoimage/recordings.rb b/lib/htmlcsstoimage/recordings.rb index 766d959..1dca48f 100644 --- a/lib/htmlcsstoimage/recordings.rb +++ b/lib/htmlcsstoimage/recordings.rb @@ -8,6 +8,7 @@ class HTMLCSSToImage # @see https://docs.htmlcsstoimage.com/parameters/actions/ # @see https://docs.htmlcsstoimage.com/parameters/trigger/ # @see https://docs.htmlcsstoimage.com/parameters/output/ + # @see https://docs.htmlcsstoimage.com/parameters/audio/ # # @param html [String] HTML to record, as a fragment or a complete document # @param params [Hash] browser, timeline, and output options passed to the API @@ -30,15 +31,14 @@ class HTMLCSSToImage # @option params [Array] :request_overrides Browser request block rules. Requires a paid plan. # @option params [Hash] :trigger Start condition: `type: "immediate"` (default), `"element_visible"` with a `selector`, or `"function_call"` to wait for `window.RecordingReady()`. Waiting triggers accept `timeout_ms`. # @option params [Array] :actions Ordered timeline interactions: `simple_scroll`, `scroll`, `stall`, `click`, `locate_selector`, `execute_javascript`, or `error`. Each action has a `type` discriminator. Each `scroll` action step requires `duration_ms` of at least 1. Omit or use an empty array to record without interactions. - # @option params [Hash] :output Media `format` (`mp4`, `webm`, or `gif`), `fps`, and pixel `scale`. Defaults to MP4 at 30 fps; GIF defaults to 15 fps. Recordings have no audio. + # @option params [Hash] :output Media `format` (`mp4`, `webm`, or `gif`), `fps`, and pixel `scale`. Defaults to MP4 at 30 fps; GIF defaults to 15 fps. + # @option params [RecordingAudio, Hash] :audio Optional MP4 or WebM soundtrack. Supply one Asset Library `asset_id` or public `url`. See {RecordingAudio#initialize} for playback options. # @option params [String] :duration_mode `at_most` (default) stops when actions finish or the duration is reached. `fixed` pads or cuts off at that duration. `at_least` lets actions finish up to 90 seconds. `target` adjusts playback speed to fit the duration. # @option params [Boolean] :defer_render Wait to render until media or storage is requested. Defaults to false; does not reset deduplicated recordings. # @option params [Boolean] :skip_scroll_preload Skip the preparation scroll that loads lazy content. Scrolling actions still run. Defaults to false. # @return [HTMLCSSToImage::ApiResponse] recording details at `.id`, `.status_url`, and `.recording_url` def create_html_css_recording(html, params = {}) - body = { html: html }.merge(params).to_json - - self.class.post("/v1/recording", basic_auth: @auth, body: body) + post_recording({ html: html }, params) end # Records a public HTTP or HTTPS webpage. @@ -58,9 +58,7 @@ def create_html_css_recording(html, params = {}) # @option params [Boolean] :include_headers_on_subrequests Also send custom headers with subrequests to allowed origins. Defaults to false. # @return [HTMLCSSToImage::ApiResponse] recording details at `.id`, `.status_url`, and `.recording_url` def create_url_recording(url, params = {}) - body = { url: url }.merge(params).to_json - - self.class.post("/v1/recording", basic_auth: @auth, body: body) + post_recording({ url: url }, params) end # Fetches a recording's current lifecycle state once. Checking status is @@ -105,4 +103,17 @@ def delete_recording_batch(recording_ids) response.success? ? true : response end + + private + + def post_recording(source, params) + body = source.merge(params).transform_keys(&:to_s) + audio = body["audio"] + if audio.is_a?(Hash) + body["audio"] = RecordingAudio.new(**audio.transform_keys(&:to_sym)) + elsif !audio.nil? && !audio.is_a?(RecordingAudio) + raise ArgumentError, "audio must be a RecordingAudio or a Hash" + end + self.class.post("/v1/recording", basic_auth: @auth, body: body.to_json) + end end diff --git a/lib/htmlcsstoimage/version.rb b/lib/htmlcsstoimage/version.rb index a2a8154..0575e77 100644 --- a/lib/htmlcsstoimage/version.rb +++ b/lib/htmlcsstoimage/version.rb @@ -1,4 +1,4 @@ class HTMLCSSToImage # Current version of the Ruby client gem. - VERSION = "1.0.0" + VERSION = "1.1.0" end diff --git a/spec/recordings_spec.rb b/spec/recordings_spec.rb index e42f5d6..7c8bdea 100644 --- a/spec/recordings_spec.rb +++ b/spec/recordings_spec.rb @@ -56,6 +56,35 @@ after { WebMock.reset! } + it "sends a private audio asset with explicit zero and false playback options" do + audio = HTMLCSSToImage::RecordingAudio.new(asset_id: "asset_1", source_start_ms: 0, + delay_ms: 500, when_audio_ends: "loop", error_on_source_invalid: false) + stub_api(:post, "/v1/recording", body: created).with do |request| + expect(JSON.parse(request.body).fetch("audio")).to eq({ + "asset_id" => "asset_1", "source_start_ms" => 0, "delay_ms" => 500, + "when_audio_ends" => "loop", "error_on_source_invalid" => false + }) + true + end + expect(client.create_html_css_recording("

    Intro

    ", duration_ms: 1000, audio: audio).id).to eq(created[:id]) + end + + it "accepts a public audio URL from a hash with string keys" do + audio = { "url" => "https://cdn.example.com/audio/intro.mp3" }.freeze + stub_api(:post, "/v1/recording", body: created).with do |request| + expect(JSON.parse(request.body).fetch("audio")).to eq(audio) + true + end + client.create_url_recording("https://example.com", { "duration_ms" => 1000, "audio" => audio }) + end + + it "rejects missing and conflicting audio sources before sending the request" do + [{}, { asset_id: "asset_1", url: "https://cdn.example.com/audio/intro.mp3" }].each do |audio| + expect { client.create_url_recording("https://example.com", duration_ms: 1000, audio: audio) } + .to raise_error(ArgumentError, /exactly one recording audio source/) + end + end + def stub_api(method, path, status: 200, body: nil) WebMock.stub_request(method, "https://hcti.io#{path}").with( headers: { "Authorization" => authorization } From c68ec51eab782e788c59ae7ed5db3894d5b43cc6 Mon Sep 17 00:00:00 2001 From: jsneedles Date: Wed, 25 Nov 2026 14:28:08 -0500 Subject: [PATCH 2/2] Pass recording audio through as a Ruby hash --- README.md | 2 +- docs/HTMLCSSToImage.html | 79 +++-- docs/HTMLCSSToImage/RecordingAudio.html | 400 ------------------------ docs/_index.html | 9 +- docs/class_list.html | 2 +- docs/file.README.html | 4 +- docs/index.html | 4 +- docs/method_list.html | 24 +- lib/htmlcsstoimage.rb | 1 - lib/htmlcsstoimage/recording_audio.rb | 31 -- lib/htmlcsstoimage/recordings.rb | 26 +- spec/recordings_spec.rb | 49 ++- 12 files changed, 84 insertions(+), 547 deletions(-) delete mode 100644 docs/HTMLCSSToImage/RecordingAudio.html delete mode 100644 lib/htmlcsstoimage/recording_audio.rb diff --git a/README.md b/README.md index 86e98fc..ecc3676 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ animation = client.create_html_css_recording( Both methods accept browser, timeline, and output options as hashes, following the image methods. Omitted settings use API defaults. -To add a soundtrack to MP4 or WebM, pass `audio: { asset_id: "YOUR_ASSET_ID", delay_ms: 500 }` or `audio: { url: "https://cdn.example.com/audio/intro.mp3" }` to either recording method. You can also reuse an `HTMLCSSToImage::RecordingAudio` instance with the same keyword arguments. [Audio sources and playback options](https://docs.htmlcsstoimage.com/parameters/audio/). +To add a soundtrack to MP4 or WebM, pass `audio: { asset_id: "YOUR_ASSET_ID", delay_ms: 500 }` or `audio: { url: "https://cdn.example.com/audio/intro.mp3" }` to either recording method. [Audio sources and playback options](https://docs.htmlcsstoimage.com/parameters/audio/). Triggers and actions use a `type` discriminator. For example, wait until an element is visible, click a button, and hold the result: diff --git a/docs/HTMLCSSToImage.html b/docs/HTMLCSSToImage.html index 32b7844..fea7169 100644 --- a/docs/HTMLCSSToImage.html +++ b/docs/HTMLCSSToImage.html @@ -102,7 +102,7 @@
    Defined in:
    lib/htmlcsstoimage/client.rb,
    - lib/htmlcsstoimage/images.rb,
    lib/htmlcsstoimage/version.rb,
    lib/htmlcsstoimage/templates.rb,
    lib/htmlcsstoimage/recordings.rb,
    lib/htmlcsstoimage/signed_urls.rb,
    lib/htmlcsstoimage/recording_audio.rb,
    lib/htmlcsstoimage/request_override_resource_type.rb
    + lib/htmlcsstoimage/images.rb,
    lib/htmlcsstoimage/version.rb,
    lib/htmlcsstoimage/templates.rb,
    lib/htmlcsstoimage/recordings.rb,
    lib/htmlcsstoimage/signed_urls.rb,
    lib/htmlcsstoimage/request_override_resource_type.rb
    @@ -124,7 +124,7 @@

    Overview

    - Classes: ApiResponse, RecordingAudio, RequestOverrideResourceType + Classes: ApiResponse, RequestOverrideResourceType

    @@ -1015,12 +1015,15 @@

  • :audio - (RecordingAudio, Hash) + (Hash) - —

    Optional MP4 or WebM soundtrack. Supply one Asset Library asset_id or public url. See HTMLCSSToImage::RecordingAudio#initialize for playback options.

    + —

    Optional MP4 or WebM soundtrack. Supply exactly one source, an Asset Library asset_id or a public HTTP(S) url. +source_start_ms skips into the track and delay_ms delays playback in the video. Both default to 0. +when_audio_ends accepts "silence" (default), "loop", or "trim_video". +Set error_on_source_invalid: false to return the full video silently if the track cannot play.

  • @@ -1098,15 +1101,19 @@

     
     
    -40
    -41
    -42
    +43 +44 +45 +46 +47

  • -
    # File 'lib/htmlcsstoimage/recordings.rb', line 40
    +      
    # File 'lib/htmlcsstoimage/recordings.rb', line 43
     
     def create_html_css_recording(html, params = {})
    -  post_recording({ html: html }, params)
    +  body = { html: html }.merge(params).to_json
    +
    +  self.class.post("/v1/recording", basic_auth: @auth, body: body)
     end
    -
    # File 'lib/htmlcsstoimage/recordings.rb', line 60
    +      
    # File 'lib/htmlcsstoimage/recordings.rb', line 65
     
     def create_url_recording(url, params = {})
    -  post_recording({ url: url }, params)
    +  body = { url: url }.merge(params).to_json
    +
    +  self.class.post("/v1/recording", basic_auth: @auth, body: body)
     end
    -
    # File 'lib/htmlcsstoimage/recordings.rb', line 84
    +      
    # File 'lib/htmlcsstoimage/recordings.rb', line 91
     
     def delete_recording(recording_id)
       response = self.class.delete("/v1/recordings/#{recording_id}", basic_auth: @auth)
    @@ -3085,20 +3096,20 @@ 

     
     
    -95
    -96
    -97
    -98
    -99
    -100
    -101
     102
     103
     104
    -105
    +105 +106 +107 +108 +109 +110 +111 +112

    -
    # File 'lib/htmlcsstoimage/recordings.rb', line 95
    +      
    # File 'lib/htmlcsstoimage/recordings.rb', line 102
     
     def delete_recording_batch(recording_ids)
       return true if recording_ids.empty?
    @@ -3187,12 +3198,12 @@ 

     
     
    -76
    -77
    -78
    +83 +84 +85

    -
    # File 'lib/htmlcsstoimage/recordings.rb', line 76
    +      
    # File 'lib/htmlcsstoimage/recordings.rb', line 83
     
     def fetch_recording_status(recording_id)
       self.class.get("/v1/recordings/#{recording_id}/status", basic_auth: @auth)
    @@ -4341,7 +4352,7 @@ 

    diff --git a/docs/HTMLCSSToImage/RecordingAudio.html b/docs/HTMLCSSToImage/RecordingAudio.html deleted file mode 100644 index 3f0e842..0000000 --- a/docs/HTMLCSSToImage/RecordingAudio.html +++ /dev/null @@ -1,400 +0,0 @@ - - - - - - - Class: HTMLCSSToImage::RecordingAudio - - — Documentation by YARD 0.9.45 - - - - - - - - - - - - - - - - - - - - - -
    - - -

    Class: HTMLCSSToImage::RecordingAudio - - - -

    -
    - -
    -
    Inherits:
    -
    - Object - -
      -
    • Object
    • - - - -
    - show all - -
    -
    - - - - - - - - - - - -
    -
    Defined in:
    -
    lib/htmlcsstoimage/recording_audio.rb -
    -
    - -
    - -

    Overview

    -
    -

    One soundtrack for an MP4 or WebM recording.

    - -
    -
    - - - - - - - - -

    - Instance Method Summary - collapse -

    - - - - - -
    -

    Constructor Details

    - -
    -

    - - #initialize(asset_id: nil, url: nil, source_start_ms: nil, delay_ms: nil, when_audio_ends: nil, error_on_source_invalid: nil) ⇒ RecordingAudio - - - - - -

    -
    -

    Returns a new instance of RecordingAudio.

    - -
    -
    -
    -

    Parameters:

    -
      - -
    • - - asset_id - - - (String, nil) - - - (defaults to: nil) - - - — -

      ID of a completed audio upload in your organization, which may be private

      - -
    • - -
    • - - url - - - (String, nil) - - - (defaults to: nil) - - - — -

      public HTTP or HTTPS URL serving the audio file at render time

      - -
    • - -
    • - - source_start_ms - - - (Integer, nil) - - - (defaults to: nil) - - - — -

      offset into the source file in milliseconds (default 0)

      - -
    • - -
    • - - delay_ms - - - (Integer, nil) - - - (defaults to: nil) - - - — -

      delay from the start of the finished video in milliseconds (default 0)

      - -
    • - -
    • - - when_audio_ends - - - (String, nil) - - - (defaults to: nil) - - - — -

      "silence" (default), "loop" from the source offset, or "trim_video"

      - -
    • - -
    • - - error_on_source_invalid - - - (Boolean, nil) - - - (defaults to: nil) - - - — -

      defaults to true; set false to return the full silent -video if the track cannot play at render time

      - -
    • - -
    - - -
    - - - - -
    -
    -
    -
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    -25
    -
    -
    # File 'lib/htmlcsstoimage/recording_audio.rb', line 12
    -
    -def initialize(asset_id: nil, url: nil, source_start_ms: nil, delay_ms: nil,
    -               when_audio_ends: nil, error_on_source_invalid: nil)
    -  if asset_id.nil? == url.nil?
    -    raise ArgumentError, "Supply exactly one recording audio source: asset_id or url"
    -  end
    -  if !when_audio_ends.nil? && !%w[silence loop trim_video].include?(when_audio_ends)
    -    raise ArgumentError, "when_audio_ends must be silence, loop, or trim_video"
    -  end
    -
    -  @options = {
    -    asset_id: asset_id, url: url, source_start_ms: source_start_ms, delay_ms: delay_ms,
    -    when_audio_ends: when_audio_ends, error_on_source_invalid: error_on_source_invalid
    -  }.compact
    -end
    -
    -
    - -
    - - -
    -

    Instance Method Details

    - - -
    -

    - - #to_json(*args) ⇒ Object - - - - - -

    - - - - -
    -
    -
    -
    -27
    -28
    -29
    -
    -
    # File 'lib/htmlcsstoimage/recording_audio.rb', line 27
    -
    -def to_json(*args)
    -  @options.to_json(*args)
    -end
    -
    -
    - -
    - -
    - - - -
    - - diff --git a/docs/_index.html b/docs/_index.html index cfce845..43d1563 100644 --- a/docs/_index.html +++ b/docs/_index.html @@ -110,13 +110,6 @@

    Namespace Listing A-Z

  • R
  • Both methods accept browser, timeline, and output options as hashes, following the image methods. Omitted settings use API defaults.

    -

    To add a soundtrack to MP4 or WebM, pass audio: { asset_id: "YOUR_ASSET_ID", delay_ms: 500 } or audio: { url: "https://cdn.example.com/audio/intro.mp3" } to either recording method. You can also reuse an HTMLCSSToImage::RecordingAudio instance with the same keyword arguments. Audio sources and playback options.

    +

    To add a soundtrack to MP4 or WebM, pass audio: { asset_id: "YOUR_ASSET_ID", delay_ms: 500 } or audio: { url: "https://cdn.example.com/audio/intro.mp3" } to either recording method. Audio sources and playback options.

    Triggers and actions use a type discriminator. For example, wait until an element is visible, click a button, and hold the result:

    demo = client.create_url_recording(
    @@ -354,7 +354,7 @@ 

    Templated image batches

    See the API reference for plan limits and examples.

    diff --git a/docs/index.html b/docs/index.html index 87ebe07..400627e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -159,7 +159,7 @@

    Recordings

    Both methods accept browser, timeline, and output options as hashes, following the image methods. Omitted settings use API defaults.

    -

    To add a soundtrack to MP4 or WebM, pass audio: { asset_id: "YOUR_ASSET_ID", delay_ms: 500 } or audio: { url: "https://cdn.example.com/audio/intro.mp3" } to either recording method. You can also reuse an HTMLCSSToImage::RecordingAudio instance with the same keyword arguments. Audio sources and playback options.

    +

    To add a soundtrack to MP4 or WebM, pass audio: { asset_id: "YOUR_ASSET_ID", delay_ms: 500 } or audio: { url: "https://cdn.example.com/audio/intro.mp3" } to either recording method. Audio sources and playback options.

    Triggers and actions use a type discriminator. For example, wait until an element is visible, click a button, and hold the result:

    demo = client.create_url_recording(
    @@ -354,7 +354,7 @@ 

    Templated image batches

    See the API reference for plan limits and examples.

    diff --git a/docs/method_list.html b/docs/method_list.html index ed1fc5e..f4720d7 100644 --- a/docs/method_list.html +++ b/docs/method_list.html @@ -184,14 +184,6 @@

    Method List

  • -
    - #initialize - HTMLCSSToImage::RecordingAudio -
    -
  • - - -
  • #initialize HTMLCSSToImage::RequestOverrideResourceType @@ -199,7 +191,7 @@

    Method List

  • -
  • +
  • #list_template_versions HTMLCSSToImage @@ -207,7 +199,7 @@

    Method List

  • -
  • +
  • #list_templates HTMLCSSToImage @@ -215,7 +207,7 @@

    Method List

  • -
  • +
  • #templates HTMLCSSToImage @@ -223,7 +215,7 @@

    Method List

  • -
  • +
  • #to_json HTMLCSSToImage::RequestOverrideResourceType @@ -231,14 +223,6 @@

    Method List

  • -
  • -
    - #to_json - HTMLCSSToImage::RecordingAudio -
    -
  • - -
  • #url_to_image diff --git a/lib/htmlcsstoimage.rb b/lib/htmlcsstoimage.rb index b27bc8b..fd61ec5 100644 --- a/lib/htmlcsstoimage.rb +++ b/lib/htmlcsstoimage.rb @@ -8,7 +8,6 @@ require "htmlcsstoimage/client" require "htmlcsstoimage/request_override_resource_type" require "htmlcsstoimage/images" -require "htmlcsstoimage/recording_audio" require "htmlcsstoimage/recordings" require "htmlcsstoimage/signed_urls" require "htmlcsstoimage/templates" diff --git a/lib/htmlcsstoimage/recording_audio.rb b/lib/htmlcsstoimage/recording_audio.rb deleted file mode 100644 index aa15813..0000000 --- a/lib/htmlcsstoimage/recording_audio.rb +++ /dev/null @@ -1,31 +0,0 @@ -class HTMLCSSToImage - # One soundtrack for an MP4 or WebM recording. - # @see https://docs.htmlcsstoimage.com/parameters/audio/ - class RecordingAudio - # @param asset_id [String, nil] ID of a completed audio upload in your organization, which may be private - # @param url [String, nil] public HTTP or HTTPS URL serving the audio file at render time - # @param source_start_ms [Integer, nil] offset into the source file in milliseconds (default 0) - # @param delay_ms [Integer, nil] delay from the start of the finished video in milliseconds (default 0) - # @param when_audio_ends [String, nil] "silence" (default), "loop" from the source offset, or "trim_video" - # @param error_on_source_invalid [Boolean, nil] defaults to true; set false to return the full silent - # video if the track cannot play at render time - def initialize(asset_id: nil, url: nil, source_start_ms: nil, delay_ms: nil, - when_audio_ends: nil, error_on_source_invalid: nil) - if asset_id.nil? == url.nil? - raise ArgumentError, "Supply exactly one recording audio source: asset_id or url" - end - if !when_audio_ends.nil? && !%w[silence loop trim_video].include?(when_audio_ends) - raise ArgumentError, "when_audio_ends must be silence, loop, or trim_video" - end - - @options = { - asset_id: asset_id, url: url, source_start_ms: source_start_ms, delay_ms: delay_ms, - when_audio_ends: when_audio_ends, error_on_source_invalid: error_on_source_invalid - }.compact - end - - def to_json(*args) - @options.to_json(*args) - end - end -end diff --git a/lib/htmlcsstoimage/recordings.rb b/lib/htmlcsstoimage/recordings.rb index 1dca48f..0371cc6 100644 --- a/lib/htmlcsstoimage/recordings.rb +++ b/lib/htmlcsstoimage/recordings.rb @@ -32,13 +32,18 @@ class HTMLCSSToImage # @option params [Hash] :trigger Start condition: `type: "immediate"` (default), `"element_visible"` with a `selector`, or `"function_call"` to wait for `window.RecordingReady()`. Waiting triggers accept `timeout_ms`. # @option params [Array] :actions Ordered timeline interactions: `simple_scroll`, `scroll`, `stall`, `click`, `locate_selector`, `execute_javascript`, or `error`. Each action has a `type` discriminator. Each `scroll` action step requires `duration_ms` of at least 1. Omit or use an empty array to record without interactions. # @option params [Hash] :output Media `format` (`mp4`, `webm`, or `gif`), `fps`, and pixel `scale`. Defaults to MP4 at 30 fps; GIF defaults to 15 fps. - # @option params [RecordingAudio, Hash] :audio Optional MP4 or WebM soundtrack. Supply one Asset Library `asset_id` or public `url`. See {RecordingAudio#initialize} for playback options. + # @option params [Hash] :audio Optional MP4 or WebM soundtrack. Supply exactly one source, an Asset Library `asset_id` or a public HTTP(S) `url`. + # `source_start_ms` skips into the track and `delay_ms` delays playback in the video. Both default to 0. + # `when_audio_ends` accepts `"silence"` (default), `"loop"`, or `"trim_video"`. + # Set `error_on_source_invalid: false` to return the full video silently if the track cannot play. # @option params [String] :duration_mode `at_most` (default) stops when actions finish or the duration is reached. `fixed` pads or cuts off at that duration. `at_least` lets actions finish up to 90 seconds. `target` adjusts playback speed to fit the duration. # @option params [Boolean] :defer_render Wait to render until media or storage is requested. Defaults to false; does not reset deduplicated recordings. # @option params [Boolean] :skip_scroll_preload Skip the preparation scroll that loads lazy content. Scrolling actions still run. Defaults to false. # @return [HTMLCSSToImage::ApiResponse] recording details at `.id`, `.status_url`, and `.recording_url` def create_html_css_recording(html, params = {}) - post_recording({ html: html }, params) + body = { html: html }.merge(params).to_json + + self.class.post("/v1/recording", basic_auth: @auth, body: body) end # Records a public HTTP or HTTPS webpage. @@ -58,7 +63,9 @@ def create_html_css_recording(html, params = {}) # @option params [Boolean] :include_headers_on_subrequests Also send custom headers with subrequests to allowed origins. Defaults to false. # @return [HTMLCSSToImage::ApiResponse] recording details at `.id`, `.status_url`, and `.recording_url` def create_url_recording(url, params = {}) - post_recording({ url: url }, params) + body = { url: url }.merge(params).to_json + + self.class.post("/v1/recording", basic_auth: @auth, body: body) end # Fetches a recording's current lifecycle state once. Checking status is @@ -103,17 +110,4 @@ def delete_recording_batch(recording_ids) response.success? ? true : response end - - private - - def post_recording(source, params) - body = source.merge(params).transform_keys(&:to_s) - audio = body["audio"] - if audio.is_a?(Hash) - body["audio"] = RecordingAudio.new(**audio.transform_keys(&:to_sym)) - elsif !audio.nil? && !audio.is_a?(RecordingAudio) - raise ArgumentError, "audio must be a RecordingAudio or a Hash" - end - self.class.post("/v1/recording", basic_auth: @auth, body: body.to_json) - end end diff --git a/spec/recordings_spec.rb b/spec/recordings_spec.rb index 7c8bdea..765dc8a 100644 --- a/spec/recordings_spec.rb +++ b/spec/recordings_spec.rb @@ -47,7 +47,7 @@ { type: "simple_scroll", scroll_distance: 900 }, { type: "stall", duration_ms: 0 } ], - output: { format: "gif", fps: 15, scale: 0.5 }, + output: { format: "webm", fps: 15, scale: 0.5 }, duration_mode: "at_least", defer_render: false, skip_scroll_preload: true @@ -56,35 +56,6 @@ after { WebMock.reset! } - it "sends a private audio asset with explicit zero and false playback options" do - audio = HTMLCSSToImage::RecordingAudio.new(asset_id: "asset_1", source_start_ms: 0, - delay_ms: 500, when_audio_ends: "loop", error_on_source_invalid: false) - stub_api(:post, "/v1/recording", body: created).with do |request| - expect(JSON.parse(request.body).fetch("audio")).to eq({ - "asset_id" => "asset_1", "source_start_ms" => 0, "delay_ms" => 500, - "when_audio_ends" => "loop", "error_on_source_invalid" => false - }) - true - end - expect(client.create_html_css_recording("

    Intro

    ", duration_ms: 1000, audio: audio).id).to eq(created[:id]) - end - - it "accepts a public audio URL from a hash with string keys" do - audio = { "url" => "https://cdn.example.com/audio/intro.mp3" }.freeze - stub_api(:post, "/v1/recording", body: created).with do |request| - expect(JSON.parse(request.body).fetch("audio")).to eq(audio) - true - end - client.create_url_recording("https://example.com", { "duration_ms" => 1000, "audio" => audio }) - end - - it "rejects missing and conflicting audio sources before sending the request" do - [{}, { asset_id: "asset_1", url: "https://cdn.example.com/audio/intro.mp3" }].each do |audio| - expect { client.create_url_recording("https://example.com", duration_ms: 1000, audio: audio) } - .to raise_error(ArgumentError, /exactly one recording audio source/) - end - end - def stub_api(method, path, status: 200, body: nil) WebMock.stub_request(method, "https://hcti.io#{path}").with( headers: { "Authorization" => authorization } @@ -96,7 +67,13 @@ def stub_api(method, path, status: 200, body: nil) end it "creates HTML recordings with all options and preserves nested branches without mutation" do - params = options.merge(google_fonts: "Roboto|Open Sans").freeze + params = options.merge( + google_fonts: "Roboto|Open Sans", + audio: { + asset_id: "asset_1", source_start_ms: 0, delay_ms: 500, + when_audio_ends: "loop", error_on_source_invalid: false + } + ).freeze before = Marshal.dump(params) expected = JSON.parse({ html: "

    Hello

    " }.merge(params).to_json) WebMock.stub_request(:post, "https://hcti.io/v1/recording").with do |request| @@ -116,6 +93,7 @@ def stub_api(method, path, status: 200, body: nil) it "creates URL recordings with headers and source-specific options" do params = options.merge( + audio: { "url" => "https://cdn.example.com/audio/intro.mp3" }, headers: { "Authorization" => "Bearer test" }, additional_header_origins: ["https://assets.example.com"], include_headers_on_subrequests: false, @@ -150,6 +128,15 @@ def stub_api(method, path, status: 200, body: nil) expect(client.create_html_css_recording("", duration_ms: 0).error).to eq("Bad Request") end + it "returns the API error when both audio sources are supplied" do + audio = { asset_id: "asset_1", url: "https://cdn.example.com/audio/intro.mp3" } + stub_api(:post, "/v1/recording", status: 400, body: { error: "Bad Request" }).with( + body: { html: "Demo", duration_ms: 1000, audio: audio }.to_json + ) + + expect(client.create_html_css_recording("Demo", duration_ms: 1000, audio: audio).code).to eq(400) + end + { "awaiting_render" => 202, "processing" => 202,