-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
39 lines (36 loc) · 1.27 KB
/
api.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
var Prestan = require('prestan')
var executeRequest = Prestan.prototype.executeRequest
Prestan.prototype.executeRequest = function (method, url, options = {}) {
if (options.form) {
options.body = options.form
if (!options.headers) {
options.headers = { 'Content-Type': 'application/x-www-form-urlencoded' }
} else {
options.headers['Content-Type'] = 'application/x-www-form-urlencoded'
}
delete options.form
}
return executeRequest.apply(this, arguments)
}
// FIX Non-whitespace before first tag. issue
var parse = Prestan.prototype.parse;
Prestan.prototype.parse = function(response) {
if(this.options.raw) {
return response;
}
response = response.replace(/[\ufeff]/ig, '')
return parse.apply(this, arguments);
}
Prestan.prototype.upload = function (resource, data = {}, options = {}) {
let url = this.resource(resource)
if (!data || typeof data !== 'object') {
throw new Error('No data specified to send, should be an object')
}
let query = this.stringify(options)
if (query.length) {
url += `?${query}`
}
return this.executeRequest('post', url, { formData: data }).then(response => this.parse(response))
}
var prestan = new Prestan('https://www.clothesgate.com', 'QVSXCGWWD754Z9WIGA3H2R3V7W1YYVHJ')
module.exports = prestan