Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickP committed Jun 18, 2016
2 parents 7934c3b + e19867a commit 7465123
Show file tree
Hide file tree
Showing 38 changed files with 1,235 additions and 641 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Change Log

All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [1.1.0] - 2016-06-18

### Added

+ Get one card
+ Cards are now instance of `Card`
+ Add Set / get limits on card
+ Add Block / unblock on card
+ Better CLI for unmocked tests
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Not all endpoints are available yet.
+ [x] Get Transactions (with search)
+ [x] Add / update memo on transactions
+ [x] Create a transfert
+ [ ] unpair
+ [x] unpair
+ [ ] pair
+ [ ] certify transfer

Expand Down Expand Up @@ -103,7 +103,4 @@ Run `npm test` for full mocked testing with coverage.

Less asserts. Used for detect api change.

Run `[email protected] TEST_PASSWORD=ilovemylittlepony TRANSFER_IBAN=FR7630001007941234567890185 TRANSFER_BIC=BNPAFRPP TRANSFER_NAME="George Loutre" TRANSFER_PIN=123456 npm run test-unmock` for un-mocked test.

The transfer test (*0.01 €) can be switch off with env `NO_TRANSFER`.
Otherwise, *it should be confirmed* in the app.
Run `npm run test-unmock` for un-mocked test.
35 changes: 20 additions & 15 deletions lib/account.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
const Promise = require('bluebird');

const Card = require('./card.js');

const api = require('./api');
const utils = require('./utils');

Expand Down Expand Up @@ -41,17 +43,9 @@ const utils = require('./utils');
/**
* @typedef cards
*
* @property {objet} paging
* @property {number} paging.totalResults Total amount of addresses
* @property {Object[]} data
* @property {String} data.id
* @property {String} data.cardType Card type
* @property {String} data.n26Status Card status
* @property {String} data.maskedPan Number card (masked)
* @property {String} data.expirationDate Expiration date
* @property {String} data.pinDefined
* @property {String} data.cardActivated
* @property {String} data.usernameOnCard Name on the card
* @property {objet} paging
* @property {number} paging.totalResults Total amount of addresses
* @property {Card[]} data
*/

