-
Notifications
You must be signed in to change notification settings - Fork 548
/
joinme.js
165 lines (131 loc) · 2.85 KB
/
joinme.js
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
(function(hello) {
hello.init({
joinme: {
name: 'join.me',
oauth: {
version: 2,
auth: 'https://secure.join.me/api/public/v1/auth/oauth2',
grant: 'https://secure.join.me/api/public/v1/auth/oauth2'
},
refresh: false,
scope: {
basic: 'user_info',
user: 'user_info',
scheduler: 'scheduler',
start: 'start_meeting',
email: '',
friends: '',
share: '',
publish: '',
photos: '',
publish_files: '',
files: '',
videos: '',
offline_access: ''
},
scope_delim: ' ',
login: function(p) {
p.options.popup.width = 400;
p.options.popup.height = 700;
},
base: 'https://api.join.me/v1/',
get: {
me: 'user',
meetings: 'meetings',
'meetings/info': 'meetings/@{id}'
},
post: {
'meetings/start/adhoc': function(p, callback) {
callback('meetings/start');
},
'meetings/start/scheduled': function(p, callback) {
var meetingId = p.data.meetingId;
p.data = {};
callback('meetings/' + meetingId + '/start');
},
'meetings/schedule': function(p, callback) {
callback('meetings');
}
},
patch: {
'meetings/update': function(p, callback) {
callback('meetings/' + p.data.meetingId);
}
},
del: {
'meetings/delete': 'meetings/@{id}'
},
wrap: {
me: function(o, headers) {
formatError(o, headers);
if (!o.email) {
return o;
}
o.name = o.fullName;
o.first_name = o.name.split(' ')[0];
o.last_name = o.name.split(' ')[1];
o.id = o.email;
return o;
},
'default': function(o, headers) {
formatError(o, headers);
return o;
}
},
xhr: formatRequest
}
});
function formatError(o, headers) {
var errorCode;
var message;
var details;
if (o && ('Message' in o)) {
message = o.Message;
delete o.Message;
if ('ErrorCode' in o) {
errorCode = o.ErrorCode;
delete o.ErrorCode;
}
else {
errorCode = getErrorCode(headers);
}
o.error = {
code: errorCode,
message: message,
details: o
};
}
return o;
}
function formatRequest(p, qs) {
// Move the access token from the request body to the request header
var token = qs.access_token;
delete qs.access_token;
p.headers.Authorization = 'Bearer ' + token;
// Format non-get requests to indicate json body
if (p.method !== 'get' && p.data) {
p.headers['Content-Type'] = 'application/json';
if (typeof (p.data) === 'object') {
p.data = JSON.stringify(p.data);
}
}
if (p.method === 'put') {
p.method = 'patch';
}
return true;
}
function getErrorCode(headers) {
switch (headers.statusCode) {
case 400:
return 'invalid_request';
case 403:
return 'stale_token';
case 401:
return 'invalid_token';
case 500:
return 'server_error';
default:
return 'server_error';
}
}
}(hello));