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 =
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
-
#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.
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
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
20 21 22 |
# File 'app/services/reviews_io_image_importer.rb', line 20 def errors @errors end |
#force ⇒ Object (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_count ⇒ Object (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 |
#review ⇒ Object (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_videos ⇒ Object (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
#call ⇒ Object
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.}" Rails.logger.error "[ReviewsIoImageImporter] Review #{review.id}, photo #{index}: #{e.}" end self end |
#success? ⇒ Boolean
49 50 51 |
# File 'app/services/reviews_io_image_importer.rb', line 49 def success? errors.empty? end |