Class: Oembed::WyVideoProvider

Inherits:
Object
  • Object
show all
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 =
%w[iframe html5 email].freeze

Instance Method Summary collapse

Constructor Details

#initialize(view_context: nil) ⇒ WyVideoProvider

Returns a new instance of WyVideoProvider.



37
38
39
# File 'app/services/oembed/wy_video_provider.rb', line 37

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'

Returns:

  • (Hash)

    oEmbed response data

Raises:



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/services/oembed/wy_video_provider.rb', line 56

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)


44
45
46
# File 'app/services/oembed/wy_video_provider.rb', line 44

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