databasedotcom-ejholmes 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +161 -0
- data/lib/databasedotcom/chatter/comment.rb +10 -0
- data/lib/databasedotcom/chatter/conversation.rb +100 -0
- data/lib/databasedotcom/chatter/feed.rb +64 -0
- data/lib/databasedotcom/chatter/feed_item.rb +40 -0
- data/lib/databasedotcom/chatter/feeds.rb +5 -0
- data/lib/databasedotcom/chatter/filter_feed.rb +14 -0
- data/lib/databasedotcom/chatter/group.rb +45 -0
- data/lib/databasedotcom/chatter/group_membership.rb +9 -0
- data/lib/databasedotcom/chatter/like.rb +9 -0
- data/lib/databasedotcom/chatter/message.rb +29 -0
- data/lib/databasedotcom/chatter/photo_methods.rb +55 -0
- data/lib/databasedotcom/chatter/record.rb +122 -0
- data/lib/databasedotcom/chatter/subscription.rb +9 -0
- data/lib/databasedotcom/chatter/user.rb +153 -0
- data/lib/databasedotcom/chatter.rb +11 -0
- data/lib/databasedotcom/client.rb +547 -0
- data/lib/databasedotcom/collection.rb +37 -0
- data/lib/databasedotcom/core_extensions/class_extensions.rb +41 -0
- data/lib/databasedotcom/core_extensions/hash_extensions.rb +8 -0
- data/lib/databasedotcom/core_extensions/string_extensions.rb +16 -0
- data/lib/databasedotcom/core_extensions.rb +3 -0
- data/lib/databasedotcom/sales_force_error.rb +26 -0
- data/lib/databasedotcom/sobject/sobject.rb +369 -0
- data/lib/databasedotcom/sobject.rb +2 -0
- data/lib/databasedotcom/version.rb +3 -0
- data/lib/databasedotcom.rb +7 -0
- metadata +129 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
module Databasedotcom
|
|
4
|
+
module Chatter
|
|
5
|
+
# Superclasses all Chatter resources except feeds. Some methods may not be supported by the Force.com API for certain subclasses.
|
|
6
|
+
class Record
|
|
7
|
+
attr_reader :raw_hash, :name, :id, :url, :type, :client
|
|
8
|
+
|
|
9
|
+
# 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
|
+
def initialize(client, response)
|
|
11
|
+
@client = client
|
|
12
|
+
@raw_hash = response.is_a?(Hash) ? response : JSON.parse(response)
|
|
13
|
+
@name = @raw_hash["name"]
|
|
14
|
+
@id = @raw_hash["id"]
|
|
15
|
+
@url = @raw_hash["url"]
|
|
16
|
+
@type = @raw_hash["type"]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Find a single Record or a Collection of records by id. _resource_id_ can be a single id or a list of ids.
|
|
20
|
+
def self.find(client, resource_id, parameters={})
|
|
21
|
+
if resource_id.is_a?(Array)
|
|
22
|
+
resource_ids = resource_id.join(',')
|
|
23
|
+
url = "/services/data/v#{client.version}/chatter/#{self.resource_name}/batch/#{resource_ids}"
|
|
24
|
+
response = JSON.parse(client.http_get(url, parameters).body)
|
|
25
|
+
good_results = response["results"].select { |r| r["statusCode"] == 200 }
|
|
26
|
+
collection = Databasedotcom::Collection.new(client, good_results.length)
|
|
27
|
+
good_results.each do |result|
|
|
28
|
+
collection << self.new(client, result["result"])
|
|
29
|
+
end
|
|
30
|
+
collection
|
|
31
|
+
else
|
|
32
|
+
path_components = ["/services/data/v#{client.version}/chatter"]
|
|
33
|
+
if parameters.has_key?(:user_id)
|
|
34
|
+
path_components << "users/#{parameters[:user_id]}"
|
|
35
|
+
parameters.delete(:user_id)
|
|
36
|
+
end
|
|
37
|
+
path_components << "#{self.resource_name}/#{resource_id}"
|
|
38
|
+
url = path_components.join('/')
|
|
39
|
+
response = JSON.parse(client.http_get(url, parameters).body)
|
|
40
|
+
self.new(client, response)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Return a Collection of records that match the _query_.
|
|
45
|
+
def self.search(client, query, parameters={})
|
|
46
|
+
self.all(client, parameters.merge(self.search_parameter_name => query))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Return a Collection of all records.
|
|
50
|
+
def self.all(client, parameters={})
|
|
51
|
+
path_components = ["/services/data/v#{client.version}/chatter"]
|
|
52
|
+
if parameters.has_key?(:user_id)
|
|
53
|
+
path_components << "users/#{parameters[:user_id]}"
|
|
54
|
+
parameters.delete(:user_id)
|
|
55
|
+
end
|
|
56
|
+
path_components << self.resource_name
|
|
57
|
+
url = path_components.join('/')
|
|
58
|
+
result = client.http_get(url, parameters)
|
|
59
|
+
response = JSON.parse(result.body)
|
|
60
|
+
collection = Databasedotcom::Collection.new(client, self.total_size_of_collection(response), response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
|
|
61
|
+
self.collection_from_response(response).each do |resource|
|
|
62
|
+
collection << self.new(client, resource)
|
|
63
|
+
end
|
|
64
|
+
collection
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Delete the Record identified by _resource_id_.
|
|
68
|
+
def self.delete(client, resource_id, parameters={})
|
|
69
|
+
path_components = ["/services/data/v#{client.version}/chatter"]
|
|
70
|
+
if parameters.has_key?(:user_id)
|
|
71
|
+
path_components << "users/#{parameters[:user_id]}"
|
|
72
|
+
parameters.delete(:user_id)
|
|
73
|
+
end
|
|
74
|
+
path_components << self.resource_name
|
|
75
|
+
path_components << resource_id
|
|
76
|
+
path = path_components.join('/')
|
|
77
|
+
client.http_delete(path, parameters)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# A Hash representation of the User that created this Record.
|
|
81
|
+
def user
|
|
82
|
+
self.raw_hash["user"]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# A Hash representation of the entity that is the parent of this Record.
|
|
86
|
+
def parent
|
|
87
|
+
self.raw_hash["parent"]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Delete this record.
|
|
91
|
+
def delete(parameters={})
|
|
92
|
+
self.class.delete(self.client, self.id, parameters)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Reload this record.
|
|
96
|
+
def reload
|
|
97
|
+
self.class.find(self.client, self.id)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# The REST resource name of this Record.
|
|
101
|
+
#
|
|
102
|
+
# GroupMembership.resource_name #=> group-memberships
|
|
103
|
+
def self.resource_name
|
|
104
|
+
(self.name.split('::').last).resourcerize + "s"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
protected
|
|
108
|
+
|
|
109
|
+
def self.total_size_of_collection(response)
|
|
110
|
+
response["total"] || response["totalMemberCount"]
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def self.collection_from_response(response)
|
|
114
|
+
response[self.resource_name]
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def self.search_parameter_name
|
|
118
|
+
:q
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
require 'databasedotcom/chatter/record'
|
|
2
|
+
require 'databasedotcom/chatter/photo_methods'
|
|
3
|
+
|
|
4
|
+
module Databasedotcom
|
|
5
|
+
module Chatter
|
|
6
|
+
# Defines a User in your org.
|
|
7
|
+
class User < Record
|
|
8
|
+
include PhotoMethods
|
|
9
|
+
|
|
10
|
+
# Returns a Collection of Subscription objects that represents all followers of the User identified by _subject_id_.
|
|
11
|
+
def self.followers(client, subject_id="me")
|
|
12
|
+
url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/followers"
|
|
13
|
+
result = client.http_get(url)
|
|
14
|
+
response = JSON.parse(result.body)
|
|
15
|
+
collection = Databasedotcom::Collection.new(client, response["total"], response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
|
|
16
|
+
response["followers"].each do |subscription|
|
|
17
|
+
collection << Subscription.new(client, subscription)
|
|
18
|
+
end
|
|
19
|
+
collection
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Returns a Collection of Subscription objects that represent all entities that the User identified by _subject_id_ is following.
|
|
23
|
+
def self.following(client, subject_id="me")
|
|
24
|
+
url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/following"
|
|
25
|
+
result = client.http_get(url)
|
|
26
|
+
response = JSON.parse(result.body)
|
|
27
|
+
collection = Databasedotcom::Collection.new(client, response["total"], response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
|
|
28
|
+
response["following"].each do |subscription|
|
|
29
|
+
collection << Subscription.new(client, subscription)
|
|
30
|
+
end
|
|
31
|
+
collection
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Returns a Collection of Group objects that represent all the groups that the User identified by _subject_id_ is a part of.
|
|
35
|
+
def self.groups(client, subject_id="me")
|
|
36
|
+
url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/groups"
|
|
37
|
+
result = client.http_get(url)
|
|
38
|
+
response = JSON.parse(result.body)
|
|
39
|
+
collection = Databasedotcom::Collection.new(client, response["total"], response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
|
|
40
|
+
response["groups"].each do |group|
|
|
41
|
+
collection << Group.new(client, group)
|
|
42
|
+
end
|
|
43
|
+
collection
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Returns the current status of the User identified by _subject_id_.
|
|
47
|
+
def self.status(client, subject_id="me")
|
|
48
|
+
url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/status"
|
|
49
|
+
result = client.http_get(url)
|
|
50
|
+
JSON.parse(result.body)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Posts a status update as the User identified by _subject_id_ with content _text_.
|
|
54
|
+
def self.post_status(client, subject_id, text)
|
|
55
|
+
url = "/services/data/v#{client.version}/chatter/users/#{subject_id}/status"
|
|
56
|
+
result = client.http_post(url, nil, :text => text)
|
|
57
|
+
JSON.parse(result.body)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Deletes the status of User identified by _subject_id_.
|
|
61
|
+
def self.delete_status(client, subject_id="me")
|
|
62
|
+
client.http_delete "/services/data/v#{client.version}/chatter/users/#{subject_id}/status"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Creates and returns a new Subscription object that represents the User identified by _subject_id_ following the resource identified by _resource_id_.
|
|
66
|
+
def self.follow(client, subject_id, resource_id)
|
|
67
|
+
response = client.http_post("/services/data/v#{client.version}/chatter/users/#{subject_id}/following", nil, :subjectId => resource_id)
|
|
68
|
+
Subscription.new(client, response.body)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Returns a Collection of conversations that belong to the User identified by _subject_id_.
|
|
72
|
+
def self.conversations(client, subject_id)
|
|
73
|
+
Conversation.all(client, :user_id => subject_id)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Returns a Collection of private messages that belong to the User identified by _subject_id_.
|
|
77
|
+
def self.messages(client, subject_id)
|
|
78
|
+
Message.all(client, :user_id => subject_id)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Get a Collection of Subscription objects for this User. Always makes a call to the server.
|
|
82
|
+
def followers!
|
|
83
|
+
self.class.followers(self.client, self.id)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Get a Collection of Subscription objects for this User. Returns cached data if it has been called before.
|
|
87
|
+
def followers
|
|
88
|
+
@followers ||= followers!
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Get a Collection of Subscription objects that represents all resources that this User is following. Always makes a call to the server.
|
|
92
|
+
def following!
|
|
93
|
+
self.class.following(self.client, self.id)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Get a Collection of Subscription objects that represents all resources that this User is following. Returns cached data if it has been called before.
|
|
97
|
+
def following
|
|
98
|
+
@following ||= following!
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Returns this current status of this User.
|
|
102
|
+
def status
|
|
103
|
+
self.raw_hash["currentStatus"]
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Posts a new status with content _text_ for this User.
|
|
107
|
+
def post_status(text)
|
|
108
|
+
self.class.post_status(self.client, self.id, text)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Deletes the current status of this User. Returns the deleted status.
|
|
112
|
+
def delete_status
|
|
113
|
+
self.class.delete_status(self.client, self.id)
|
|
114
|
+
status
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Get a Collection of Group objects that represents all groups that this User is in. Always makes a call to the server.
|
|
118
|
+
def groups!
|
|
119
|
+
self.class.groups(self.client, self.id)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Get a Collection of Group objects that represents all groups that this User is in. Returns cached data if it has been called before.
|
|
123
|
+
def groups
|
|
124
|
+
@groups ||= groups!
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Creates a new Subscription that represents this User following the resource with id _record_id_.
|
|
128
|
+
def follow(record_id)
|
|
129
|
+
self.class.follow(self.client, self.id, record_id)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Get a Collection of Conversation objects that represents the conversations for this User. Always makes a call to the server.
|
|
133
|
+
def conversations!
|
|
134
|
+
self.class.conversations(self.client, self.id)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Get a Collection of Conversation objects that represents the conversations for this User. Returns cached data if it has been called before.
|
|
138
|
+
def conversations
|
|
139
|
+
@conversations ||= conversations!
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Get a Collection of Message objects that represents the messages for this User. Always makes a call to the server.
|
|
143
|
+
def messages!
|
|
144
|
+
self.class.messages(self.client, self.id)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Get a Collection of Message objects that represents the messages for this User. Returns cached data if it has been called before.
|
|
148
|
+
def messages
|
|
149
|
+
@messages ||= messages!
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'databasedotcom/chatter/feeds'
|
|
2
|
+
require 'databasedotcom/chatter/filter_feed'
|
|
3
|
+
require 'databasedotcom/chatter/feed_item'
|
|
4
|
+
require 'databasedotcom/chatter/comment'
|
|
5
|
+
require 'databasedotcom/chatter/like'
|
|
6
|
+
require 'databasedotcom/chatter/user'
|
|
7
|
+
require 'databasedotcom/chatter/group'
|
|
8
|
+
require 'databasedotcom/chatter/group_membership'
|
|
9
|
+
require 'databasedotcom/chatter/subscription'
|
|
10
|
+
require 'databasedotcom/chatter/conversation'
|
|
11
|
+
require 'databasedotcom/chatter/message'
|