Sha256: eb99fead83b69e2927545af18e5e7c5dc59fe475ebb324fa3db4af89a0a87634

Contents?: true

Size: 442 Bytes

Versions: 1

Compression:

Stored size: 442 Bytes

Contents

require 'uri'
require 'net/http'

AutoHtml.add_filter(:twitter).with({}) do |text, options|
  regex = %r{(?<!href=")https://twitter\.com(/#!)?/[A-Za-z0-9_]{1,15}/status(es)?/\d+}

  text.gsub(regex) do |match|
    params = { :url => match }.merge(options)

    uri = URI("http://api.twitter.com/1/statuses/oembed.json")
    uri.query = URI.encode_www_form(params)

    response = JSON.parse(Net::HTTP.get(uri))
    response["html"]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
auto_html-1.6.1 lib/auto_html/filters/twitter.rb