Class: Databasedotcom::Chatter::Record
- Inherits:
-
Object
- Object
- Databasedotcom::Chatter::Record
- Defined in:
- lib/databasedotcom/chatter/record.rb
Overview
Superclasses all Chatter resources except feeds. Some methods may not be supported by the Force.com API for certain subclasses.
Direct Known Subclasses
Comment, Conversation, FeedItem, Group, GroupMembership, Like, Message, Subscription, User
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#raw_hash ⇒ Object
readonly
Returns the value of attribute raw_hash.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.all(client, parameters = {}) ⇒ Object
Return a Collection of all records.
-
.delete(client, resource_id, parameters = {}) ⇒ Object
Delete the Record identified by resource_id.
-
.find(client, resource_id, parameters = {}) ⇒ Object
Find a single Record or a Collection of records by id.
-
.resource_name ⇒ Object
The REST resource name of this Record.
-
.search(client, query, parameters = {}) ⇒ Object
Return a Collection of records that match the query.
Instance Method Summary collapse
-
#delete(parameters = {}) ⇒ Object
Delete this record.
-
#initialize(client, response) ⇒ Record
constructor
Create a new record from the returned JSON response of an API request.
-
#parent ⇒ Object
A Hash representation of the entity that is the parent of this Record.
-
#reload ⇒ Object
Reload this record.
-
#user ⇒ Object
A Hash representation of the User that created this Record.
Constructor Details
#initialize(client, response) ⇒ Record
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
.
10 11 12 13 14 15 16 17 |
# 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 |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/databasedotcom/chatter/record.rb', line 7 def client @client end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/databasedotcom/chatter/record.rb', line 7 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/databasedotcom/chatter/record.rb', line 7 def name @name end |
#raw_hash ⇒ Object (readonly)
Returns the value of attribute raw_hash.
7 8 9 |
# File 'lib/databasedotcom/chatter/record.rb', line 7 def raw_hash @raw_hash end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/databasedotcom/chatter/record.rb', line 7 def type @type end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/databasedotcom/chatter/record.rb', line 7 def url @url end |
Class Method Details
.all(client, parameters = {}) ⇒ Object
Return a Collection of all records.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# 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 = {}) ⇒ Object
Delete the Record identified by resource_id.
68 69 70 71 72 73 74 75 76 77 78 |
# 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 = {}) ⇒ Object
Find a single Record or a Collection of records by id. resource_id can be a single id or a list of ids.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 |
.resource_name ⇒ Object
The REST resource name of this Record.
GroupMembership.resource_name #=> group-memberships
103 104 105 |
# File 'lib/databasedotcom/chatter/record.rb', line 103 def self.resource_name (self.name.split('::').last).resourcerize + "s" end |
.search(client, query, parameters = {}) ⇒ Object
Return a Collection of records that match the query.
45 46 47 |
# File 'lib/databasedotcom/chatter/record.rb', line 45 def self.search(client, query, parameters={}) self.all(client, parameters.merge(self.search_parameter_name => query)) end |
Instance Method Details
#delete(parameters = {}) ⇒ Object
Delete this record.
91 92 93 |
# File 'lib/databasedotcom/chatter/record.rb', line 91 def delete(parameters={}) self.class.delete(self.client, self.id, parameters) end |
#parent ⇒ Object
A Hash representation of the entity that is the parent of this Record.
86 87 88 |
# File 'lib/databasedotcom/chatter/record.rb', line 86 def parent self.raw_hash["parent"] end |
#reload ⇒ Object
Reload this record.
96 97 98 |
# File 'lib/databasedotcom/chatter/record.rb', line 96 def reload self.class.find(self.client, self.id) end |
#user ⇒ Object
A Hash representation of the User that created this Record.
81 82 83 |
# File 'lib/databasedotcom/chatter/record.rb', line 81 def user self.raw_hash["user"] end |