Permalink
Browse files

Truncate Tweet with link to original on long notes

  • Loading branch information...
adamdawkins committed Jan 21, 2019
1 parent b90af40 commit dce024ad7d7cf02e24c43c433c31801cf993e150
Showing with 10 additions and 0 deletions.
  1. +10 −0 app/services/twitter_service.rb
@@ -5,10 +5,20 @@
config.access_token_secret = Rails.application.credentials.twitter[:access_token_secret]
end

MAX_TWEET_LENGTH = 280

class TwitterService
def self.post(post)
tweet = post.content
tweet.gsub!('*', '')
if (tweet.length > MAX_TWEET_LENGTH)
pp "too long"
pp post.id
url = "#{ENV['SHORT_URL']}/#{post.id}"
pp url
cut_off = MAX_TWEET_LENGTH - url.length - 4 # the 4 is 3 elipses dots + a space or return
tweet = "#{tweet[0..cut_off]}...\r#{url}"
end
response = TwitterClient.update(tweet)

twitter_silo = Silo.find_by(name: "Twitter")

0 comments on commit dce024a

Please sign in to comment.