-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (41 loc) · 1.29 KB
/
Copy pathindex.js
File metadata and controls
52 lines (41 loc) · 1.29 KB
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
var querystring = require('querystring'),
_ = require('underscore'),
request = require('request');
var SDK = function(config) {
if (!config || !config.api_key || !config.api_secret)
return false;
this.api_key = config.api_key;
this.api_secret = config.api_secret;
this.region = config.region ? config.region : "cn";
};
SDK.prototype.apiUrl = function(path){
return 'https://api' + this.region + '.faceplusplus.com/v2/' + path;
};
SDK.prototype.get = function(path, data, callback){
var url = this.apiUrl(path);
params = _.extend({
api_key : this.api_key,
api_secret : this.api_secret,
}, data);
url += '?' + querystring.stringify(params);
request.get(url, {json : true}, callback);
};
SDK.prototype.post = function(path, data, callback){
var url = this.apiUrl(path),
params = _.extend({
api_key : this.api_key,
api_secret : this.api_secret,
}, data);
request.post(url, {json : true, form:params}, callback);
};
SDK.prototype.postMulti = function(path, data, callback){
var url = this.apiUrl(path);
var r = request.post(url, {json : true}, callback);
var form = r.form();
form.append('api_key', this.api_key);
form.append('api_secret', this.api_secret);
_.each(data, function(obj, key){
form.append(key, obj.value, obj.meta);
});
};
module.exports = SDK;