Skip to content

Commit

Permalink
Merge pull request sferik#349 from bshelton229/oembed-url
Browse files Browse the repository at this point in the history
Allow the oembed endpoints to take a url as well as a status id
  • Loading branch information
sferik committed Feb 6, 2013
2 parents 19c176c + 0d986fa commit 1d94549
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/twitter/api/tweets.rb
Expand Up @@ -224,7 +224,8 @@ def update_with_media(status, media, options={})
# @example Return oEmbeds for Tweet with the ID 25938088801
# Twitter.status_with_activity(25938088801)
def oembed(id, options={})
object_from_response(Twitter::OEmbed, :get, "/1.1/statuses/oembed.json?id=#{id}", options)
lookup = ( id.kind_of?(String) and id =~ /^https?:\/\//i ) ? "url" : "id"
object_from_response(Twitter::OEmbed, :get, "/1.1/statuses/oembed.json?#{lookup}=#{id}", options)
end

# Returns oEmbeds for Tweets
Expand All @@ -251,7 +252,7 @@ def oembed(id, options={})
def oembeds(*args)
arguments = Twitter::API::Arguments.new(args)
arguments.flatten.threaded_map do |id|
object_from_response(Twitter::OEmbed, :get, "/1.1/statuses/oembed.json?id=#{id}", arguments.options)
oembed(id, arguments.options)
end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/twitter/api/tweets_spec.rb
Expand Up @@ -220,11 +220,16 @@
describe "#oembed" do
before do
stub_get("/1.1/statuses/oembed.json").with(:query => {:id => "25938088801"}).to_return(:body => fixture("oembed.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1.1/statuses/oembed.json").with(:query => {:url => "https://twitter.com/sferik/status/25938088801"}).to_return(:body => fixture("oembed.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.oembed(25938088801)
expect(a_get("/1.1/statuses/oembed.json").with(:query => {:id => "25938088801"})).to have_been_made
end
it "requests the correct resource when a url is given" do
@client.oembed("https://twitter.com/sferik/status/25938088801")
expect(a_get("/1.1/statuses/oembed.json").with(:query => {:url => "https://twitter.com/sferik/status/25938088801"}))
end
it "returns an array of OEmbed instances" do
oembed = @client.oembed(25938088801)
expect(oembed).to be_a Twitter::OEmbed
Expand All @@ -234,11 +239,16 @@
describe "#oembeds" do
before do
stub_get("/1.1/statuses/oembed.json").with(:query => {:id => "25938088801"}).to_return(:body => fixture("oembed.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1.1/statuses/oembed.json").with(:query => {:url => "https://twitter.com/sferik/status/25938088801"}).to_return(:body => fixture("oembed.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.oembeds(25938088801)
expect(a_get("/1.1/statuses/oembed.json").with(:query => {:id => "25938088801"})).to have_been_made
end
it "requests the correct resource when a url is given" do
@client.oembeds("https://twitter.com/sferik/status/25938088801")
expect(a_get("/1.1/statuses/oembed.json").with(:query => {:url => "https://twitter.com/sferik/status/25938088801"})).to have_been_made
end
it "returns an array of OEmbed instances" do
oembeds = @client.oembeds(25938088801)
expect(oembeds).to be_an Array
Expand Down

0 comments on commit 1d94549

Please sign in to comment.