-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set twitter images from our db or cloudinary conditionally
- Loading branch information
1 parent
65af126
commit 85e516b
Showing
4 changed files
with
27 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
module ApplicationHelper | ||
def get_twitter_image(twitter_handle) | ||
image_tag "https://res.cloudinary.com/#{ENV['CLOUDINARY_HANDLE']}/image/twitter_name/#{twitter_handle}.jpg", onerror: 'this.error=null;this.src="https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png"' | ||
def get_twitter_image(user) | ||
image_tag image_for_twitter_handle(user), onerror: 'this.error=null;this.src="https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png"' | ||
end | ||
|
||
private | ||
|
||
RubyConfIndia2023 = Date.parse('2023-08-26') | ||
|
||
def image_for_twitter_handle(user) | ||
if user.updated_at.after?(RubyConfIndia2023) && user.image.present? | ||
# this is a quick workaround for being unable to fetch images via Cloudinary for new twitter sign_ins due to Twitter API policy changes. | ||
# one problem with continuing to use this long term would be: | ||
# - if a user changes their profile picture, the url saved on our model will become invalid | ||
# we do have a fallback to default image in place, but it's not ideal | ||
# - As an improvement, we can try to cache it (more like a permanent snapshot until their next login) | ||
# - But a proper solution would be to fetch their current profile picture via a service or to periodically refresh it ourself | ||
user.image | ||
else | ||
cloudinary_image_url(user.twitter_handle) | ||
end | ||
end | ||
|
||
def cloudinary_image_url(twitter_handle) | ||
"https://res.cloudinary.com/#{ENV['CLOUDINARY_HANDLE']}/image/twitter_name/#{twitter_handle}.jpg" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters