Class: ReviewsIoImageImporter

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

Overview

Imports review photos from Reviews.io into the Image library (ImageKit).
Creates Image records, tags them, and links them back to the ReviewsIo record.

Handles both the photos column and raw_api_data['photos_raw'] data.
Skips video assets (logs them for future video import support).

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

Constant Summary collapse

IMAGEKIT_FOLDER =
'img/reviews/'
BASE_TAGS =
%w[review-photo reviews-io user-generated-content].freeze
VIDEO_EXTENSIONS =
%w[.mp4 .mov .avi .webm .mkv .m4v].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(review, force: false) ⇒ ReviewsIoImageImporter

Returns a new instance of ReviewsIoImageImporter.



19
20
21
22
23
24
25
# File 'app/services/reviews_io_image_importer.rb', line 19

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

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



17
18
19
# File 'app/services/reviews_io_image_importer.rb', line 17

def errors
  @errors
end

#forceObject (readonly)

Returns the value of attribute force.



17
18
19
# File 'app/services/reviews_io_image_importer.rb', line 17

def force
  @force
end

#imported_countObject (readonly)

Returns the value of attribute imported_count.



17
18
19
# File 'app/services/reviews_io_image_importer.rb', line 17

def imported_count
  @imported_count
end

#reviewObject (readonly)

Returns the value of attribute review.



17
18
19
# File 'app/services/reviews_io_image_importer.rb', line 17

def review
  @review
end

#skipped_videosObject (readonly)

Returns the value of attribute skipped_videos.



17
18
19
# File 'app/services/reviews_io_image_importer.rb', line 17

def skipped_videos
  @skipped_videos
end

Instance Method Details

#callObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/services/reviews_io_image_importer.rb', line 27

def call
  return self unless review.has_media?

  review.photo_urls.each_with_index do |url, index|
    if video_url?(url)
      @skipped_videos += 1
      Rails.logger.info "[ReviewsIoImageImporter] Review #{review.id}: skipped video URL #{url.truncate(80)}"
      next
    end

    import_single_photo(url, index)
  rescue StandardError => e
    @errors << "Photo #{index} (#{url.truncate(80)}): #{e.message}"
    Rails.logger.error "[ReviewsIoImageImporter] Review #{review.id}, photo #{index}: #{e.message}"
  end

  self
end

#success?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/services/reviews_io_image_importer.rb', line 46

def success?
  errors.empty?
end