/**
Expand Down Expand Up @@ -328,12 +322,23 @@ class Account {
}

/**
* Get cards
* Get one specific or all cards
*
* @return {Promise<cards>}
* @param {String} [cardId] Card Id
*
* @return {Promise<Card>|Promise<cards>}
*/
cards() {
return utils.callApi(this, 'getCards');
cards(cardId) {
if (cardId) {
return utils.callApi(this, 'getCard', cardId)
.then((card) => new Card(this, card));
}

return utils.callApi(this, 'getCards')
.then(cards => ({
paging: cards.paging,
data: cards.data.map((card) => new Card(this, card))
}));
}

/**
Expand Down
55 changes: 55 additions & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ module.exports = {
.catch(errorHandler);
},

blockCard(token, cardId) {
return request.post({
url: `${api}/api/cards/${cardId}/block`,
json: true,
headers: {
Authorization: `Bearer ${token}`
}
})
.catch(errorHandler);
},

unblockCard(token, cardId) {
return request.post({
url: `${api}/api/cards/${cardId}/unblock`,
json: true,
headers: {
Authorization: `Bearer ${token}`
}
})
.catch(errorHandler);
},

checkBarzahlen(token) {
return request.get({
url: `${api}/api/barzahlen/check`,
Expand Down Expand Up @@ -103,6 +125,17 @@ module.exports = {
.catch(errorHandler);
},

getCard(token, cardId) {
return request.get({
url: `${api}/api/cards/${cardId}`,
json: true,
headers: {
Authorization: `Bearer ${token}`
}
})
.catch(errorHandler);
},

getCards(token) {
return request.get({
url: `${api}/api/cards`,
Expand All @@ -114,6 +147,28 @@ module.exports = {
.catch(errorHandler);
},

getCardLimits(token, cardId) {
return request.get({
url: `${api}/api/settings/limits/${cardId}`,
json: true,
headers: {
Authorization: `Bearer ${token}`
}
})
.catch(errorHandler);
},

setCardLimits(token, opt) {
return request.put({
url: `${api}/api/settings/limits/${opt.cardId}`,
json: opt.limit,
headers: {
Authorization: `Bearer ${token}`
}
})
.catch(errorHandler);
},

getContacts(token) {
return request.get({
url: `${api}/api/smrt/contacts`,
Expand Down
79 changes: 79 additions & 0 deletions lib/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
'use strict';

const Promise = require('bluebird');

const utils = require('./utils');

/**
* @typedef cardLimit
*
* @property {String} limit Limit type
* @property {Number} [amount] Amount
* @property {String[]} [countryList] Array of country code
*/

/**
* Card instance
* linked to an account. An account should contains many card.
*/
class Card {
constructor(account, card) {
this.account = account;
this.id = card.id;
this.cardType = card.cardType;
this.n26Status = card.n26Status;
this.maskedPan = card.maskedPan;
this.expirationDate = card.expirationDate;
this.pinDefined = card.pinDefined;
this.cardActivated = card.cardActivated;
this.usernameOnCard = card.usernameOnCard;
}

/**
* Get / set card limit
*
* @param {Object} [limit]
* @param {String} limit.limit Limit type
* @param {Number} [limit.amount] Amount
* @param {String[]} [limit.countryList] Array of country code
*
* @return {Promise<cardLimit[]>}
*/
limits(limit) {
return Promise.try(() => {
if (limit) {
if (!limit.limit ||
(limit.limit === 'COUNTRY_LIST' && !limit.countryList) ||
(limit.limit !== 'COUNTRY_LIST' && limit.amount === undefined)) {
throw new Error('BAD_PARAMS');
}

return utils.callApi(this.account, 'setCardLimits', {cardId: this.id, limit});
}

return utils.callApi(this.account, 'getCardLimits', this.id);
});
}

/**
* Block card
*
* @return {Promise}
*/
block() {
return utils.callApi(this.account, 'blockCard', this.id)
.tap(() => { this.n26Status = 'BLOCKED'; });
}

/**
* Unblock card
*
* @return {Promise}
*/
unblock() {
return utils.callApi(this.account, 'unblockCard', this.id)
.tap(() => { this.n26Status = 'ACTIVE'; });
}
}

module.exports = Card;
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "number26",
"version": "1.0.0",
"version": "1.1.0",
"description": "Un-official node.js module for interact with your number26 account",
"main": "index.js",
"scripts": {
"test": "istanbul cover _mocha tests/index.js && if [ \"$CONTINUOUS_INTEGRATION\" = \"true\" ]; then cat ./coverage/lcov.info | ./node_modules/.bin/coveralls; fi",
"test-unmock": "_mocha -b tests/unmock.js",
"test-unmock": "node tests/unmock.js",
"lint": "eslint *.js lib/* tests/*; exit 0",
"docs": "jsdoc -c .jsdoc.json -R README.md",
"deployDocs": "npm run docs && sh ./scripts/deployDocs.sh"
Expand All @@ -30,12 +30,14 @@
},
"devDependencies": {
"chai": "^3.2.0",
"configstore": "^2.0.0",
"coveralls": "^2.11.9",
"dirty-chai": "^1.2.2",
"docdash": "^0.4.0",
"eslint": "^2.8.0",
"eslint-config-airbnb-base": "^3.0.1",
"eslint-plugin-import": "^1.5.0",
"inquirer": "^1.0.3",
"istanbul": "^0.4.2",
"jsdoc": "^3.4.0",
"mocha": "^2.2.5",
Expand Down
2 changes: 1 addition & 1 deletion tests/account/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('account', () => {
.defaultReplyHeaders({
'Content-Type': 'application/json'
})
.matchHeader('Authorization', `Bearer ${data.access_token}`)
.matchHeader('Authorization', `Bearer ${data.account.access_token}`)
.get('/api/accounts')
.reply(200, {
status: 'OPEN_PRIMARY_ACCOUNT',
Expand Down
2 changes: 1 addition & 1 deletion tests/account/addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('addresses', () => {
.defaultReplyHeaders({
'Content-Type': 'application/json'
})
.matchHeader('Authorization', `Bearer ${data.access_token}`)
.matchHeader('Authorization', `Bearer ${data.account.access_token}`)
.get('/api/addresses')
.reply(200, {
paging: {
Expand Down
4 changes: 2 additions & 2 deletions tests/account/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ describe('auth', () => {
password: 'password',
grant_type: 'password'
})
.reply(200, data);
.reply(200, data.account);

api = nock('https://api.tech26.de')
.defaultReplyHeaders({
'Content-Type': 'application/json'
})
.matchHeader('Authorization', `Bearer ${data.access_token}`)
.matchHeader('Authorization', `Bearer ${data.account.access_token}`)
.get('/api/me')
.reply(200, {
email: '[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion tests/account/barzahlen.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('barzahlen', () => {
.defaultReplyHeaders({
'Content-Type': 'application/json'
})
.matchHeader('Authorization', `Bearer ${data.access_token}`)
.matchHeader('Authorization', `Bearer ${data.account.access_token}`)
.get('/api/barzahlen/check')
.reply(200, dataBarzahlen);

Expand Down
Loading

0 comments on commit 7465123

Please sign in to comment.