class Databasedotcom::Chatter::Record

Superclasses all Chatter resources except feeds. Some methods may not be supported by the Force.com API for certain subclasses.

Attributes

client[R]
id[R]
name[R]
raw_hash[R]
type[R]
url[R]

Public Class Methods

all(client, parameters={}) click to toggle source

Return a Collection of all records.

# File lib/databasedotcom/chatter/record.rb, line 50
def self.all(client, parameters={})
  path_components = ["/services/data/v#{client.version}/chatter"]
  if parameters.has_key?(:user_id)
    path_components << "users/#{parameters[:user_id]}"
    parameters.delete(:user_id)
  end
  path_components << self.resource_name
  url = path_components.join('/')
  result = client.http_get(url, parameters)
  response = JSON.parse(result.body)
  collection = Databasedotcom::Collection.new(client, self.total_size_of_collection(response), response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
  self.collection_from_response(response).each do |resource|
    collection << self.new(client, resource)
  end
  collection
end
delete(client, resource_id, parameters={}) click to toggle source

Delete the Record identified by resource_id.

# File lib/databasedotcom/chatter/record.rb, line 68
def self.delete(client, resource_id, parameters={})
  path_components = ["/services/data/v#{client.version}/chatter"]
  if parameters.has_key?(:user_id)
    path_components << "users/#{parameters[:user_id]}"
    parameters.delete(:user_id)
  end
  path_components << self.resource_name
  path_components << resource_id
  path = path_components.join('/')
  client.http_delete(path, parameters)
end
find(client, resource_id, parameters={}) click to toggle source

Find a single Record or a Collection of records by id. resource_id can be a single id or a list of ids.

# File lib/databasedotcom/chatter/record.rb, line 20
def self.find(client, resource_id, parameters={})
  if resource_id.is_a?(Array)
    resource_ids = resource_id.join(',')
    url = "/services/data/v#{client.version}/chatter/#{self.resource_name}/batch/#{resource_ids}"
    response = JSON.parse(client.http_get(url, parameters).body)
    good_results = response["results"].select { |r| r["statusCode"] == 200 }
    collection = Databasedotcom::Collection.new(client, good_results.length)
    good_results.each do |result|
      collection << self.new(client, result["result"])
    end
    collection
  else
    path_components = ["/services/data/v#{client.version}/chatter"]
    if parameters.has_key?(:user_id)
      path_components << "users/#{parameters[:user_id]}"
      parameters.delete(:user_id)
    end
    path_components << "#{self.resource_name}/#{resource_id}"
    url = path_components.join('/')
    response = JSON.parse(client.http_get(url, parameters).body)
    self.new(client, response)
  end
end
new(client, response) click to toggle source

Create a new record from the returned JSON response of an API request. Sets the client, name, id, url, and type attributes. Saves the raw response as raw_hash.

# File lib/databasedotcom/chatter/record.rb, line 10
def initialize(client, response)
  @client = client
  @raw_hash = response.is_a?(Hash) ? response : JSON.parse(response)
  @name = @raw_hash["name"]
  @id = @raw_hash["id"]
  @url = @raw_hash["url"]
  @type = @raw_hash["type"]
end
resource_name() click to toggle source

The REST resource name of this Record.

GroupMembership.resource_name  #=>  group-memberships
# File lib/databasedotcom/chatter/record.rb, line 103
def self.resource_name
  (self.name.split('::').last).resourcerize + "s"
end

Protected Class Methods

collection_from_response(response) click to toggle source
# File lib/databasedotcom/chatter/record.rb, line 113
def self.collection_from_response(response)
  response[self.resource_name]
end
search_parameter_name() click to toggle source
# File lib/databasedotcom/chatter/record.rb, line 117
def self.search_parameter_name
  :q
end
total_size_of_collection(response) click to toggle source
# File lib/databasedotcom/chatter/record.rb, line 109
def self.total_size_of_collection(response)
  response["total"] || response["totalMemberCount"]
end

Public Instance Methods

delete(parameters={}) click to toggle source

Delete this record.

# File lib/databasedotcom/chatter/record.rb, line 91
def delete(parameters={})
  self.class.delete(self.client, self.id, parameters)
end
parent() click to toggle source

A Hash representation of the entity that is the parent of this Record.

# File lib/databasedotcom/chatter/record.rb, line 86
def parent
  self.raw_hash["parent"]
end
reload() click to toggle source

Reload this record.

# File lib/databasedotcom/chatter/record.rb, line 96
def reload
  self.class.find(self.client, self.id)
end
user() click to toggle source

A Hash representation of the User that created this Record.

# File lib/databasedotcom/chatter/record.rb, line 81
def user
  self.raw_hash["user"]
end