Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow the oembed endpoints to take a url as well as a status id #349

Merged
merged 1 commit into from

2 participants

@bshelton229

I've run into a situation where it would be nice to be able to pass a url to the oembed methods.

Twitter.oembed('https://twitter.com/bshelton229/status/294601034834255872')
@sferik sferik merged commit 1d94549 into sferik:master
@sferik
Owner

This looks good. Thanks!

@sferik sferik referenced this pull request from a commit
@sferik Clean up after #349 c3df1ba
@bshelton229 bshelton229 deleted the bshelton229:oembed-url branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 6, 2013
  1. @bshelton229
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.