-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
68 lines (66 loc) · 2.56 KB
/
index.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
var
Mbsy = require('./lib/mbsy');
// Export as main entry point in this module
/**
* The main mbsy constructor, takes the api key, api username and additional options
* Visit https://getambassador.com/api for api id and key
* @param {String} api_username The users API id
* @param {String} api_key The users API key
* @param {Object} options Optional options
* @return {mbsy}
*/
module.exports.createClient = function(api_username, api_key, options) {
var mbsy = new Mbsy(api_username, api_key, options);
return {
Event: {
/**
* Records an instance of a campaign referral event.
* @param {Object} params as described on https://getambassador.com/#v2_method_event_record
* @param {Function} cb The callback function with the results
* @return {void}
*/
record: function(params, cb) {
if (!params || !params.campaign_uid) return cb('Required params missing: campaign_uid');
if (!params || !params.email) return cb('Required params missing: email');
mbsy._doRequest(mbsy._generateNiceUrl(params, 'event/record'), cb);
},
/**
* Records an instance of a campaign referral event.
* @param {Object} params as described on https://getambassador.com/#v2_method_event_record
* @param {Function} cb The callback function with the results
* @return {void}
*/
multi_record: function(params, cb) {
if (!params || !params.campaign_uid) return cb('Required params missing: campaign_uid');
if (!params || !params.email) return cb('Required params missing: email');
mbsy._doRequest(mbsy._generateNiceUrl(params, 'event/multi_record'), cb);
}
},
Ambassador: {
/**
* Retrieves details about a given ambassador including their active share links.
* Automatically creates the requested ambassador if they do not exist yet.
* @param {Object} params as described on https://getambassador.com/#v2_method_ambassador_get
* @param {Function} cb The callback function with the results
* @return {void}
*/
get: function(params, cb) {
if (!params || !params.email) return cb('Required params missing: email');
mbsy._doRequest(mbsy._generateNiceUrl(params, 'ambassador/get'), cb);
}
},
Custom: {
/**
* Generic api call
* Check all available methods on https://getambassador.com/api
* @param {String} method eg. "company/get"
* @param {Object} method params
* @param {Function} cb The callback function with the results
* @return {void}
*/
get: function(method, params, cb) {
mbsy._doRequest(mbsy._generateNiceUrl(params, method), cb);
}
}
}
}