Class: SpreeCmCommissioner::ProfileImageUpdater
- Inherits:
-
BaseInteractor
- Object
- BaseInteractor
- SpreeCmCommissioner::ProfileImageUpdater
- Defined in:
- app/interactors/spree_cm_commissioner/profile_image_updater.rb
Instance Method Summary collapse
-
#call ⇒ Object
url: ‘
’.
Instance Method Details
#call ⇒ Object
url: ‘
’
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/interactors/spree_cm_commissioner/profile_image_updater.rb', line 4 def call presigned_url = SpreeCmCommissioner::S3UrlGenerator.s3_presigned_url(context.url) response = Faraday.get(presigned_url) if response.success? user = context.user io = StringIO.new(response.body) filename = File.basename(context.url) profile = user.profile || SpreeCmCommissioner::UserProfile.new(viewable: user) profile..attach(io: io, filename: filename) if profile.save context.result = profile else context.fail!(message: profile.errors..join(',')) end end rescue StandardError => e context.fail!(message: "Error fetching the remote image: #{e.message}") end |