Class: ReviewsIoImageImporter
- Inherits:
-
Object
- Object
- ReviewsIoImageImporter
- 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
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#force ⇒ Object
readonly
Returns the value of attribute force.
-
#imported_count ⇒ Object
readonly
Returns the value of attribute imported_count.
-
#review ⇒ Object
readonly
Returns the value of attribute review.
-
#skipped_videos ⇒ Object
readonly
Returns the value of attribute skipped_videos.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(review, force: false) ⇒ ReviewsIoImageImporter
constructor
A new instance of ReviewsIoImageImporter.
- #success? ⇒ Boolean
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
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
17 18 19 |
# File 'app/services/reviews_io_image_importer.rb', line 17 def errors @errors end |
#force ⇒ Object (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_count ⇒ Object (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 |
#review ⇒ Object (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_videos ⇒ Object (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
#call ⇒ Object
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.}" Rails.logger.error "[ReviewsIoImageImporter] Review #{review.id}, photo #{index}: #{e.}" end self end |
#success? ⇒ Boolean
46 47 48 |
# File 'app/services/reviews_io_image_importer.rb', line 46 def success? errors.empty? end |