1 require 'databasedotcom/chatter/record'
2
3 module Databasedotcom
4 module Chatter
5
6 # An item in a Feed.
7 class FeedItem < Record
8
9 # Returns a Collection of comments that were posted on this FeedItem instance.
10 def comments
11 collection = Databasedotcom::Collection.new(self.client, self.raw_hash["comments"]["total"], self.raw_hash["comments"]["nextPageUrl"], nil, self.raw_hash["comments"]["currentPageUrl"])
12 collection.concat(self.raw_hash["comments"]["comments"])
13 end
14
15 # Returns a Collection of likes for this FeedItem instance.
16 def likes
17 collection = Databasedotcom::Collection.new(self.client, self.raw_hash["likes"]["total"], self.raw_hash["likes"]["nextPageUrl"], self.raw_hash["likes"]["previousPageUrl"], self.raw_hash["likes"]["currentPageUrl"])
18 collection.concat(self.raw_hash["likes"]["likes"])
19 end
20
21 # Like this FeedItem.
22 def like
23 result = self.client.http_post("/services/data/v#{self.client.version}/chatter/feed-items/#{self.id}/likes")
24 Like.new(self.client, result.body)
25 end
26
27 # Post a Comment on this FeedItem with content _text_.
28 def comment(text)
29 result = self.client.http_post("/services/data/v#{self.client.version}/chatter/feed-items/#{self.id}/comments", nil, :text => text)
30 Comment.new(self.client, result.body)
31 end
32
33 protected
34
35 def self.collection_from_response(response)
36 response["items"]
37 end
38 end
39 end
40 en