sfdc 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/sfdc/client/api.rb +11 -1
- data/lib/sfdc/version.rb +1 -1
- metadata +2 -16
- data/lib/sfdc/chatter/comment.rb +0 -10
- data/lib/sfdc/chatter/conversation.rb +0 -100
- data/lib/sfdc/chatter/feed.rb +0 -64
- data/lib/sfdc/chatter/feed_item.rb +0 -40
- data/lib/sfdc/chatter/feeds.rb +0 -5
- data/lib/sfdc/chatter/filter_feed.rb +0 -14
- data/lib/sfdc/chatter/group.rb +0 -45
- data/lib/sfdc/chatter/group_membership.rb +0 -9
- data/lib/sfdc/chatter/like.rb +0 -9
- data/lib/sfdc/chatter/message.rb +0 -29
- data/lib/sfdc/chatter/photo_methods.rb +0 -55
- data/lib/sfdc/chatter/record.rb +0 -122
- data/lib/sfdc/chatter/subscription.rb +0 -9
- data/lib/sfdc/chatter/user.rb +0 -153
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDExNjkzZjA1ZWE3MDE2OGEzMWMwZTE1ZTExNzZjMjk1NzVhMmM2YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDdhMzE2MTdkMmFjYjBjZDMxODE2ODExNTIyZDVkZGUyMTIyNDM0ZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmM5OTc2N2NmOGY5YTc4NDM2NzIwMTdjMTc2ZDYwODZkYzUwNThjODE2YzYz
|
10
|
+
ZjVhMjQyNTFmODQ2NGZkNDk2ZDhlOGI5YjI2M2I1MzNiMDkyOGExMzI3NzYw
|
11
|
+
OTQyNDlhZjk1MzRkMTc5Yzc1NTQxNDczMmVkODEwMTE0MWNkZWI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDE4ZTAwZmMzMTJjZDFkMTVmN2RiOTRlNjE0MGM2OWQwZmM2YTg2YzIxYzky
|
14
|
+
YTIwODczYjczMTcyNjc4MzQ1OTJlMmMwZjEzODJkOTMyNTY5ZGE1NjVlOGU1
|
15
|
+
ZmUxYTQ5OTQ3NjNmNmU2MGUxMjM0YTczODcyZjE5NDQ5ZjMzMjc=
|
data/lib/sfdc/client/api.rb
CHANGED
@@ -105,6 +105,10 @@ module Sfdc
|
|
105
105
|
end
|
106
106
|
|
107
107
|
# Returns SFDC recent items Id.
|
108
|
+
# Returns Sfdc::SObject
|
109
|
+
# client.recent.each do |r|
|
110
|
+
# puts r.Name + ' ' + r.Id
|
111
|
+
# end
|
108
112
|
def recent
|
109
113
|
response = api_get 'recent'
|
110
114
|
mashify? ? response.body : response.body['records']
|
@@ -294,10 +298,16 @@ module Sfdc
|
|
294
298
|
|
295
299
|
|
296
300
|
#################### Chatter items ############################
|
301
|
+
# @client.feeds.each do |f|
|
302
|
+
# puts f.to_hash['id']
|
303
|
+
# puts f.to_hash['body']['text']
|
304
|
+
# end
|
297
305
|
def feeds
|
298
|
-
api_get("/chatter/feeds/").body
|
306
|
+
api_get("/chatter/feeds/news/me/feed-items").body.items
|
299
307
|
end
|
300
308
|
|
309
|
+
###############################################################
|
310
|
+
|
301
311
|
private
|
302
312
|
|
303
313
|
# Internal: Returns a path to an api endpoint
|
data/lib/sfdc/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sfdc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruce Yue
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir:
|
10
10
|
- bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -118,20 +118,6 @@ extensions: []
|
|
118
118
|
extra_rdoc_files: []
|
119
119
|
files:
|
120
120
|
- lib/sfdc/attachment.rb
|
121
|
-
- lib/sfdc/chatter/comment.rb
|
122
|
-
- lib/sfdc/chatter/conversation.rb
|
123
|
-
- lib/sfdc/chatter/feed.rb
|
124
|
-
- lib/sfdc/chatter/feed_item.rb
|
125
|
-
- lib/sfdc/chatter/feeds.rb
|
126
|
-
- lib/sfdc/chatter/filter_feed.rb
|
127
|
-
- lib/sfdc/chatter/group.rb
|
128
|
-
- lib/sfdc/chatter/group_membership.rb
|
129
|
-
- lib/sfdc/chatter/like.rb
|
130
|
-
- lib/sfdc/chatter/message.rb
|
131
|
-
- lib/sfdc/chatter/photo_methods.rb
|
132
|
-
- lib/sfdc/chatter/record.rb
|
133
|
-
- lib/sfdc/chatter/subscription.rb
|
134
|
-
- lib/sfdc/chatter/user.rb
|
135
121
|
- lib/sfdc/client/api.rb
|
136
122
|
- lib/sfdc/client/authentication.rb
|
137
123
|
- lib/sfdc/client/caching.rb
|
data/lib/sfdc/chatter/comment.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'sfdc/chatter/record'
|
2
|
-
|
3
|
-
module Sfdc
|
4
|
-
module Chatter
|
5
|
-
# A thread of private messages. When calling +Conversation.find+ or +Conversation.all+, you must pass +:user_id => <my_user_id>+ in the _parameters_
|
6
|
-
#
|
7
|
-
# Conversation.all(@client, :user_id => "me")
|
8
|
-
# Conversation.find(@client, "conversationId", :user_id => "f80ad89f9d98d89dfd89")
|
9
|
-
class Conversation < Record
|
10
|
-
|
11
|
-
# Creates a new Conversation and sets its +id+ and +url+ to values obtained from the server response.
|
12
|
-
def initialize(client, response)
|
13
|
-
super
|
14
|
-
@id ||= @raw_hash["conversationId"]
|
15
|
-
@url ||= @raw_hash["conversationUrl"]
|
16
|
-
end
|
17
|
-
|
18
|
-
# Find the Conversation identified by _cid_ and archive it. Returns the updated Conversation.
|
19
|
-
#
|
20
|
-
# Conversation.archive(@client, "fakeid")
|
21
|
-
def self.archive(client, cid)
|
22
|
-
url = "/services/data/v#{client.version}/chatter/users/me/conversations/#{cid}"
|
23
|
-
response = client.http_patch(url, nil, :archived => "true")
|
24
|
-
Conversation.new(client, response.body)
|
25
|
-
end
|
26
|
-
|
27
|
-
# Find the Conversation identified by _cid_ and unarchive it. Returns the updated Conversation.
|
28
|
-
#
|
29
|
-
# Conversation.unarchive(@client, "fakeid")
|
30
|
-
def self.unarchive(client, cid)
|
31
|
-
url = "/services/data/v#{client.version}/chatter/users/me/conversations/#{cid}"
|
32
|
-
response = client.http_patch(url, nil, :archived => "false")
|
33
|
-
Conversation.new(client, response.body)
|
34
|
-
end
|
35
|
-
|
36
|
-
# Find the Conversation identified by _cid_ and mark it as read. Returns the updated Conversation.
|
37
|
-
#
|
38
|
-
# Conversation.mark_read(@client, "fakeid")
|
39
|
-
def self.mark_read(client, cid)
|
40
|
-
url = "/services/data/v#{client.version}/chatter/users/me/conversations/#{cid}"
|
41
|
-
response = client.http_patch(url, nil, :read => "true")
|
42
|
-
Conversation.new(client, response.body)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Find the Conversation identified by _cid_ and mark it as unread. Returns the updated Conversation.
|
46
|
-
#
|
47
|
-
# Conversation.mark_unread(@client, "fakeid")
|
48
|
-
def self.mark_unread(client, cid)
|
49
|
-
url = "/services/data/v#{client.version}/chatter/users/me/conversations/#{cid}"
|
50
|
-
response = client.http_patch(url, nil, :read => "false")
|
51
|
-
Conversation.new(client, response.body)
|
52
|
-
end
|
53
|
-
|
54
|
-
# Gets all messages for the Conversation specified by _cid_ and the User specified by _uid_. Returns a Collection of Message objects.
|
55
|
-
def self.messages(client, uid, cid)
|
56
|
-
conversation = self.find(client, cid, :user_id => uid)
|
57
|
-
collection = Sfdc::Collection.new(client, nil, conversation.raw_hash["messages"]["nextPageUrl"], conversation.raw_hash["messages"]["previousPageUrl"], conversation.raw_hash["messages"]["currentPageUrl"])
|
58
|
-
conversation.raw_hash["messages"]["messages"].each do |item|
|
59
|
-
collection << Message.new(client, item)
|
60
|
-
end
|
61
|
-
collection
|
62
|
-
end
|
63
|
-
|
64
|
-
# Archive this Conversation.
|
65
|
-
def archive
|
66
|
-
self.class.archive(self.client, self.id)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Unarchive this Conversation.
|
70
|
-
def unarchive
|
71
|
-
self.class.unarchive(self.client, self.id)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Mark this Conversation as read.
|
75
|
-
def mark_read
|
76
|
-
self.class.mark_read(self.client, self.id)
|
77
|
-
end
|
78
|
-
|
79
|
-
# Mark this Conversation as unread.
|
80
|
-
def mark_unread
|
81
|
-
self.class.mark_unread(self.client, self.id)
|
82
|
-
end
|
83
|
-
|
84
|
-
# Return a Collection of messages from this Conversation.
|
85
|
-
def messages
|
86
|
-
collection = Sfdc::Collection.new(client, nil, self.raw_hash["messages"]["nextPageUrl"], self.raw_hash["messages"]["previousPageUrl"], self.raw_hash["messages"]["currentPageUrl"])
|
87
|
-
self.raw_hash["messages"]["messages"].each do |item|
|
88
|
-
collection << Message.new(client, item)
|
89
|
-
end
|
90
|
-
collection
|
91
|
-
end
|
92
|
-
|
93
|
-
protected
|
94
|
-
|
95
|
-
def self.search_parameter_name
|
96
|
-
:Q
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
data/lib/sfdc/chatter/feed.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module Sfdc
|
4
|
-
module Chatter
|
5
|
-
# 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*.
|
6
|
-
class Feed < Collection
|
7
|
-
|
8
|
-
# 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.
|
9
|
-
#
|
10
|
-
# NewsFeed.find(@client) #=> [#<FeedItem ...>, #<FeedItem ...>, ...]
|
11
|
-
# PeopleFeed.find(@client, "userid") #=> [#<FeedItem ...>, #<FeedItem ...>, ...]
|
12
|
-
# FilterFeed.find(@client, "me", "000") #=> [#<FeedItem ...>, #<FeedItem ...>, ...]
|
13
|
-
#
|
14
|
-
# _id_prefix_ is only applicable for FilterFeed.
|
15
|
-
def self.find(client, id="me", id_prefix=nil)
|
16
|
-
path_components = %w(services data)
|
17
|
-
path_components << "v#{client.version}"
|
18
|
-
path_components.concat(%w(chatter feeds))
|
19
|
-
path_components << feed_type
|
20
|
-
path_components << id unless feed_type == "company"
|
21
|
-
path_components << id_prefix
|
22
|
-
path_components << "feed-items"
|
23
|
-
path = "/" + path_components.compact.join('/')
|
24
|
-
result = client.http_get(path)
|
25
|
-
response = JSON.parse(result.body)
|
26
|
-
collection = self.new(client, nil, response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
|
27
|
-
response["items"].each do |item|
|
28
|
-
collection << FeedItem.new(client, item)
|
29
|
-
end
|
30
|
-
collection
|
31
|
-
end
|
32
|
-
|
33
|
-
# 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.
|
34
|
-
#
|
35
|
-
# UserProfileFeed.post(@client, "me", :text => "This is a status update about Salesforce.", :url => "http://www.salesforce.com")
|
36
|
-
#
|
37
|
-
# Returns the newly created FeedItem.
|
38
|
-
def self.post(client, user_id, parameters)
|
39
|
-
url = "/services/data/v#{client.version}/chatter/feeds/#{feed_type}/#{user_id}/feed-items"
|
40
|
-
response = client.http_post(url, nil, parameters)
|
41
|
-
Sfdc::Chatter::FeedItem.new(client, response.body)
|
42
|
-
end
|
43
|
-
|
44
|
-
# 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.
|
45
|
-
#
|
46
|
-
# UserProfileFeed.post_file(@client, "me", File.open("MyFile"), "text/plain", "MyFile", :desc => "This is an uploaded text file.")
|
47
|
-
#
|
48
|
-
# Returns the newly created FeedItem.
|
49
|
-
def self.post_file(client, user_id, io, file_type, file_name, parameters={})
|
50
|
-
url = "/services/data/v#{client.version}/chatter/feeds/#{feed_type}/#{user_id}/feed-items"
|
51
|
-
response = client.http_multipart_post(url, {"feedItemFileUpload" => UploadIO.new(io, file_type, file_name), "fileName" => file_name}, parameters)
|
52
|
-
Sfdc::Chatter::FeedItem.new(client, response.body)
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def self.feed_type
|
58
|
-
self.name.match(/.+::(.+)Feed$/)[1].resourcerize
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
FEED_TYPES = %w(News UserProfile Record To People Groups Files Company)
|
63
|
-
end
|
64
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'Sfdc/chatter/record'
|
2
|
-
|
3
|
-
module Sfdc
|
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 = Sfdc::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 = Sfdc::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
|
-
end
|
data/lib/sfdc/chatter/feeds.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
module Sfdc
|
2
|
-
module Chatter
|
3
|
-
# Filter feeds contain items pertaining to both a user and another specified resource.
|
4
|
-
class FilterFeed < Feed
|
5
|
-
|
6
|
-
# Lists all FilterFeeds for the user with id _user_id_.
|
7
|
-
def self.feeds(client, user_id="me")
|
8
|
-
url = "/services/data/v#{client.version}/chatter/feeds/filter/#{user_id}"
|
9
|
-
result = client.http_get(url)
|
10
|
-
JSON.parse(result.body)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/lib/sfdc/chatter/group.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'Sfdc/chatter/record'
|
2
|
-
require 'Sfdc/chatter/photo_methods'
|
3
|
-
|
4
|
-
module Sfdc
|
5
|
-
module Chatter
|
6
|
-
# A group of Users
|
7
|
-
class Group < Record
|
8
|
-
include PhotoMethods
|
9
|
-
|
10
|
-
# Returns a Collection of GroupMembership instances for the Group identified by _group_id_.
|
11
|
-
def self.members(client, group_id)
|
12
|
-
url = "/services/data/v#{client.version}/chatter/groups/#{group_id}/members"
|
13
|
-
result = client.http_get(url)
|
14
|
-
response = JSON.parse(result.body)
|
15
|
-
collection = Sfdc::Collection.new(client, response["totalMemberCount"], response["nextPageUrl"], response["previousPageUrl"], response["currentPageUrl"])
|
16
|
-
response["members"].each do |member|
|
17
|
-
collection << GroupMembership.new(client, member)
|
18
|
-
end
|
19
|
-
collection
|
20
|
-
end
|
21
|
-
|
22
|
-
# Join the group identified by _group_id_ as the user identified by _user_id_.
|
23
|
-
def self.join(client, group_id, user_id="me")
|
24
|
-
url = "/services/data/v#{client.version}/chatter/groups/#{group_id}/members"
|
25
|
-
response = client.http_post(url, nil, :userId => user_id)
|
26
|
-
GroupMembership.new(client, response.body)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Get a Collection of GroupMembership objects for this Group. Always makes a call to the server.
|
30
|
-
def members!
|
31
|
-
self.class.members(self.client, self.id)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Get a Collection of GroupMembership objects for this Group. Returns cached data if it has been called before.
|
35
|
-
def members
|
36
|
-
@members ||= members!
|
37
|
-
end
|
38
|
-
|
39
|
-
# Join this Group as the user identified by _user_id_.
|
40
|
-
def join(user_id="me")
|
41
|
-
self.class.join(self.client, self.id, user_id)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
data/lib/sfdc/chatter/like.rb
DELETED
data/lib/sfdc/chatter/message.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'Sfdc/chatter/record'
|
2
|
-
|
3
|
-
module Sfdc
|
4
|
-
module Chatter
|
5
|
-
# A private message between two or more Users
|
6
|
-
class Message < Record
|
7
|
-
|
8
|
-
# Send a private message with the content _text_ to each user in the _recipients_ list.
|
9
|
-
def self.send_message(client, recipients, text)
|
10
|
-
url = "/services/data/v#{client.version}/chatter/users/me/messages"
|
11
|
-
recipients = recipients.is_a?(Array) ? recipients : [recipients]
|
12
|
-
response = client.http_post(url, nil, :text => text, :recipients => recipients.join(','))
|
13
|
-
Message.new(client, response.body)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Send a reply to the message identified by _in_reply_to_message_id_ with content _text_.
|
17
|
-
def self.reply(client, in_reply_to_message_id, text)
|
18
|
-
url = "/services/data/v#{client.version}/chatter/users/me/messages"
|
19
|
-
response = client.http_post(url, nil, :text => text, :inReplyTo => in_reply_to_message_id)
|
20
|
-
Message.new(client, response.body)
|
21
|
-
end
|
22
|
-
|
23
|
-
# Send a reply to this Message with content _text_.
|
24
|
-
def reply(text)
|
25
|
-
self.class.reply(self.client, self.id, text)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module Sfdc
|
2
|
-
module Chatter
|
3
|
-
# Defines methods for entities that can have photos i.e. Users, Groups.
|
4
|
-
module PhotoMethods
|
5
|
-
def self.included(base)
|
6
|
-
base.extend ClassMethods
|
7
|
-
end
|
8
|
-
|
9
|
-
# Defines class methods for resources that can have photos.
|
10
|
-
module ClassMethods
|
11
|
-
# Returns a Hash with urls for the small and large versions of the photo for a resource.
|
12
|
-
def photo(client, resource_id)
|
13
|
-
url = "/services/data/v#{client.version}/chatter/#{self.resource_name}/#{resource_id}/photo"
|
14
|
-
result = client.http_get(url)
|
15
|
-
JSON.parse(result.body)
|
16
|
-
end
|
17
|
-
|
18
|
-
# Uploads a photo for a resource with id _resource_id_.
|
19
|
-
#
|
20
|
-
# User.upload_photo(@client, "me", File.open("SomePicture.png"), "image/png")
|
21
|
-
def upload_photo(client, resource_id, io, file_type)
|
22
|
-
url = "/services/data/v#{client.version}/chatter/#{self.resource_name}/#{resource_id}/photo"
|
23
|
-
result = client.http_multipart_post(url, {"fileUpload" => UploadIO.new(io, file_type)})
|
24
|
-
JSON.parse(result.body)
|
25
|
-
end
|
26
|
-
|
27
|
-
# Deletes the photo for the resource with id _resource_id_.
|
28
|
-
def delete_photo(client, resource_id)
|
29
|
-
client.http_delete "/services/data/v#{client.version}/chatter/#{self.resource_name}/#{resource_id}/photo"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Returns a Hash with urls for the small and large versions of the photo for this resource.
|
34
|
-
#
|
35
|
-
# User.find(@client, "me").photo #=> {"smallPhotoUrl"=>"/small/photo/url", "largePhotoUrl"=>"/large/photo/url"}
|
36
|
-
def photo
|
37
|
-
self.raw_hash["photo"]
|
38
|
-
end
|
39
|
-
|
40
|
-
# Uploads a photo for this resource.
|
41
|
-
#
|
42
|
-
# me = User.find(@client)
|
43
|
-
# me.upload_photo(File.open("SomePicture.png"), "image/png")
|
44
|
-
def upload_photo(io, file_type)
|
45
|
-
self.class.upload_photo(self.client, self.id, io, file_type)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Deletes the photo for this resource.
|
49
|
-
def delete_photo
|
50
|
-
self.class.delete_photo(self.client, self.id)
|
51
|
-
photo
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
data/lib/sfdc/chatter/record.rb
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module Sfdc
|
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 = Sfdc::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 = Sfdc::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
|
data/lib/sfdc/chatter/user.rb
DELETED
@@ -1,153 +0,0 @@
|
|
1
|
-
require 'Sfdc/chatter/record'
|
2
|
-
require 'Sfdc/chatter/photo_methods'
|
3
|
-
|
4
|
-
module Sfdc
|
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 = Sfdc::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 = Sfdc::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 = Sfdc::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
|