Comparing version 0.1.0 to 0.1.1
@@ -10,5 +10,2 @@ // require library | ||
// enable debug; | ||
tuc.setDebug(false); | ||
// call method getBalance | ||
@@ -15,0 +12,0 @@ tuc.getBalance(number, (balance) => { |
@@ -10,5 +10,2 @@ // require library | ||
// enable debug; | ||
tuc.setDebug(false); | ||
// call method getType | ||
@@ -15,0 +12,0 @@ tuc.getType(number, (balance) => { |
'use strict'; | ||
const debug = require('debug')('tuc'); | ||
const randomstring = require('randomstring'); | ||
@@ -6,6 +7,12 @@ const request = require('request'); | ||
const INVALID_FORMAT = 100; | ||
const HTTP_REQUEST_ERROR = 101; | ||
const EMPTY_RESPONSE = 102; | ||
const INVALID_RESPONSE = 103; | ||
const INACTIVE = 104; | ||
let captcha = randomstring.generate({ | ||
length: 6, | ||
charset: '123456789', | ||
});; | ||
}); | ||
@@ -23,18 +30,9 @@ /** | ||
/** | ||
* Enable or disable show debug | ||
* @debug {boolean} | ||
*/ | ||
setDebug(debug) { | ||
if (typeof debug === 'boolean') { | ||
this.debug = debug; | ||
} | ||
} | ||
/** | ||
* Create a object error | ||
*/ | ||
error(message) { | ||
error(message, code) { | ||
let error = { | ||
error: { | ||
message: message, | ||
code: code, | ||
}, | ||
@@ -68,11 +66,5 @@ }; | ||
callback( | ||
_this.error('El formato no es correcto. El formato correcto es 00000000.') | ||
_this.error('El formato no es correcto. El formato correcto es 00000000.', INVALID_FORMAT) | ||
); | ||
} else { | ||
// init request settings | ||
request.defaults({ | ||
strictSSL: false, // allow us to use our _this-signed cert for testing | ||
rejectUnauthorized: false, | ||
}); | ||
let options = { | ||
@@ -88,9 +80,8 @@ url: _this.url, | ||
request.post(options, (error, response, body) => { | ||
if (_this.debug) { | ||
console.log(body); | ||
} | ||
debug('Status Code: %d', response.statusCode); | ||
debug(body); | ||
if (error) { | ||
callback( | ||
_this.error(error) | ||
_this.error(error, HTTP_REQUEST_ERROR) | ||
); | ||
@@ -102,4 +93,5 @@ } else { | ||
} catch (e) { | ||
console.log(e.message); | ||
callback( | ||
_this.error('El sitio www.mpeso.net está presentando problemas en la consulta del saldo.') | ||
_this.error('El sitio www.mpeso.net está presentando problemas en la consulta del saldo.', EMPTY_RESPONSE) | ||
); | ||
@@ -109,3 +101,3 @@ } | ||
callback( | ||
_this.error('Error al intentar conectarse con el sitio www.mpeso.net') | ||
_this.error('Error al intentar conectarse con el sitio www.mpeso.net', INVALID_RESPONSE) | ||
); | ||
@@ -133,2 +125,5 @@ } | ||
getBalance(number, callback) { | ||
debug('Method: Balance'); | ||
debug('Card: %s', number); | ||
// set context on _this | ||
@@ -157,3 +152,3 @@ let _this = this; | ||
callback( | ||
_this.error(`${form._terminal} está inactivo`) | ||
_this.error(`${form._terminal} está inactivo`, INACTIVE) | ||
); | ||
@@ -164,3 +159,3 @@ } | ||
callback( | ||
_this.error('Respuesta inválida del servidor') | ||
_this.error('Respuesta inválida del servidor', INVALID_RESPONSE) | ||
); | ||
@@ -177,2 +172,5 @@ } | ||
getType(number, callback) { | ||
debug('Method: Type'); | ||
debug('Card: %s', number); | ||
// set context on _this | ||
@@ -204,3 +202,3 @@ let _this = this; | ||
callback( | ||
_this.error(`${form._terminal} está inactivo`) | ||
_this.error(`${form._terminal} está inactivo`, INACTIVE) | ||
); | ||
@@ -207,0 +205,0 @@ } |
{ | ||
"name": "tuc", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "TUC Client for Node.js", | ||
"author": "Paulo McNally <paulomcnally@gmail.com>", | ||
"scripts": { | ||
"test": "node_modules/mocha/bin/mocha" | ||
}, | ||
"contributors": [ | ||
@@ -14,2 +17,6 @@ { | ||
"email": "om.cortez.2010@gmail.com" | ||
}, | ||
{ | ||
"name": "Bruce Lampson", | ||
"email": "brucelampson@gmail.com" | ||
} | ||
@@ -27,5 +34,6 @@ ], | ||
"dependencies": { | ||
"debug": "2.2.0", | ||
"randomstring": "1.1.5", | ||
"request": "~2.34.0", | ||
"string": "~1.8.0" | ||
"request": "~2.72.0", | ||
"string": "~3.3.1" | ||
}, | ||
@@ -39,3 +47,7 @@ "bugs": { | ||
"url": "git://github.com/nodenica/node-tuc.git" | ||
}, | ||
"devDependencies": { | ||
"is_js": "0.8.0", | ||
"mocha": "2.5.3" | ||
} | ||
} |
@@ -13,16 +13,19 @@ # TUC | ||
var Tuc = require('tuc'); | ||
// require library | ||
const Tuc = require('tuc'); | ||
var tuc = new Tuc(); | ||
// instance class | ||
const tuc = new Tuc(); | ||
tuc.getBalance('00759795', function( balance ){ | ||
// set number | ||
let number = '00758888'; | ||
console.log( balance ); | ||
// call method getBalance | ||
tuc.getBalance(number, (balance) => { | ||
console.log(balance); | ||
}); | ||
tuc.getType('00759795', function( type ){ | ||
console.log( type ); | ||
// call method getType | ||
tuc.getType(number, (balance) => { | ||
console.log(balance); | ||
}); | ||
@@ -40,3 +43,4 @@ | ||
* [robe007](https://github.com/robe007) | ||
* [oscarmcm](https://github.com/oscarmcm) | ||
This is a unoficial client. For more info visit [https://mpeso.net/](https://mpeso.net/) |
19523
10
250
45
4
2
+ Addeddebug@2.2.0
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@0.2.01.0.0(transitive)
+ Addedasync@2.6.4(transitive)
+ Addedaws-sign2@0.6.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbl@1.1.2(transitive)
+ Addedboom@2.10.1(transitive)
+ Addedcaseless@0.11.0(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedcore-util-is@1.0.21.0.3(transitive)
+ Addedcryptiles@2.0.5(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddebug@2.2.0(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@1.0.1(transitive)
+ Addedgenerate-function@2.3.1(transitive)
+ Addedgenerate-object-property@1.2.0(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-validator@2.0.6(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhawk@3.1.3(transitive)
+ Addedhoek@2.16.3(transitive)
+ Addedhttp-signature@1.1.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-my-ip-valid@1.0.1(transitive)
+ Addedis-my-json-valid@2.20.6(transitive)
+ Addedis-property@1.0.2(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjsonpointer@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@0.7.1(transitive)
+ Addedoauth-sign@0.8.2(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedprocess-nextick-args@1.0.7(transitive)
+ Addedqs@6.1.2(transitive)
+ Addedreadable-stream@2.0.6(transitive)
+ Addedrequest@2.72.0(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsntp@1.0.9(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstring@3.3.3(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedstringstream@0.0.6(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedtough-cookie@2.2.2(transitive)
+ Addedtunnel-agent@0.4.3(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedasn1@0.1.11(transitive)
- Removedassert-plus@0.1.5(transitive)
- Removedasync@0.9.2(transitive)
- Removedaws-sign2@0.5.0(transitive)
- Removedboom@0.4.2(transitive)
- Removedcombined-stream@0.0.7(transitive)
- Removedcryptiles@0.2.2(transitive)
- Removedctype@0.5.3(transitive)
- Removeddelayed-stream@0.0.5(transitive)
- Removedforever-agent@0.5.2(transitive)
- Removedform-data@0.1.4(transitive)
- Removedhawk@1.0.0(transitive)
- Removedhoek@0.9.1(transitive)
- Removedhttp-signature@0.10.1(transitive)
- Removedmime@1.2.11(transitive)
- Removedoauth-sign@0.3.0(transitive)
- Removedqs@0.6.6(transitive)
- Removedrequest@2.34.0(transitive)
- Removedsntp@0.2.4(transitive)
- Removedstring@1.8.1(transitive)
- Removedtldts@6.1.77(transitive)
- Removedtldts-core@6.1.77(transitive)
- Removedtough-cookie@5.1.1(transitive)
- Removedtunnel-agent@0.3.0(transitive)
Updatedrequest@~2.72.0
Updatedstring@~3.3.1