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 =

Recognised 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.



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

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.



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

def errors
  @errors
end

#forceObject (readonly)

Returns the value of attribute force.



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

def force
  @force
end

#imported_countObject (readonly)

Returns the value of attribute imported_count.



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

def imported_count
  @imported_count
end

#reviewObject (readonly)

Returns the value of attribute review.



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

def review
  @review
end

Instance Method Details

#callObject



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

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)


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

def success?
  errors.empty?
end