Class: Databasedotcom::Chatter::Feed

Inherits:
Databasedotcom::Collection show all
Defined in:
lib/databasedotcom/chatter/feed.rb

Overview

Parent class of all feeds and inherits from Collection. This class is not intended to be instantiated. Methods should be called on subclasses, which are all are dynamically defined (except for FilterFeed). Defined feeds are NewsFeed, UserProfileFeed, RecordFeed, ToFeed, PeopleFeed, GroupsFeed, FilesFeed, CompanyFeed, and FilterFeed.

Direct Known Subclasses

FilterFeed

Instance Attribute Summary

Attributes inherited from Databasedotcom::Collection

#client, #current_page_url, #next_page_url, #previous_page_url, #total_size

Class Method Summary collapse

Methods inherited from Databasedotcom::Collection

#initialize, #next_page, #next_page?, #previous_page, #previous_page?

Constructor Details

This class inherits a constructor from Databasedotcom::Collection

Class Method Details

.find(client, id = "me", id_prefix = nil) ⇒ Object

Returns an enumerable Feed of FeedItem objects that make up the feed with the specified id. Should not be called as a class method on Feed, but as a method on subclasses.

NewsFeed.find(@client)                   #=>   [#<FeedItem ...>, #<FeedItem ...>, ...]
PeopleFeed.find(@client, "userid")       #=>   [#<FeedItem ...>, #<FeedItem ...>, ...]
FilterFeed.find(@client, "me", "000")    #=>   [#<FeedItem ...>, #<FeedItem ...>, ...]

id_prefix is only applicable for FilterFeed.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/databasedotcom/chatter/feed.rb', line 15

def self.find(client, id="me", id_prefix=nil)
  path_components = %w(services data)
  path_components << "v#{client.version}"
  path_components.concat(%w(chatter feeds))
  path_components << feed_type
  path_components << id unless feed_type == "company"
  path_components << id_prefix
  path_components << "feed-items"
  path = "/" + path_components.compact.join('/')
  result = client.http_get(path)
  response = JSON.parse(result.body)
  collection = self.new(client, nil, response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
  response["items"].each do |item|
    collection << FeedItem.new(client, item)
  end
  collection
end

.post(client, user_id, parameters) ⇒ Object

Posts a FeedItem to a Feed specified by user_id. Should not be called as a class method on Feed, but as a method on subclasses.

UserProfileFeed.post(@client, "me", :text => "This is a status update about Salesforce.", :url => "http://www.salesforce.com")

Returns the newly created FeedItem.



38
39
40
41
42
# File 'lib/databasedotcom/chatter/feed.rb', line 38

def self.post(client, user_id, parameters)
  url = "/services/data/v#{client.version}/chatter/feeds/#{feed_type}/#{user_id}/feed-items"
  response = client.http_post(url, nil, parameters)
  Databasedotcom::Chatter::FeedItem.new(client, response.body)
end

.post_file(client, user_id, io, file_type, file_name, parameters = {}) ⇒ Object

Posts a file to a Feed specified by user_id. Should not be called as a class method on Feed, but as a method on subclasses.

UserProfileFeed.post_file(@client, "me", File.open("MyFile"), "text/plain", "MyFile", :desc => "This is an uploaded text file.")

Returns the newly created FeedItem.



49
50
51
52
53
# File 'lib/databasedotcom/chatter/feed.rb', line 49

def self.post_file(client, user_id, io, file_type, file_name, parameters={})
  url = "/services/data/v#{client.version}/chatter/feeds/#{feed_type}/#{user_id}/feed-items"
  response = client.http_multipart_post(url, {"feedItemFileUpload" => UploadIO.new(io, file_type, file_name), "fileName" => file_name}, parameters)
  Databasedotcom::Chatter::FeedItem.new(client, response.body)
end