-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex-es5.js
144 lines (130 loc) · 4.11 KB
/
index-es5.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
'use strict';
var _createClass = function () {
function defineProperties(target, props) { for (var i = 0; i < props.length; i++) {
var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor);
} } return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor;
};
}();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var axios = require('axios');
var httpAdapter = require('axios/lib/adapters/http');
var querystring = require('querystring');
// axios settings needed when testing actions
axios.defaults.host = 'https://api.envato.com';
axios.defaults.adapter = httpAdapter;
var EnvatoApi = function () {
function EnvatoApi(options) {
_classCallCheck(this, EnvatoApi);
this.username = options.username;
this.token = options.token;
this.baseUrl = 'https://api.envato.com/';
this.baseVersion = 'v1';
}
_createClass(EnvatoApi, [{
key: 'prepareUrl',
value: function prepareUrl(version, url) {
return this.baseUrl + (version ? version : this.baseVersion) + url;
},
}, {
key: 'get',
value: function get(options, callback) {
var url = this.prepareUrl(options.version, options.url);
if (options.params) {
url += '?' + querystring.stringify(options.params);
}
return axios.get(url, {
headers: { Authorization: 'Bearer ' + this.token },
}).then(function (result) {
return callback(null, result.data);
}).catch(function (err) {
return callback(err);
});
},
}, {
key: 'totalItems',
value: function totalItems(callback) {
return this.get({
url: '/market/total-items.json',
}, callback);
},
}, {
key: 'totalUsers',
value: function totalUsers(callback) {
return this.get({
url: '/market/total-users.json',
}, callback);
},
}, {
key: 'userUsername',
value: function userUsername(callback) {
return this.get({
url: '/market/private/user/username.json',
}, callback);
},
}, {
key: 'userEmail',
value: function userEmail(callback) {
return this.get({
url: '/market/private/user/email.json',
}, callback);
},
}, {
key: 'userDetails',
value: function userDetails(params, callback) {
return this.get({
url: '/market/user:' + params.username + '.json',
}, callback);
},
}, {
key: 'userAccount',
value: function userAccount(callback) {
return this.get({
url: '/market/private/user/account.json',
}, callback);
},
}, {
key: 'userBadges',
value: function userBadges(params, callback) {
return this.get({
url: '/market/user-badges:' + params.username + '.json',
}, callback);
},
}, {
key: 'authorItemsBySite',
value: function authorItemsBySite(params, callback) {
return this.get({
url: '/market/user-items-by-site:' + params.username + '.json',
}, callback);
},
}, {
key: 'authorFiles',
value: function authorFiles(params, callback) {
var username = params.username,
site = params.site;
return this.get({
url: '/market/new-files-from-user:' + username + ',' + site + '.json',
}, callback);
},
}, {
key: 'authorEarningsSales',
value: function authorEarningsSales(callback) {
return this.get({
url: '/market/private/user/earnings-and-sales-by-month.json',
}, callback);
},
}, {
key: 'authorStatement',
value: function authorStatement(params, callback) {
return this.get({
url: '/market/user/statement',
version: 'v3',
params: params,
}, callback);
},
},]);
return EnvatoApi;
}();
module.exports = function (options) {
return new EnvatoApi(options);
};