Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #137 from DylanDavidson/media_shortcode
Browse files Browse the repository at this point in the history
Adds get_media_by_shortcode endpoint, tests, and fixture.
  • Loading branch information
heatonjb committed Oct 23, 2014
2 parents 56dd51d + aafccbb commit b8f9e2c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/instagram/client/media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ def media_item(*args)
response
end

# Returns extended information of a given media item
#
# @overload media_shortcode(shortcode)
# @param shortcode [String] An Instagram media item shortcode
# @return [Hashie::Mash] The requested media item.
# @example Return extended information for media item with shortcode 'D'
# Instagram.media_shortcode('D')
# @format none
# @authenticated false unless requesting media from a protected user
#
# If getting this data of a protected user, you must authenticate (and be allowed to see that user).
# @rate_limited true
# @see http://instagram.com/developer/endpoints/media/#get_media_by_shortcode
def media_shortcode(*args)
shortcode = args.first
response = get("media/shortcode/#{shortcode}", {}, false, false, true)
response
end

# Returns a list of the overall most popular media
#
# @overload media_popular(options={})
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/media_shortcode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"meta":{"code":200},"data":{"attribution":null,"tags":["youknowitslate"],"type":"image","location":null,"comments":{"count":3,"data":[{"created_time":"1295535132","text":"Nice","from":{"username":"newyorkcity","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_1483611_75sq_1391632115.jpg","id":"1483611","full_name":"newyorkcity"},"id":"20808205"},{"created_time":"1295549402","text":"I hope you guys got some good work done :)","from":{"username":"abelnation","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_5315_75sq_1391467051.jpg","id":"5315","full_name":"Abel Allison"},"id":"20873301"},{"created_time":"1295556861","text":"Hey do you follow @docpop ?Him, and his friend, made a pretty awesome Instagram Scarf.","from":{"username":"jasonsposa","profile_picture":"http:\/\/photos-c.ak.instagram.com\/hphotos-ak-xaf1\/10616446_1460074390927282_1108706618_a.jpg","id":"102516","full_name":"jason"},"id":"20900554"}]},"filter":"X-Pro II","created_time":"1295525094","link":"http:\/\/instagram.com\/p\/BG9It\/","likes":{"count":52,"data":[{"username":"bailey","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_120_75sq_1328690799.jpg","id":"120","full_name":"Bailey Siewert"},{"username":"bill","profile_picture":"http:\/\/photos-h.ak.instagram.com\/hphotos-ak-xfa1\/10597268_695384913848791_1949499102_a.jpg","id":"34","full_name":"Bill Bogenschutz"},{"username":"juss0445","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_1416773_75sq_1296220025.jpg","id":"1416773","full_name":"juss0445"},{"username":"mimidea","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_1133519_75sq_1361436617.jpg","id":"1133519","full_name":"mimi\ud83d\udc95"}]},"images":{"low_resolution":{"url":"http:\/\/scontent-a.cdninstagram.com\/hphotos-xfa1\/outbound-distillery\/t0.0-17\/OBPTH\/media\/2011\/01\/20\/6248835b0acd48d39d7ee606937ae9f7_6.jpg","width":306,"height":306},"thumbnail":{"url":"http:\/\/scontent-a.cdninstagram.com\/hphotos-xfa1\/outbound-distillery\/t0.0-17\/OBPTH\/media\/2011\/01\/20\/6248835b0acd48d39d7ee606937ae9f7_5.jpg","width":150,"height":150},"standard_resolution":{"url":"http:\/\/scontent-a.cdninstagram.com\/hphotos-xfa1\/outbound-distillery\/t0.0-17\/OBPTH\/media\/2011\/01\/20\/6248835b0acd48d39d7ee606937ae9f7_7.jpg","width":612,"height":612}},"users_in_photo":[],"caption":{"created_time":"1295525094","text":"#youknowitslate when the cab driver wishes you good morning","from":{"username":"mikeyk","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_4_75sq_1374110869.jpg","id":"4","full_name":"Mike Krieger"},"id":"20757161"},"user_has_liked":false,"id":"18600493_4","user":{"username":"mikeyk","website":"","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_4_75sq_1374110869.jpg","full_name":"Mike Krieger","bio":"","id":"4"}}}
21 changes: 21 additions & 0 deletions spec/instagram/client/media_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@
end
end

describe ".media_shortcode" do

before do
stub_get('media/shortcode/BG9It').
with(:query => {:access_token => @client.access_token}).
to_return(:body => fixture("media_shortcode.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
end

it "should get the correct resource" do
@client.media_shortcode('BG9It')
a_get('media/shortcode/BG9It').
with(:query => {:access_token => @client.access_token}).
should have_been_made
end

it "should return extended information of a given media item" do
media = @client.media_shortcode('BG9It')
media.user.username.should == 'mikeyk'
end
end

describe ".media_popular" do

before do
Expand Down

0 comments on commit b8f9e2c

Please sign in to comment.