-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathactivity.html
174 lines (151 loc) · 6.23 KB
/
activity.html
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" data-app-id="CLIENT ID HERE" src="https://assets.yammer.com/assets/platform_js_sdk.js"></script>
</head>
<body>
<script>
function logout() {
yam.platform.getLoginStatus(
function (response) {
if (response.authResponse) {
yam.platform.logout(function (response) {
toggleLoginStatus(false);
location.reload();
})
}
}
);
}
function toggleLoginStatus(loggedIn) {
if (loggedIn) {
$('.not-logged-in').hide();
$('.logged-in').show('slow');
} else {
$('.not-logged-in').show('slow');
$('.logged-in').hide();
}
}
function displayAuthResult(authResult) {
console.log("AuthResult", authResult); //print user information to the console
$('#yammer-login').innerHTML = 'Welcome to Yammer!';
toggleLoginStatus(true);
$('#authResult').html('Auth Result:<br/>');
for (var field in authResult) {
$('#authResult').append(' ' + field + ': ' +
authResult[field] + '<br/>');
}
$('#authOps').show('slow');
}
function postActivity() {
yam.platform.request({
// yam.request({
url: "activity.json", //this is one of many REST endpoints that are available
method: "POST",
data: {
"activity": {
"actor": {"name": "Brian Davis", "email": "EMAIL HERE"},
"action": "create",
"object": {
"url": "https://www.news.google.com",
"image":"https://a248.e.akamai.net/assets.github.com/images/modules/dashboard/octofication.png",
"description":"Testing Activity STREAM",
"title":"yam-git-OG"
},
"private": "false",
"message": "testing commit"
}
},
success: function (activity) { //print message response information to the console
console.log("Activity request was successful.");
console.dir(activity);
$('#authResult').html('User Result:<br/>');
for (var field in activity) {
$('#authResult').append(' ' + field + ': ' +
escape(activity[field]) + '<br/>');
}
},
error: function (activity) {
console.error("There was an error with the request.");
}
});
}
function getCurrentGroups() {
yam.platform.request({
// yam.request({
url: "groups.json?mine=1",
method: "GET",
data: {},
success: function (group) {
$mygroup = "";
for ($i = 0; $i < group.length; $i++) {
$mygroup += '<img src="' + group[$i].mugshot_url + '">' + " " + group[$i].full_name + "," + "<br>";
}
$("#current-groups").html($mygroup);
},
error: function (group) {
console.error("There was an error with the request.");
}
});
}
function login() {
console.log("Trigger LoginStatus");
yam.platform.getLoginStatus(
function (response) {
if (response.authResponse) {
console.log("Logged in");
displayAuthResult(response.access_token);
localStorage.setItem(1, JSON.stringify(response.access_token.token).replace(/"/g, ""));
} else {
console.log("Not logged in. Going to login now.");
yam.platform.login(function (response) { //prompt user to login and authorize your app, as necessary
if (response.authResponse) {
displayAuthResult(response.access_token);
localStorage.setItem(1, JSON.stringify(response.access_token.token).replace(/"/g, ""));
}
});
}
}
);
}
function logout() {
yam.platform.getLoginStatus(
function (response) {
if (response.authResponse) {
yam.platform.logout(function (response) {
console.log("User was logged out");
location.reload();
})
} else {
toggleLoginStatus(false);
}
}
);
}
$(document).ready(function () {
$('#disconnect').click(logout);
$('#yammer-js-login-button').click(login);
$('#yammer-user-button').click(postActivity);
$('#yammer-group-button').click(getCurrentGroups);
});
</script>
<div id='page'>
<div>
<h2>JS SDK</h2>
<button id="yammer-js-login-button">JS Login</button>
<button id="yammer-user-button">Get Current User</button>
<button id="yammer-group-button">Get Current Groups</button>
<div id="current-groups"></div>
</div>
<div class="logged-in" style="display:none">
<p>User is now signed in to the app using Yammer</p>
<button id="disconnect" class="yj-btn yj-btn-alt">Log out from your Yammer account</button>
</div>
<div class="logged-in" style="display:none">
<h2>Authentication Logs</h2>
<pre id="authResult"></pre>
</div>
</div>
</body>
</html>