Permalink
Browse files

Merge pull request #45 from holoiii/master

Adds oembed support
  • Loading branch information...
2 parents 81cda3b + 1451fd0 commit 29dee1b88663c15b815b6213c4dac1a7bb711f06 @shayne shayne committed Feb 21, 2013
View
3 lib/instagram/client.rb
@@ -16,5 +16,6 @@ class Client < API
include Instagram::Client::Comments
include Instagram::Client::Likes
include Instagram::Client::Subscriptions
+ include Instagram::Client::Embedding
end
-end
+end
View
11 lib/instagram/client/embedding.rb
@@ -0,0 +1,11 @@
+module Instagram
+ class Client
+ module Embedding
+ def oembed(*args)
+ url = args.first
+ return nil unless url
+ get("oembed?url=#{url}", {}, false, true)
+ end
+ end
+ end
+end
View
14 spec/fixtures/oembed.json
@@ -0,0 +1,14 @@
+{
+ "provider_url": "http:\/\/instagram.com\/",
+ "media_id": "123657555223544123_41812344",
+ "title": "I like this title #hash",
+ "url": "http:\/\/distilleryimage4.s3.amazonaws.com\/7.jpg",
+ "author_name": "my_name",
+ "height": 612,
+ "width": 612,
+ "version": "1.0",
+ "author_url": "http:\/\/instagram.com\/",
+ "author_id": 1234,
+ "type": "photo",
+ "provider_name": "Instagram"
+}
View
36 spec/instagram/client/embedding_spec.rb
@@ -0,0 +1,36 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe Instagram::Client do
+ Instagram::Configuration::VALID_FORMATS.each do |format|
+ context ".new(:format => '#{format}')" do
+ before do
+ @client = Instagram::Client.new(:format => format, :client_id => 'CID', :client_secret => 'CS', :access_token => 'AT')
+ end
+
+ describe ".oembed" do
+ before do
+ stub_get("oembed").
+ with(:query => {:access_token => @client.access_token, :url => "http://instagram.com/p/abcdef"}).
+ to_return(:body => fixture("oembed.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
+ end
+
+ it "should get the correct resource" do
+ @client.oembed("http://instagram.com/p/abcdef")
+ a_get("oembed?url=http://instagram.com/p/abcdef").
+ with(:query => {:access_token => @client.access_token}).
+ should have_been_made
+ end
+
+ it "should return the oembed information for an instagram media url" do
+ oembed = @client.oembed("http://instagram.com/p/abcdef")
+ oembed.media_id.should == "123657555223544123_41812344"
+ end
+
+ it "should return nil if a URL is not provided" do
+ oembed = @client.oembed
+ oembed.should be_nil
+ end
+ end
+ end
+ end
+end

0 comments on commit 29dee1b

Please sign in to comment.