Class: Oembed::WyVideoProvider

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
app/services/oembed/wy_video_provider.rb

Overview

Custom oEmbed provider for WarmlyYours videos
Returns video embed HTML - either iframe (for CRM/editor) or html5 (for WWW frontend)

Handles URLs like:

Player types:

  • 'iframe' (default): Cloudflare iframe with built-in controls (for CRM/editors)
  • 'html5': Shaka player with HLS/captions support (for WWW frontend)

Examples:

provider = Oembed::WyVideoProvider.new
if provider.handles?('https://www.warmlyyours.com/videos/my-video')
  # Iframe mode (default, for editors)
  result = provider.get('https://www.warmlyyours.com/videos/my-video')

  # HTML5 mode (for frontend rendering)
  result = provider.get('https://www.warmlyyours.com/videos/my-video', player_type: 'html5')
end

Defined Under Namespace

Classes: VideoNotFoundError

Constant Summary collapse

URL_PATTERNS =

URL patterns we handle

[
  # Production: warmlyyours.com
  %r{https?://(?:www\.)?warmlyyours\.com/(?:[a-z]{2}-[A-Z]{2}/)?videos/([^/?#]+)},
  # Development: warmlyyours.me
  %r{https?://(?:www\.)?warmlyyours\.me(?::\d+)?/(?:[a-z]{2}-[A-Z]{2}/)?videos/([^/?#]+)}
].freeze
PLAYER_TYPES =

Recognised player types.

%w[iframe html5 email].freeze

Instance Method Summary collapse

Constructor Details

#initialize(view_context: nil) ⇒ WyVideoProvider

Returns a new instance of WyVideoProvider.



41
42
43
# File 'app/services/oembed/wy_video_provider.rb', line 41

def initialize(view_context: nil)
  @view_context = view_context
end

Instance Method Details

#get(url, options = {}) ⇒ Hash

Get oEmbed data for a WY video URL

Parameters:

  • url (String)

    The video URL

  • options (Hash) (defaults to: {})

    Optional parameters:

    • maxwidth: Maximum width for the embed (default: 800)
    • maxheight: Maximum height for the embed (default: 450)
    • player_type: 'iframe' (default) or 'html5'

Options Hash (options):

  • :maxwidth (Integer)

    maximum width for the embed (default: 800)

  • :maxheight (Integer)

    maximum height for the embed (default: 450)

  • :player_type (String)

    'iframe' (default) or 'html5'

  • :poster_url (String)

    poster image URL override

  • :include_wrapper (Boolean)

    wrap the embed HTML

  • :embedded_asset_uuid (String)

    EmbeddedAsset UUID for tracking

Returns:

  • (Hash)

    oEmbed response data

Raises:



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/services/oembed/wy_video_provider.rb', line 66

def get(url, options = {})
  slug = extract_slug(url)
  raise VideoNotFoundError, "Invalid WY video URL: #{url}" unless slug

  video = Video.friendly.find_by(slug: slug)
  raise VideoNotFoundError, "Video not found: #{slug}" unless video

  # Default to iframe for CRM/editor contexts (has built-in controls)
  player_type = options[:player_type].to_s
  player_type = 'iframe' unless PLAYER_TYPES.include?(player_type)

  build_oembed_response(video, options.merge(player_type: player_type))
end

#handles?(url) ⇒ Boolean

Check if this provider handles the given URL

Parameters:

  • url (String)

Returns:

  • (Boolean)


48
49
50
# File 'app/services/oembed/wy_video_provider.rb', line 48

def handles?(url)
  extract_slug(url).present?
end