-
Notifications
You must be signed in to change notification settings - Fork 0
/
collection.js
30 lines (28 loc) · 1009 Bytes
/
collection.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
/**
* Module dependencies.
*/
var http = require('http'),
Config = require('./config'),
Rest = require('./restler');
exports.load = function (collectionId, handler) {
var target = Config.shopUrl + '/rest/collections/' + collectionId + '?fields=title';
console.time(target);
Rest.get(target, {'headers':{'Authorization':'Bearer ' + Config.accessToken}}).on('success', function(data) {
handler(null, data);
}).on('error', function(data) {
handler(new Error("Failed to load collection"), null);
}).on('complete', function(data) {
console.timeEnd(target);
});
}
exports.list = function (handler) {
var target = Config.shopUrl + '/rest/collections?fields=title';
console.time(target);
Rest.get(target, {'headers':{'Authorization':'Bearer ' + Config.accessToken}}).on('success', function(data) {
handler(null, data);
}).on('error', function(data) {
handler(new Error("Failed to load collections"), null);
}).on('complete', function(data) {
console.timeEnd(target);
});
}