Skip to content

Commit

Permalink
added twitter/twicture.es provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bumann committed Sep 28, 2008
1 parent 0bba6c2 commit 5ba8f53
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/embedit/providers/twitter.rb
@@ -0,0 +1,36 @@
module Embedit

class Twitter

attr_reader :title, :url, :format

def initialize(url)
@format = 'photo'
@url = url
end

def html(options = {})
attributes = options.collect {|k,v| "#{k}=\"#{v}\" "}.join(" ")
%{<img src="http://twictur.es/i/#{status_id}.gif" #{attributes} />}
end

def status_id
@status_id ||= url[/twitter\.com\/(\S+)\/statuses\/(\d+)/,2]
end

def title
@title ||= page.at("title").inner_html
end

def self.match(url)
url.match(/twitter\.com\/(\S+)\/statuses\/(\d+)/)
end

private

def page
@page ||= Hpricot(open(@url))
end
end

end
27 changes: 27 additions & 0 deletions spec/twitter_spec.rb
@@ -0,0 +1,27 @@
require File.dirname(__FILE__) + '/spec_helper.rb'

describe "Twitter" do

it "should show true on valid url" do
Embedit::Media.new("http://twitter.com/Bumi/statuses/937196371").should be_valid
end

it "should return the correct title" do
Embedit::Media.new("http://twitter.com/Bumi/statuses/937196371").title.should eql("Twitter / Michael Bumann: I love github!")
end

it "should show format as photo" do
Embedit::Media.new("http://twitter.com/Bumi/statuses/937196371").format.should eql("photo")
end

it "should accept width and height options for embeded code" do
embed = Embedit::Media.new("http://twitter.com/Bumi/statuses/937196371").html(:width=>200, :height => 100)
embed.match(/width="200"/).should_not be_nil
embed.match(/height="100"/).should_not be_nil
end

it "should return correct the embed code" do
Embedit::Media.new("http://twitter.com/Bumi/statuses/937196371").html.should eql('<img src="http://twictur.es/i/937196371.gif" />')
end

end

0 comments on commit 5ba8f53

Please sign in to comment.