Class: ReviewsIoVideoImporter

Inherits:
Object
  • Object
show all
Defined in:
app/services/reviews_io_video_importer.rb

Overview

Imports review videos from Reviews.io into the Video library via Cloudflare Stream.
Creates Video records with category 'ugc' (invisible on the public site),
tags them, and links them back to the ReviewsIo record.

Usage:
ReviewsIoVideoImporter.new(review).call
ReviewsIoVideoImporter.new(review, force: true).call # re-import all

Constant Summary collapse

BASE_TAGS =
%w[review-video reviews-io ugc user-generated-content].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(review, force: false) ⇒ ReviewsIoVideoImporter

Returns a new instance of ReviewsIoVideoImporter.



15
16
17
18
19
20
# File 'app/services/reviews_io_video_importer.rb', line 15

def initialize(review, force: false)
  @review = review
  @force = force
  @imported_count = 0
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



13
14
15
# File 'app/services/reviews_io_video_importer.rb', line 13

def errors
  @errors
end

#forceObject (readonly)

Returns the value of attribute force.



13
14
15
# File 'app/services/reviews_io_video_importer.rb', line 13

def force
  @force
end

#imported_countObject (readonly)

Returns the value of attribute imported_count.



13
14
15
# File 'app/services/reviews_io_video_importer.rb', line 13

def imported_count
  @imported_count
end

#reviewObject (readonly)

Returns the value of attribute review.



13
14
15
# File 'app/services/reviews_io_video_importer.rb', line 13

def review
  @review
end

Instance Method Details

#callObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/reviews_io_video_importer.rb', line 22

def call
  return self unless review.has_videos?

  review.video_urls.each_with_index do |url, index|
    import_single_video(url, index)
  rescue StandardError => e
    @errors << "Video #{index} (#{url.truncate(80)}): #{e.message}"
    Rails.logger.error "[ReviewsIoVideoImporter] Review #{review.id}, video #{index}: #{e.message}"
  end

  self
end

#success?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/services/reviews_io_video_importer.rb', line 35

def success?
  errors.empty?
end