Class: Oembed::ContentRefreshService
- Inherits:
-
Object
- Object
- Oembed::ContentRefreshService
- Defined in:
- app/services/oembed/content_refresh_service.rb
Overview
Service to refresh oEmbed content in blog posts
Scans posts for oEmbed markers and re-fetches content:
- data-wy-oembed="faq" - FAQ sections with JSON-LD schema
- data-wy-oembed="product" - Product embeds with pricing
- data-wy-oembed="video" / wy-video-embed - Video embeds (wrapper + play overlay)
- data-wy-oembed="image" / wy-image-embed - Image embeds (URLs, srcset, caption)
Product embeds are special:
- Prices are updated to reflect current catalog prices
- Products that become discontinued/unavailable are hidden
- Locale-aware pricing for US/Canada
Usage:
service = Oembed::ContentRefreshService.new
result = service.refresh_all
result = service.refresh_post(post)
Constant Summary collapse
- OEMBED_TYPES =
%w[faq product video image].freeze
Instance Method Summary collapse
-
#initialize ⇒ ContentRefreshService
constructor
A new instance of ContentRefreshService.
-
#refresh_all ⇒ Hash
Refresh all posts with oEmbed content.
-
#refresh_post(post) ⇒ Boolean
Refresh oEmbed content in a single post.
Constructor Details
#initialize ⇒ ContentRefreshService
Returns a new instance of ContentRefreshService.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/services/oembed/content_refresh_service.rb', line 25 def initialize @stats = { posts_scanned: 0, posts_updated: 0, faqs_refreshed: 0, products_refreshed: 0, products_hidden: 0, videos_refreshed: 0, images_refreshed: 0, errors: [] } end |
Instance Method Details
#refresh_all ⇒ Hash
Refresh all posts with oEmbed content
40 41 42 43 44 45 46 |
# File 'app/services/oembed/content_refresh_service.rb', line 40 def refresh_all .find_each do |post| refresh_post(post) end @stats end |
#refresh_post(post) ⇒ Boolean
Refresh oEmbed content in a single post
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/services/oembed/content_refresh_service.rb', line 51 def refresh_post(post) @stats[:posts_scanned] += 1 source = post_solution_html_for_refresh(post) return false if source.blank? updated_body = (source) return false if updated_body == source persist_refreshed_post_solution!(post, updated_body) @stats[:posts_updated] += 1 Rails.logger.info "[OembedRefresh] Updated post #{post.id}: #{post.subject}" true rescue StandardError => e @stats[:errors] << "Post #{post.id}: #{e.}" Rails.logger.error "[OembedRefresh] Error refreshing post #{post.id}: #{e.}" false end |