Browse files

Added ability to remove likes and delete comments

  • Loading branch information...
1 parent e1e4148 commit 4159181b1d72c6832e99ff04a394dfd2fcf7754b Shayne Sweeney committed Feb 3, 2011
View
18 lib/instagram/client/comments.rb
@@ -39,6 +39,24 @@ def create_media_comment(id, text, options={})
response["data"]
end
+ # Delete's a comment for a given media item ID
+ #
+ # @overload delete_media_comment(media_id, comment_id)
+ # @param media_id [Integer] An Instagram media item ID.
+ # @param comment_id [Integer] Your comment ID of the comment you wish to delete.
+ # @return [nil]
+ # @example Delete the comment with ID of 1234, on the media item with ID of 777
+ # Instagram.delete_media_comment(777, 1234)
+ # @format :json
+ # @authenticated true
+ #
+ # In order to remove a comment, you must be either the owner comment or the media item (or both).
+ # @rate_limited true
+ # @see TODO:docs url
+ def delete_media_comment(media_id, comment_id, options={})
+ response = delete("media/#{media_id}/comments/#{comment_id}", options)
+ response["data"]
+ end
end
end
end
View
18 lib/instagram/client/likes.rb
@@ -24,7 +24,7 @@ def media_likes(id, *args)
#
# @overload like_media(id, text)
# @param id [Integer] An Instagram media item ID
- # @return [Hashie::Mash] The user who performed the like.
+ # @return [nil]
# @example Like media item with ID 777
# Instagram.like_media(777)
# @format :json
@@ -37,6 +37,22 @@ def like_media(id, options={})
response = post("media/#{id}/likes", options)
response["data"]
end
+
+ # Removes the like on a givem media item ID for the currently authenticated user
+ #
+ # @overload unlike_media(id)
+ # @param media_id [Integer] An Instagram media item ID.
+ # @return [nil]
+ # @example Remove the like for the currently authenticated user on the media item with the ID of 777
+ # Instagram.unlike_media(777)
+ # @format :json
+ # @authenticated true
+ # @rate_limited true
+ # @see TODO:docs url
+ def unlike_media(id, options={})
+ response = delete("media/#{id}/likes", options)
+ response["data"]
+ end
end
end
end
View
1 spec/faraday/response_spec.rb
@@ -9,6 +9,7 @@
400 => Instagram::BadRequest,
404 => Instagram::NotFound,
500 => Instagram::InternalServerError,
+ 503 => Instagram::ServiceUnavailable
}.each do |status, exception|
context "when HTTP status is #{status}" do
View
1 spec/fixtures/media_comment_deleted.json
@@ -0,0 +1 @@
+{"meta": {"code": 200}, "data": null}
View
1 spec/fixtures/media_unliked.json
@@ -0,0 +1 @@
+{"meta": {"code": 200}, "data": null}
View
16 spec/instagram/client/comments_spec.rb
@@ -52,6 +52,22 @@
comment.text.should == "hi there"
end
end
+
+ describe ".delete_media_comment" do
+
+ before do
+ stub_delete("media/777/comments/1234.#{format}").
+ with(:query => {:access_token => @client.access_token}).
+ to_return(:body => fixture("media_comment_deleted.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
+ end
+
+ it "should get the correct resource" do
+ @client.delete_media_comment(777, 1234)
+ a_delete("media/777/comments/1234.#{format}").
+ with(:query => {:access_token => @client.access_token}).
+ should have_been_made
+ end
+ end
end
end
end
View
17 spec/instagram/client/likes_spec.rb
@@ -44,10 +44,21 @@
with(:query => {:access_token => @client.access_token}).
should have_been_made
end
+ end
+
+ describe ".unlike_media" do
- it "should return nil data when successful" do
- data = @client.like_media(777)
- data.should == nil
+ before do
+ stub_delete("media/777/likes.#{format}").
+ with(:query => {:access_token => @client.access_token}).
+ to_return(:body => fixture("media_unliked.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
+ end
+
+ it "should get the correct resource" do
+ @client.unlike_media(777)
+ a_delete("media/777/likes.#{format}").
+ with(:query => {:access_token => @client.access_token}).
+ should have_been_made
end
end
end

0 comments on commit 4159181

Please sign in to comment.