Links in the message translate into a proper link on Facebook when sending to facebook.

This commit is contained in:
Uiri 2011-09-26 16:40:53 -04:00
parent 49bee9bf19
commit 82feff7fb4

View file

@ -9,7 +9,15 @@ class Services::Facebook < Service
Rails.logger.debug("event=post_to_service type=facebook sender_id=#{self.user_id}")
message = public_message(post, url)
begin
Faraday.post("https://graph.facebook.com/me/feed", {:message => message, :access_token => self.access_token}.to_param)
if /https?:\/\/(.+) / =~ message
link = /https?:\/\/(.+) /.match(message)[0]
Faraday.post("https://graph.facebook.com/me/feed", {:message => message, :link => link, :access_token => self.access_token}.to_param)
elsif /https?:\/\/(.+)$/ =~ message
link = /https?:\/\/(.+)$/.match(message)[0]
Faraday.post("https://graph.facebook.com/me/feed", {:message => message, :link => link, :access_token => self.access_token}.to_param)
else
Faraday.post("https://graph.facebook.com/me/feed", {:message => message, :access_token => self.access_token}.to_param)
end
rescue Exception => e
Rails.logger.info("#{e.message} failed to post to facebook")
end