Skip to content

Commit

Permalink
barebones oembed support: id only, no other params yet. this is just …
Browse files Browse the repository at this point in the history
…to get the gem to build with the new functionality so I can test it under irb
  • Loading branch information
Oliver Azevedo Barnes committed Dec 26, 2011
1 parent 5e23b67 commit 084623f
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/twitter/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require 'twitter/follow'
require 'twitter/mention'
require 'twitter/metadata'
require 'twitter/oembed'
require 'twitter/photo'
require 'twitter/place'
require 'twitter/point'
Expand Down
13 changes: 12 additions & 1 deletion lib/twitter/client/tweets.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'twitter/status'
require 'twitter/oembed'

module Twitter
class Client
Expand Down Expand Up @@ -68,7 +69,17 @@ def status(id, options={})
status = get("/1/statuses/show/#{id}.json", options)
Twitter::Status.new(status)
end


# Returns an oEmbed version of a single status, specified by ID or url to the tweet
#
# @see https://dev.twitter.com/docs/api/1/get/statuses/oembed
# @rate_limited Yes
# @requires_authentication No unless the author of the status is protected
# @param id [Integer] The numerical ID of the desired status to be embedded.
def oembed(id)
oembed = get("/1/statuses/oembed.json?id=#{id}")
Twitter::OEmbed.new(oembed)
end
# Destroys the specified status
#
# @see https://dev.twitter.com/docs/api/1/post/statuses/destroy/:id
Expand Down
8 changes: 8 additions & 0 deletions lib/twitter/oembed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'twitter/base'

module Twitter
class OEmbed < Twitter::Base
lazy_attr_reader :author_name,:author_url, :cache_age, :height, :html, :id,
:provider_name, :provider_url, :type, :width, :url, :version
end
end
1 change: 1 addition & 0 deletions spec/fixtures/oembed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"rich","url":"https:\/\/twitter.com\/sferik\/status\/25938088801","author_url":"https:\/\/twitter.com\/sferik","provider_name":"Twitter","height":null,"html":"\u003Cblockquote class=\"twitter-tweet\"\u003E\u003Cp\u003E@\u003Ca href=\"https:\/\/twitter.com\/noradio\"\u003Enoradio\u003C\/a\u003E working on implementing \u003Ca href=\"https:\/\/twitter.com\/search\/%2523NewTwitter\"\u003E#NewTwitter\u003C\/a\u003E API methods in the twitter gem. Twurl is making it easy. Thank you!\u003C\/p\u003E&mdash; Erik Michaels-Ober (@sferik) \u003Ca href=\"https:\/\/twitter.com\/sferik\/status\/25938088801\" data-datetime=\"2010-09-30T01:43:44+00:00\"\u003ESeptember 30, 2010\u003C\/a\u003E\u003C\/blockquote\u003E\n\u003Cscript src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"\u003E\u003C\/script\u003E","provider_url":"http:\/\/twitter.com","author_name":"Erik Michaels-Ober","version":"1.0","width":550,"cache_age":"31536000000"}
3 changes: 3 additions & 0 deletions spec/helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require 'simplecov'
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
SimpleCov.start

require 'twitter'
require 'rspec'
require 'webmock/rspec'
Expand Down
18 changes: 18 additions & 0 deletions spec/twitter/client/tweets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,23 @@
status.media.should be
end
end

describe ".oembed" do
context "with id passed" do
before do
stub_get("/1/statuses/oembed.json?id=25938088801").
to_return(:body => fixture("oembed.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@client.oembed(25938088801)
a_get("/1/statuses/oembed.json?id=25938088801").
should have_been_made
end
it "should return an oembed instance" do
oembed = @client.oembed(25938088801)
oembed.should be_a Twitter::OEmbed
end
end
end

end
145 changes: 145 additions & 0 deletions spec/twitter/oembed_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
require 'helper'

describe Twitter::OEmbed do
describe "#author_url" do
it "should return the author's url" do
oembed = Twitter::OEmbed.new('author_url' => 'https://twitter.com/sferik')
oembed.author_url.should == "https://twitter.com/sferik"
end

it "should return nil when not set" do
author_url = Twitter::OEmbed.new.author_url
author_url.should be_nil
end
end

describe "#author_name" do
it "should return the author's name" do
oembed = Twitter::OEmbed.new('author_name' => 'Erik Michaels-Ober')
oembed.author_name.should == "Erik Michaels-Ober"
end

it "should return nil when not set" do
author_name = Twitter::OEmbed.new.author_name
author_name.should be_nil
end
end

describe "#cache_age" do
it "should return the cache_age" do
oembed = Twitter::OEmbed.new('cache_age' => '31536000000')
oembed.cache_age.should == "31536000000"
end

it "should return nil when not set" do
cache_age = Twitter::OEmbed.new.cache_age
cache_age.should be_nil
end
end

describe "#height" do
it "should return the height" do
oembed = Twitter::OEmbed.new('height' => 200)
oembed.height.should == 200
end

it "should return it as a Fixnum" do
oembed = Twitter::OEmbed.new('height' => 200)
oembed.height.should be_a Fixnum
end

it "should return nil when not set" do
height = Twitter::OEmbed.new.height
height.should be_nil
end
end

describe "#html" do
it "should return the html" do
oembed = Twitter::OEmbed.new('html' => '<blockquote>all my <b>witty tweet</b> stuff here</blockquote>')
oembed.html.should == "<blockquote>all my <b>witty tweet</b> stuff here</blockquote>"
end

it "should return nil when not set" do
html = Twitter::OEmbed.new.html
html.should be_nil
end
end

describe "#provider_name" do
it "should return the provider_name" do
oembed = Twitter::OEmbed.new('provider_name' => 'Twitter')
oembed.provider_name.should == "Twitter"
end

it "should return nil when not set" do
provider_name = Twitter::OEmbed.new.provider_name
provider_name.should be_nil
end
end

describe "#provider_url" do
it "should return the provider_url" do
oembed = Twitter::OEmbed.new('provider_url' => 'http://twitter.com')
oembed.provider_url.should == "http://twitter.com"
end

it "should return nil when not set" do
provider_url = Twitter::OEmbed.new.provider_url
provider_url.should be_nil
end
end

describe "#type" do
it "should return the type" do
oembed = Twitter::OEmbed.new('type' => 'rich')
oembed.type.should == "rich"
end

it "should return nil when not set" do
type = Twitter::OEmbed.new.type
type.should be_nil
end
end

describe "#width" do
it "should return the width" do
oembed = Twitter::OEmbed.new('width' => 550)
oembed.width.should == 550
end

it "should return it as a Fixnum" do
oembed = Twitter::OEmbed.new('width' => 550)
oembed.width.should be_a Fixnum
end

it "should return nil when not set" do
width = Twitter::OEmbed.new.width
width.should be_nil
end
end

describe "#url" do
it "should return the url" do
oembed = Twitter::OEmbed.new('url' => 'https://twitter.com/twitterapi/status/133640144317198338')
oembed.url.should == "https://twitter.com/twitterapi/status/133640144317198338"
end

it "should return nil when not set" do
url = Twitter::OEmbed.new.url
url.should be_nil
end
end

describe "#version" do
it "should return the version" do
oembed = Twitter::OEmbed.new('version' => '1.0')
oembed.version.should == "1.0"
end

it "should return nil when not set" do
version = Twitter::OEmbed.new.version
version.should be_nil
end
end
end

0 comments on commit 084623f

Please sign in to comment.