-
Notifications
You must be signed in to change notification settings - Fork 0
/
handshake.js
63 lines (55 loc) · 1.49 KB
/
handshake.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
(function ( exports ) {
function handshakejsSdk( $ ) {
var app_name,
root_url;
function _sendRequest ( endpoint, data, callback ) {
return $.ajax({
crossDomain : true,
url : root_url + endpoint,
data : data,
type : "POST",
success : function ( res, statuscode ) {
callback(null, res);
},
error : function ( xhr, statuscode ) {
var res = xhr.responseJSON;
var msg = res.errors[0].message;
var err = new Error(msg);
callback(err, res);
}
});
}
function _setCall ( endpoint ) {
return function ( values, callback ) {
values = typeof values !== 'undefined' ? values : {};
values.app_name = app_name;
_sendRequest( endpoint, values, function( err, res ) {
callback( err, res );
});
}
}
return {
setAppName: function ( value ) {
app_name = value;
},
getAppName: function ( ) {
return app_name;
},
setRootUrl: function ( value ) {
root_url = value;
},
getRootUrl: function ( ) {
return root_url;
},
login: {
request: _setCall('/api/v1/login/request.json'),
confirm: _setCall('/api/v1/login/confirm.json')
}
}
}
if ( typeof define === 'function' ) {
return define( 'Handshakejs', ['jquery'], handshakejsSdk )
}
// globals
exports.Handshakejs = handshakejsSdk( jQuery );
}( this ));