Sha256: c3f704876c0dc9e87c67f65245ca065f86595706a987159dafe21990d4785741

Contents?: true

Size: 446 Bytes

Versions: 1

Compression:

Stored size: 446 Bytes

Contents

AutoHtml.add_filter(:twitter).with({}) do |text, options|
  require 'uri'
  require 'net/http'

  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.2 lib/auto_html/filters/twitter.rb