emailable
Advanced tools
Comparing version 3.0.4 to 3.0.5
@@ -11,3 +11,3 @@ 'use strict'; | ||
return this.client.makePostRequest( | ||
'post', 'batch', Object.assign({}, { emails: emails.join(',') }, options) | ||
'batch', { emails: emails.join(','), ...options } | ||
); | ||
@@ -17,5 +17,3 @@ } | ||
status(id, options = {}) { | ||
return this.client.makeRequest( | ||
'get', 'batch', Object.assign({}, { id: id }, options) | ||
); | ||
return this.client.makeGetRequest('batch', { id: id, ...options }); | ||
} | ||
@@ -22,0 +20,0 @@ |
@@ -8,22 +8,30 @@ 'use strict'; | ||
constructor(key) { | ||
this.key = key; | ||
this.instance = axios.create({ baseURL: 'https://api.emailable.com/v1/' }); | ||
if (key) { | ||
this.instance.defaults.headers.common['Authorization'] = `Bearer ${key}`; | ||
} | ||
} | ||
makeRequest(method, endpoint, params = {}, transformResponse) { | ||
makeGetRequest(endpoint, params = {}) { | ||
return new Promise((resolve, reject) => { | ||
this.instance.get(endpoint, { params: params }) | ||
.then(response => resolve(response.data)) | ||
.catch(error => { | ||
if (error.response) { | ||
reject({ | ||
message: error.response.data.message, | ||
code: error.response.status | ||
}) | ||
} else { | ||
reject({ message: error }); | ||
} | ||
}); | ||
}); | ||
}; | ||
params = Object.assign(params, { api_key: this.key }) | ||
makePostRequest(endpoint, data = {}) { | ||
return new Promise((resolve, reject) => { | ||
axios({ | ||
method: method, | ||
url: `https://api.emailable.com/v1/${endpoint}`, | ||
params: params, | ||
transformResponse: transformResponse | ||
}) | ||
.then(response => { | ||
resolve(response.data); | ||
}) | ||
.catch(error => { | ||
if (error.response) { | ||
this.instance.post(endpoint, data) | ||
.then(response => resolve(response.data)) | ||
.catch(error => { | ||
reject({ | ||
@@ -33,36 +41,8 @@ message: error.response.data.message, | ||
}) | ||
} else { | ||
reject({ message: error }); | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
makePostRequest(method, endpoint, data = {}, transformResponse) { | ||
data = Object.assign(data, { api_key: this.key }) | ||
return new Promise((resolve, reject) => { | ||
axios({ | ||
method: method, | ||
url: `https://api.emailable.com/v1/${endpoint}`, | ||
data: data, | ||
transformResponse: transformResponse | ||
}) | ||
.then(response => { | ||
resolve(response.data); | ||
}) | ||
.catch(error => { | ||
reject({ | ||
message: error.response.data.message, | ||
code: error.response.status | ||
}) | ||
}); | ||
}); | ||
}; | ||
} | ||
module.exports = Client; |
@@ -14,9 +14,7 @@ 'use strict'; | ||
verify(email, options = {}) { | ||
var params = Object.assign({ email: email }, options); | ||
return this.client.makeRequest('get', 'verify', params); | ||
return this.client.makePostRequest('verify', { email: email, ...options }); | ||
} | ||
account() { | ||
return this.client.makeRequest('get', 'account'); | ||
return this.client.makeGetRequest('account'); | ||
} | ||
@@ -23,0 +21,0 @@ |
{ | ||
"name": "emailable", | ||
"version": "3.0.4", | ||
"version": "3.0.5", | ||
"description": "Email Verification that's astonishingly easy and low-cost. See https://emailable.com for details.", | ||
"main": "lib/emailable.js", | ||
"types": "lib/emailable.d.ts", | ||
"scripts": { | ||
"test": "mocha --timeout 10000" | ||
"test": "mocha --timeout 10000 && tsd" | ||
}, | ||
"tsd": { | ||
"directory": "test" | ||
}, | ||
"repository": { | ||
@@ -31,3 +35,4 @@ "type": "git", | ||
"chai": "^4.2.0", | ||
"mocha": "^9.2.0" | ||
"mocha": "^9.2.0", | ||
"tsd": "^0.30.3" | ||
}, | ||
@@ -34,0 +39,0 @@ "dependencies": { |
@@ -16,3 +16,3 @@ 'use strict'; | ||
it('should return a 401 status code when an invalid API key', done => { | ||
it('should return a 401 status code when no API key', done => { | ||
require('../lib/emailable')().account().catch(error => { | ||
@@ -24,2 +24,9 @@ expect(error.code).to.be.equal(401); | ||
it('should return a 403 status code when an invalid API key', done => { | ||
require('../lib/emailable')('test_xxxxxxxxxx').account().catch(error => { | ||
expect(error.code).to.be.equal(403); | ||
done(); | ||
}); | ||
}); | ||
}); |
13418
13
193
3