Skip to content

Instantly share code, notes, and snippets.

@bogdan
Last active November 17, 2017 19:32
Show Gist options
  • Save bogdan/7a823c15ac350aaf948668f0fc3a3238 to your computer and use it in GitHub Desktop.
Save bogdan/7a823c15ac350aaf948668f0fc3a3238 to your computer and use it in GitHub Desktop.
# Our architecture didn't allow us
# to customize message body in a right way.
# That is why we fuck it up right here.
def fuck_short_url(text)
return nil unless text
# Offer short url in email should differ from generic one
# Additional parameters should be included:
# share_specific_short_url includes {source: 'email', email_shared_with: email}
# Sometimes we can not avoid this hack because of the following usecase:
# When user is sharing offer via email though talkable offer page
# Email body might have a link within.
# For example user sees the following message body:
# "I can get you $25 off with this link: http://www.talkable.com/x/Uk6EX"
# In "Share this offer by email" form
# But this link doesn't yet know the email person wants to share with.
# And we are not able to set a placeholder
# That is why we need this hack to replace it.
whitelist = [site.url, site.custom_domain].compact
text.gsub(URI.regexp(['http', 'https'])) do |url|
whitelist.include?(url) ? url : self.share_specific_short_url
end
end
@vanclist
Copy link

Typo: though -> through

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment