Permalink
Browse files

Added ability to perform likes and add comments

Endpoint reorganizations and some internal renaming
Bump to 0.1
  • Loading branch information...
1 parent e7e46c6 commit 9afde9926daee84717f7a297375cf0461eea55d7 Shayne Sweeney committed Feb 3, 2011
View
@@ -69,7 +69,7 @@ API Usage Examples
require "instagram"
# Get a list of a user's most recent media
- puts Instagram.user_recent_media(1234)
+ puts Instagram.user_recent_media(777)
# Get the currently authenticated user's media feed
puts Instagram.user_media_feed
View
@@ -8,9 +8,11 @@ class Client < API
include Instagram::Client::Utils
- include Instagram::Client::User
+ include Instagram::Client::Users
include Instagram::Client::Media
- include Instagram::Client::Location
- include Instagram::Client::Tag
+ include Instagram::Client::Locations
+ include Instagram::Client::Tags
+ include Instagram::Client::Comments
+ include Instagram::Client::Likes
end
end
@@ -0,0 +1,44 @@
+module Instagram
+ class Client
+ # Defines methods related to comments
+ module Comments
+ # Returns a list of comments for a given media item ID
+ #
+ # @overload media_comments(id)
+ # @param id [Integer] An Instagram media item ID
+ # @return [Hashie::Mash] The requested comment.
+ # @example Returns a list of comments for the media item of ID 1234
+ # Instagram.media_comments(777)
+ # @format :json
+ # @authenticated true
+ #
+ # If getting this data of a protected user, you must be authenticated (and be allowed to see that user).
+ # @rate_limited true
+ # @see TODO:docs url
+ def media_comments(id, *args)
+ response = get("media/#{id}/comments")
+ response["data"]
+ end
+
+ # Create's a comment for a given media item ID
+ #
+ # @overload create_media_comment(id, text)
+ # @param id [Integer] An Instagram media item ID
+ # @param text [String] The text of your comment
+ # @return [Hashie::Mash] The comment created.
+ # @example Creates a new comment on media item with ID 777
+ # Instagram.create_media_comment(777, "Oh noes!")
+ # @format :json
+ # @authenticated true
+ #
+ # If getting this data of a protected user, you must be authenticated (and be allowed to see that user).
+ # @rate_limited true
+ # @see TODO:docs url
+ def create_media_comment(id, text, options={})
+ response = post("media/#{id}/comments", options.merge(:text => text))
+ response["data"]
+ end
+
+ end
+ end
+end
@@ -0,0 +1,42 @@
+module Instagram
+ class Client
+ # Defines methods related to likes
+ module Likes
+ # Returns a list of users who like a given media item ID
+ #
+ # @overload media_likes(id)
+ # @param media [Integer] An Instagram media item ID
+ # @return [Hashie::Mash] A list of users.
+ # @example Returns a list of users who like the media item of ID 1234
+ # Instagram.media_likes(777)
+ # @format :json
+ # @authenticated true
+ #
+ # If getting this data of a protected user, you must be authenticated (and be allowed to see that user).
+ # @rate_limited true
+ # @see TODO:docs url
+ def media_likes(id, *args)
+ response = get("media/#{id}/likes")
+ response["data"]
+ end
+
+ # Issues a like by the currently authenticated user, for a given media item ID
+ #
+ # @overload like_media(id, text)
+ # @param id [Integer] An Instagram media item ID
+ # @return [Hashie::Mash] The user who performed the like.
+ # @example Like media item with ID 777
+ # Instagram.like_media(777)
+ # @format :json
+ # @authenticated true
+ #
+ # If getting this data of a protected user, you must be authenticated (and be allowed to see that user).
+ # @rate_limited true
+ # @see TODO:docs url
+ def like_media(id, options={})
+ response = post("media/#{id}/likes", options)
+ response["data"]
+ end
+ end
+ end
+end
@@ -1,7 +1,7 @@
module Instagram
class Client
# Defines methods related to media items
- module Location
+ module Locations
# Returns extended information of a given Instagram location
#
# @overload location(id)
@@ -15,7 +15,7 @@ module Location
# @see TODO:docs url
def location(id, *args)
response = get("locations/#{id}")
- response['data']
+ response["data"]
end
# Returns a list of recent media items for a given Instagram location
@@ -52,7 +52,7 @@ def location_recent_media(id, *args)
# @rate_limited true
def location_search(lat, lng, options={})
response = get('locations/search', options.merge(:lat => lat, :lng => lng))
- response['data']
+ response["data"]
end
end
end
@@ -18,26 +18,7 @@ module Media
def media_item(*args)
id = args.first || 'self'
response = get("media/#{id}")
- response['data']
- end
-
- # Returns a list of users who liked the given media object
- #
- # @overload media_item_likers(id)
- # @param user [Integer] An Instagram media item ID
- # @return [Hashie::Mash] The requested media item.
- # @example Return a list of all the likers for media item ID 1234
- # Instagram.media_item_likers(1324)
- # @format :json
- # @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 TODO:docs url
- def media_item_likers(*args)
- id = args.first || 'self'
- response = get("media/#{id}/likers")
- response['data']
+ response["data"]
end
# Returns a list of the overall most popular media
@@ -75,7 +56,7 @@ def media_popular(*args)
# @rate_limited true
def media_search(lat, lng, options={})
response = get('media/search', options.merge(:lat => lat, :lng => lng))
- response['data']
+ response["data"]
end
end
end
@@ -1,7 +1,7 @@
module Instagram
class Client
# Defines methods related to tags
- module Tag
+ module Tags
# Returns extended information of a given Instagram tag
#
# @overload tag(tag)
@@ -15,7 +15,7 @@ module Tag
# @see TODO:docs url
def tag(tag, *args)
response = get("tags/#{tag}")
- response['data']
+ response["data"]
end
# Returns a list of recent media items for a given Instagram tag
@@ -52,7 +52,7 @@ def tag_recent_media(id, *args)
# Instagram.tag_search("cat")
def tag_search(query, options={})
response = get('tags/search', options.merge(:q => query))
- response['data']
+ response["data"]
end
end
end
@@ -1,7 +1,7 @@
module Instagram
class Client
# Defines methods related to users
- module User
+ module Users
# Returns extended information of a given user
#
# @overload user(id=nil, options={})
@@ -18,7 +18,7 @@ module User
def user(*args)
id = args.first || 'self'
response = get("users/#{id}")
- response['data']
+ response["data"]
end
# Returns users that match the given query
@@ -35,7 +35,7 @@ def user(*args)
# Instagram.user_search("Shayne Sweeney")
def user_search(query, options={})
response = get('users/search', options.merge(:q => query))
- response['data']
+ response["data"]
end
# Returns a list of users whom a given user follows
@@ -62,7 +62,7 @@ def user_search(query, options={})
def user_follows(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
id = args.first || "self"
- response = get("users/#{id}/follows/users", options)
+ response = get("users/#{id}/follows", options)
response["data"]
end
end
@@ -91,7 +91,7 @@ def user_follows(*args)
def user_followed_by(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
id = args.first || "self"
- response = get("users/#{id}/followed-by/users", options)
+ response = get("users/#{id}/followed-by", options)
response["data"]
end
View
@@ -10,6 +10,16 @@ def get(path, options={}, raw=false, unformatted=false)
def post(path, options={}, raw=false, unformatted=false)
request(:post, path, options, raw, unformatted)
end
+
+ # Perform an HTTP PUT request
+ def put(path, options={}, raw=false, unformatted=false)
+ request(:put, path, options, raw, unformatted)
+ end
+
+ # Perform an HTTP DELETE request
+ def delete(path, options={}, raw=false, unformatted=false)
+ request(:delete, path, options, raw, unformatted)
+ end
private
@@ -18,9 +28,9 @@ def request(method, path, options, raw=false, unformatted=false)
response = connection(raw).send(method) do |request|
path = formatted_path(path) unless unformatted
case method
- when :get
+ when :get, :delete
request.url(path, options)
- when :post
+ when :post, :put
request.path = path
request.body = options unless options.empty?
end
View
@@ -1,3 +1,3 @@
module Instagram
- VERSION = '0.0.1'.freeze unless defined?(::Instagram::VERSION)
+ VERSION = '0.1'.freeze unless defined?(::Instagram::VERSION)
end
Oops, something went wrong.

0 comments on commit 9afde99

Please sign in to comment.