Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Oembed methods can take a url or id.

  • Loading branch information...
commit 0d986fa4b0c254e8c816bce086c3f6648d8fd3d7 1 parent 0b4d2e5
@bshelton229 bshelton229 authored
Showing with 13 additions and 2 deletions.
  1. +3 −2 lib/twitter/api/tweets.rb
  2. +10 −0 spec/twitter/api/tweets_spec.rb
View
5 lib/twitter/api/tweets.rb
@@ -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
@@ -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
View
10 spec/twitter/api/tweets_spec.rb
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.