Created
September 3, 2012 23:03
-
-
Save fantattitude/3614500 to your computer and use it in GitHub Desktop.
Go from simple http link to twitter embed automagically using RedCarpet !
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
def autolink(link, link_type) | |
statusReg = /https?:\/\/twitter\.com\/[a-zA-Z]+\/status\/([0-9]+)/ | |
if link_type == :url | |
if link =~ statusReg | |
tweet = statusReg.match(link) | |
urlTweet = tweet[0] | |
idTweet = tweet[1] | |
uri = URI.parse("https://api.twitter.com/1/statuses/oembed.json?id=#{idTweet}") | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
request = Net::HTTP::Get.new(uri.request_uri) | |
response = http.request(request) | |
jsonTweet = ActiveSupport::JSON.decode(response.body) | |
jsonTweet["html"] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment