Class: Oembed::WyVideoProvider
- Inherits:
-
Object
- Object
- Oembed::WyVideoProvider
- 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:
- https://www.warmlyyours.com/videos/my-video-slug
- https://www.warmlyyours.com/en-US/videos/my-video-slug
- https://www.warmlyyours.me/videos/my-video-slug (dev)
Player types:
- 'iframe' (default): Cloudflare iframe with built-in controls (for CRM/editors)
- 'html5': Shaka player with HLS/captions support (for WWW frontend)
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
-
#get(url, options = {}) ⇒ Hash
Get oEmbed data for a WY video URL.
-
#handles?(url) ⇒ Boolean
Check if this provider handles the given URL.
-
#initialize(view_context: nil) ⇒ WyVideoProvider
constructor
A new instance of WyVideoProvider.
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
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, = {}) 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 = [:player_type].to_s player_type = 'iframe' unless PLAYER_TYPES.include?(player_type) (video, .merge(player_type: player_type)) end |
#handles?(url) ⇒ Boolean
Check if this provider handles the given URL
44 45 46 |
# File 'app/services/oembed/wy_video_provider.rb', line 44 def handles?(url) extract_slug(url).present? end |