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 =

Imagekit folder.

'img/reviews/'
BASE_TAGS =

Recognised base tags.

%w[review-photo reviews-io user-generated-content].freeze
VIDEO_EXTENSIONS =

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.



22
23
24
25
26
27
28
# File 'app/services/reviews_io_image_importer.rb', line 22

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.



20
21
22
# File 'app/services/reviews_io_image_importer.rb', line 20

def errors
  @errors
end

#forceObject (readonly)

Returns the value of attribute force.



20
21
22
# File 'app/services/reviews_io_image_importer.rb', line 20

def force
  @force
end

#imported_countObject (readonly)

Returns the value of attribute imported_count.



20
21
22
# File 'app/services/reviews_io_image_importer.rb', line 20

def imported_count
  @imported_count
end

#reviewObject (readonly)

Returns the value of attribute review.



20
21
22
# File 'app/services/reviews_io_image_importer.rb', line 20

def review
  @review
end

#skipped_videosObject (readonly)

Returns the value of attribute skipped_videos.



20
21
22
# File 'app/services/reviews_io_image_importer.rb', line 20

def skipped_videos
  @skipped_videos
end

Instance Method Details

#callObject



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

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)


49
50
51
# File 'app/services/reviews_io_image_importer.rb', line 49

def success?
  errors.empty?
end