Class: FriendFeed::Feed
- Inherits:
-
Object
- Object
- FriendFeed::Feed
- Defined in:
- lib/friend-feed/feed.rb
Instance Method Summary collapse
-
#add_comment(entry_id, body) ⇒ Object
Adds the given comment to the entry with the given ID.
-
#add_like(entry_id) ⇒ Object
‘Likes’ the entry with the given ID.
-
#delete_comment(entry_id, comment_id) ⇒ Object
Deletes the comment with the given ID.
-
#delete_like(entry_id) ⇒ Object
Deletes the ‘Like’ for the entry with the given ID (if any).
-
#edit_comment(entry_id, comment_id, body) ⇒ Object
Updates the comment with the given ID.
-
#fetch_home_feed(url_args = {}) ⇒ Object
Returns the entries the authenticated user sees on their home page.
-
#fetch_multi_user_feed(nicknames, url_args = {}) ⇒ Object
Returns a merged feed with all of the given users’ entries.
-
#fetch_public_feed(url_args = {}) ⇒ Object
Returns the public feed with everyone’s public entries.
-
#fetch_user_comments_feed(nickname, url_args = {}) ⇒ Object
Returns the entries the given user has commented on.
-
#fetch_user_discussion_feed(nickname, url_args = {}) ⇒ Object
Returns the entries the given user has commented on or “liked”.
-
#fetch_user_feed(nickname, url_args = {}) ⇒ Object
Returns the entries shared by the user with the given nickname.
-
#fetch_user_likes_feed(nickname, url_args = {}) ⇒ Object
Returns the entries the given user has “liked”.
-
#initialize(auth_nickname = nil, auth_key = nil) ⇒ Feed
constructor
A new instance of Feed.
-
#publish_link(title, link = nil, comment = nil, image_urls = [], images = []) ⇒ Object
Publishes the given link/title to the authenticated user’s feed.
-
#publish_message(*args) ⇒ Object
Publishes the given message to the authenticated user’s feed.
-
#search(q, url_args = {}) ⇒ Object
Searches over entries in FriendFeed.
-
#undelete_comment(entry_id, comment_id) ⇒ Object
Un-deletes the comment with the given ID.
Constructor Details
#initialize(auth_nickname = nil, auth_key = nil) ⇒ Feed
Returns a new instance of Feed.
9 10 11 12 |
# File 'lib/friend-feed/feed.rb', line 9 def initialize(auth_nickname = nil, auth_key = nil) @auth_nickname = auth_nickname @auth_key = auth_key end |
Instance Method Details
#add_comment(entry_id, body) ⇒ Object
Adds the given comment to the entry with the given ID.
We return the ID of the new comment, which can be used to edit or delete the comment.
127 128 129 130 |
# File 'lib/friend-feed/feed.rb', line 127 def add_comment(entry_id, body) result = fetch("/api/comment", {}, {:entry => entry_id, :body => body}) result["id"] end |
#add_like(entry_id) ⇒ Object
‘Likes’ the entry with the given ID.
148 149 150 |
# File 'lib/friend-feed/feed.rb', line 148 def add_like(entry_id) fetch("/api/like", {}, { :entry => entry_id }) end |
#delete_comment(entry_id, comment_id) ⇒ Object
Deletes the comment with the given ID.
138 139 140 |
# File 'lib/friend-feed/feed.rb', line 138 def delete_comment(entry_id, comment_id) fetch("/api/comment/delete", {}, { :entry => entry_id, :comment => comment_id }) end |
#delete_like(entry_id) ⇒ Object
Deletes the ‘Like’ for the entry with the given ID (if any).
153 154 155 |
# File 'lib/friend-feed/feed.rb', line 153 def delete_like(entry_id) fetch("/api/like/delete", {}, { :entry => entry_id }) end |
#edit_comment(entry_id, comment_id, body) ⇒ Object
Updates the comment with the given ID.
133 134 135 |
# File 'lib/friend-feed/feed.rb', line 133 def edit_comment(entry_id, comment_id, body) fetch("/api/comment", {}, { :entry => entry_id, :comment => comment_id, :body => body }) end |
#fetch_home_feed(url_args = {}) ⇒ Object
Returns the entries the authenticated user sees on their home page. Authentication is always required.
52 53 54 |
# File 'lib/friend-feed/feed.rb', line 52 def fetch_home_feed(url_args = {}) fetch_feed("/api/feed/home", url_args) end |
#fetch_multi_user_feed(nicknames, url_args = {}) ⇒ Object
Returns a merged feed with all of the given users’ entries. Authentication is required if any one of the users’ feeds is not public.
TODO Fix this - some weird authentication thing.
46 47 48 |
# File 'lib/friend-feed/feed.rb', line 46 def fetch_multi_user_feed(nicknames, url_args = {}) fetch_feed("/api/feed/user", {:nickname => nicknames.join(',')}.merge(url_args)) end |
#fetch_public_feed(url_args = {}) ⇒ Object
Returns the public feed with everyone’s public entries. Authentication is not required.
16 17 18 |
# File 'lib/friend-feed/feed.rb', line 16 def fetch_public_feed(url_args = {}) fetch_feed('/api/feed/public', url_args) end |
#fetch_user_comments_feed(nickname, url_args = {}) ⇒ Object
Returns the entries the given user has commented on.
27 28 29 |
# File 'lib/friend-feed/feed.rb', line 27 def fetch_user_comments_feed(nickname, url_args = {}) fetch_feed("/api/feed/user/#{e nickname}/comments", url_args) end |
#fetch_user_discussion_feed(nickname, url_args = {}) ⇒ Object
Returns the entries the given user has commented on or “liked”.
37 38 39 |
# File 'lib/friend-feed/feed.rb', line 37 def fetch_user_discussion_feed(nickname, url_args = {}) fetch_feed("/api/feed/user/#{e nickname}/discussion", url_args) end |
#fetch_user_feed(nickname, url_args = {}) ⇒ Object
Returns the entries shared by the user with the given nickname. Authentication is required if the user’s feed is not public.
22 23 24 |
# File 'lib/friend-feed/feed.rb', line 22 def fetch_user_feed(nickname, url_args = {}) fetch_feed("/api/feed/user/#{e nickname}", url_args) end |
#fetch_user_likes_feed(nickname, url_args = {}) ⇒ Object
Returns the entries the given user has “liked”.
32 33 34 |
# File 'lib/friend-feed/feed.rb', line 32 def fetch_user_likes_feed(nickname, url_args = {}) fetch_feed("/api/feed/user/#{e nickname}/likes", url_args) end |
#publish_link(title, link = nil, comment = nil, image_urls = [], images = []) ⇒ Object
Publishes the given link/title to the authenticated user’s feed.
Authentication is always required.
image_urls is a list of URLs that will be downloaded and included as thumbnails beneath the link. The thumbnails will all link to the destination link. If you would prefer that the images link somewhere else, you can specify images[] instead, which should be a list of dicts of the form …, “link”: …. The thumbnail with the given url will link to the specified link.
We return the parsed/published entry as returned from the server, which includes the final thumbnail URLs as well as the ID for the new entry.
Example:
session = friendfeed.FriendFeed(nickname, remote_key)
entry = session.publish_link(
title="Testing the FriendFeed API",
link="http://friendfeed.com/",
image_urls=[
"http://friendfeed.com/static/images/jim-superman.jpg",
"http://friendfeed.com/static/images/logo.png",
],
)
print "Posted images at http://friendfeed.com/e/%s" % entry["id"]
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/friend-feed/feed.rb', line 95 def publish_link(title, link = nil, comment = nil, image_urls = [], images = []) post_args = {:title => title} post_args['link'] = link unless link.nil? post_args['comment'] = comment unless comment.nil? image_urls.each do |image_url| images.push({:url => image_url}) end images.each_with_index do |image, i| post_args["image#{i}_url"] = image[:url] if image[:link] post_args["image#{i}_link"] = image[:link] end end feed = fetch_feed("/api/share", {}, post_args) feed['entries'][0] end |
#publish_message(*args) ⇒ Object
Publishes the given message to the authenticated user’s feed. See publish_link for additional options.
119 120 121 |
# File 'lib/friend-feed/feed.rb', line 119 def (*args) publish_link(*args) end |
#search(q, url_args = {}) ⇒ Object
Searches over entries in FriendFeed.
If the request is authenticated, the default scope is over all of the entries in the authenticated user’s Friends Feed. If the request is not authenticated, the default scope is over all public entries.
The query syntax is the same syntax as friendfeed.com/advancedsearch
64 65 66 |
# File 'lib/friend-feed/feed.rb', line 64 def search(q, url_args = {}) fetch_feed("/api/feed/search", url_args.merge(:q => q)) end |
#undelete_comment(entry_id, comment_id) ⇒ Object
Un-deletes the comment with the given ID.
143 144 145 |
# File 'lib/friend-feed/feed.rb', line 143 def undelete_comment(entry_id, comment_id) fetch("/api/comment/delete", {}, { :entry => entry_id, :comment => comment_id, :undelete => 1 }) end |