-
Notifications
You must be signed in to change notification settings - Fork 2
/
chatterlang.erl
69 lines (50 loc) · 2.15 KB
/
chatterlang.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-module(chatterlang).
-export([login/3,login/4,post_link/4,update_status/3,post_file_to_group/7,post_file/5]).
login (Username, Password, SecurityToken)->
sfdc:login(Username, Password, SecurityToken).
login (Username, Password, SecurityToken, Endpoint)->
sfdc:login(Username, Password, SecurityToken, Endpoint).
post_link(Url, Description, SessionId, Endpoint)->
Id=get_current_user_id(SessionId, Endpoint),
PostLinkSobject=[
{"type", "string", "FeedPost"},
{"ParentId", "string", Id},
{"LinkUrl", "string", Url}
],
case Description of
"" -> sfdc:create(PostLinkSobject, SessionId, Endpoint);
_ -> sfdc:create(lists:flatten([PostLinkSobject,{"Title", "string", Description}]), SessionId, Endpoint)
end.
update_status(Status, SessionId, Endpoint)->
Id=get_current_user_id(SessionId, Endpoint),
UpdateStatusSobject=[
{"type", "string", "User"},
{"Id", "string", Id},
{"CurrentStatus", "string", Status}
],
sfdc:update(UpdateStatusSobject, SessionId, Endpoint).
post_file(PostBody, Description, Name, File, SessionId, Endpoint)->
UserId=get_current_user_id(SessionId, Endpoint),
PostFileObject=[
{"type", "string", "FeedItem"},
{"ParentId", "string", UserId},
{"Body", "string", PostBody},
{"ContentDescription", "string", Description},
{"ContentFileName", "string", Name},
{"ContentData", "base64Binary", base64:encode_to_string(File)}
],
sfdc:create(PostFileObject, SessionId, Endpoint).
post_file_to_group(GroupId, PostBody, Description, Name, File, SessionId, Endpoint)->
PostFileObject=[
{"type", "string", "FeedPost"},
{"ParentId", "string", GroupId},
{"Body", "string", PostBody},
{"ContentDescription", "string", Description},
{"ContentFileName", "string", Name},
{"ContentData", "base64Binary", base64:encode_to_string(File)}
],
sfdc:create(PostFileObject, SessionId, Endpoint).
get_current_user_id(SessionId, Endpoint)->
UserInfo=sfdc:get_user_info(SessionId, Endpoint),
{_,_,Id}=lists:keyfind("userId", 1, UserInfo),
Id.