Skip to content

Commit

Permalink
Format all files with .editorconfig.
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoffrey Roguelon committed Jan 9, 2017
1 parent 2bc4109 commit c2abe08
Show file tree
Hide file tree
Showing 26 changed files with 517 additions and 298 deletions.
26 changes: 13 additions & 13 deletions lib/regaliator.js
Expand Up @@ -9,62 +9,62 @@ function Regaliator(apiHost, apiKey, secret) {

this.request = new Request(apiHost, apiKey, secret);

this.account = function() {
this.account = function () {
return this.request.get('/account');
};

this.bills = function(params) {
this.bills = function (params) {
return this.request.get('/bills', params);
};

this.createCredentialsBill = function(billerId, login, password) {
this.createCredentialsBill = function (billerId, login, password) {
return this.request.post('/bills', {
biller_id: billerId,
login: login,
password: password
});
};

this.createAccountNumberBill = function(billerId, accountNumber) {
this.createAccountNumberBill = function (billerId, accountNumber) {
return this.request.post('/bills', {
biller_id: billerId,
account_number: accountNumber
});
};

this.updateBillMfas = function(billId, mfas) {
this.updateBillMfas = function (billId, mfas) {
return this.request.patch('/bills/' + billId, mfas);
};

this.showBill = function(billId) {
this.showBill = function (billId) {
return this.request.get('/bills/' + billId);
};

this.showBillXdata = function(billId) {
this.showBillXdata = function (billId) {
return this.request.get('/bills/' + billId + '/xdata');
};

this.xpayBill = function(billId, content) {
this.xpayBill = function (billId, content) {
return this.request.post('/bills/' + billId + '/pay', content);
};

this.xchangeBill = function(billId, content) {
this.xchangeBill = function (billId, content) {
return this.request.post('/bills/' + billId + '/xchange', content);
};

this.updateBill = function(billId, content) {
this.updateBill = function (billId, content) {
return this.request.patch('/bills/' + billId, content);
};

this.billers = function(type, params) {
this.billers = function (type, params) {
return this.request.get('/billers/' + type, params);
};

this.rates = function() {
this.rates = function () {
return this.request.get('/rates');
};

this.transactions = function(params) {
this.transactions = function (params) {
return this.request.get('/transactions', params);
};
}
Expand Down
24 changes: 12 additions & 12 deletions lib/request.js
Expand Up @@ -21,23 +21,23 @@ function Request(apiHost, apiKey, secret) {

let that = this;

this.get = function(endpoint, params) {
this.get = function (endpoint, params) {
const contentMd5 = '';
const queryParams = parameterize(params);
const headers = generateHeaders(endpoint, contentMd5);

return request('GET', headers, that.apiHost + endpoint + queryParams);
};

this.post = function(endpoint, content) {
this.post = function (endpoint, content) {
const contentJson = json_encode(content);
const contentMd5 = md5(contentJson);
const headers = generateHeaders(endpoint, contentMd5);

return request('POST', headers, that.apiHost + endpoint, contentJson);
};

this.patch = function(endpoint, content) {
this.patch = function (endpoint, content) {
const contentJson = json_encode(content);
const contentMd5 = md5(contentJson);
const headers = generateHeaders(endpoint, contentMd5);
Expand Down Expand Up @@ -78,14 +78,14 @@ function Request(apiHost, apiKey, secret) {

function parameterize(params) {
switch (typeof params) {
case 'string':
params = '?' + params;
break;
case 'object':
params = '?' + querystring.stringify(params);
break;
default:
params = '';
case 'string':
params = '?' + params;
break;
case 'object':
params = '?' + querystring.stringify(params);
break;
default:
params = '';
}

return params;
Expand All @@ -103,7 +103,7 @@ function Request(apiHost, apiKey, secret) {

res.setEncoding('utf8');
res.on('data', (chunk) => body += chunk);
res.on('end', () => resolve({ body: JSON.parse(body), req: res.req, res: res }));
res.on('end', () => resolve({body: JSON.parse(body), req: res.req, res: res}));
});

req.on('error', reject);
Expand Down
4 changes: 2 additions & 2 deletions test/proxy_server.js
Expand Up @@ -11,11 +11,11 @@ function ProxyServer(tape) {

this.proxy = http.createServer(tape);

this.listen = function(done) {
this.listen = function (done) {
this.proxy.listen(4567, done);
};

this.close = function(done) {
this.close = function (done) {
this.proxy.close(done);
};
}
60 changes: 30 additions & 30 deletions test/regaliator/account.js
Expand Up @@ -6,35 +6,35 @@ const ProxyServer = require('../proxy_server');
const Regaliator = require('../../lib/regaliator');

describe('Regaliator', () => {
describe('Account', () => {
describe('Successed call', () => {
let proxy = new ProxyServer(require('../tapes/account/successful_info'));

before('Creating fake server', (done) => proxy.listen(done));
after('Killing fake server', (done) => proxy.close(done));

it('should return JSON body', () => {
return new Regaliator('http://localhost:4567', 'key', 'secret')
.account()
.then((res) => {
assert.propertyVal(res.body, 'name', 'ABC Ltd');
});
});
});

describe('Failed call', () => {
let proxy = new ProxyServer(require('../tapes/account/failed_info'));

before('Creating fake server', (done) => proxy.listen(done));
after('Killing fake server', (done) => proxy.close(done));

it('should return JSON error', () => {
return new Regaliator('http://localhost:4567', 'key', 'secret')
.account()
.then((res) => {
assert.propertyVal(res.body, 'message', 'Unauthorized');
});
});
});
describe('Account', () => {
describe('Successed call', () => {
let proxy = new ProxyServer(require('../tapes/account/successful_info'));

before('Creating fake server', (done) => proxy.listen(done));
after('Killing fake server', (done) => proxy.close(done));

it('should return JSON body', () => {
return new Regaliator('http://localhost:4567', 'key', 'secret')
.account()
.then((res) => {
assert.propertyVal(res.body, 'name', 'ABC Ltd');
});
});
});

describe('Failed call', () => {
let proxy = new ProxyServer(require('../tapes/account/failed_info'));

before('Creating fake server', (done) => proxy.listen(done));
after('Killing fake server', (done) => proxy.close(done));

it('should return JSON error', () => {
return new Regaliator('http://localhost:4567', 'key', 'secret')
.account()
.then((res) => {
assert.propertyVal(res.body, 'message', 'Unauthorized');
});
});
});
});
});

0 comments on commit c2abe08

Please sign in to comment.