-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2bec0a8
Showing
11 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
# EditorConfig helps developers define and maintain consistent | ||
# coding styles between different editors and IDEs | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
language: node_js | ||
node_js: | ||
- "0.12" | ||
- "4" | ||
- "5" | ||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Leonardo Gatica | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# hubot-bip | ||
|
||
[![npm version](https://img.shields.io/npm/v/hubot-bip.svg?style=flat-square)](https://www.npmjs.com/package/hubot-bip) | ||
[![npm downloads](https://img.shields.io/npm/dm/hubot-bip.svg?style=flat-square)](https://www.npmjs.com/package/hubot-bip) | ||
[![Build Status](https://img.shields.io/travis/lgaticaq/hubot-bip.svg?style=flat-square)](https://travis-ci.org/lgaticaq/hubot-bip) | ||
[![dependency Status](https://img.shields.io/david/lgaticaq/hubot-bip.svg?style=flat-square)](https://david-dm.org/lgaticaq/hubot-bip#info=dependencies) | ||
[![devDependency Status](https://img.shields.io/david/dev/lgaticaq/hubot-bip.svg?style=flat-square)](https://david-dm.org/lgaticaq/hubot-bip#info=devDependencies) | ||
[![Join the chat at https://gitter.im/lgaticaq/hubot-bip](https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg?style=flat-square)](https://gitter.im/lgaticaq/hubot-bip?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
|
||
Hubot script to get balance of bip card (Chile) | ||
|
||
## Install | ||
```bash | ||
npm i -S hubot-bip | ||
``` | ||
|
||
agregar `["hubot-bip"]` en `external-scripts.json`. | ||
|
||
## Example | ||
`hubot bip 111111111` -> `Número: <numero>, Saldo: <saldo>, Fecha: <fecha>, Mensaje: <mensaje>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
fs = require "fs" | ||
path = require "path" | ||
|
||
module.exports = (robot, scripts) -> | ||
scriptsPath = path.resolve(__dirname, "src") | ||
fs.exists scriptsPath, (exists) -> | ||
if exists | ||
for script in fs.readdirSync(scriptsPath) | ||
if scripts? and "*" not in scripts | ||
robot.loadFile(scriptsPath, script) if script in scripts | ||
else | ||
robot.loadFile(scriptsPath, script) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "hubot-bip", | ||
"version": "1.0.0", | ||
"description": "Hubot script to get balance of bip card (Chile)", | ||
"main": "index.coffee", | ||
"scripts": { | ||
"test": "mocha --compilers coffee:coffee-script/register" | ||
}, | ||
"engines": { | ||
"node": ">=0.12" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/lgaticaq/hubot-bip.git" | ||
}, | ||
"keywords": [ | ||
"hubot", | ||
"hubot-scripts", | ||
"bip" | ||
], | ||
"author": "Leonardo Gatica <lgatica@protonmail.com> (https://about.me/lgatica)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/lgaticaq/hubot-bip/issues" | ||
}, | ||
"homepage": "https://github.com/lgaticaq/hubot-bip#readme", | ||
"dependencies": { | ||
"bip": "^1.1.0", | ||
"moment": "^2.11.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.4.1", | ||
"coffee-script": "^1.10.0", | ||
"hubot-test-helper": "^1.3.0", | ||
"mocha": "^2.3.4", | ||
"nock": "^5.2.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Description | ||
# Obtiene el saldo de una tarjeta bip | ||
# | ||
# Dependencies: | ||
# "bip": "^1.1.0" | ||
# | ||
# Commands: | ||
# hubot bip <number> -> Número: <numero>, Saldo: <saldo>, Fecha: <fecha>, Mensaje: <mensaje> | ||
# | ||
# Author: | ||
# lgaticaq | ||
|
||
bip = require("bip") | ||
moment = require("moment") | ||
|
||
module.exports = (robot) -> | ||
robot.respond /bip (\d{8})/i, (res) -> | ||
bip(res.match[1]) | ||
.then (data) -> | ||
msg = "Número: #{data.number}\n" | ||
msg += "Saldo: $#{data.balance}\n" | ||
msg += "Fecha: #{moment(data.date).format("DD/MM/YYYY HH:mm")}\n" if data.date | ||
msg += "Mensaje: #{data.message}" | ||
robot.send {room: res.message.user.name}, msg | ||
.catch (err) -> | ||
res.reply "ocurrio un error al consultar la tarjeta bip" | ||
robot.emit "error", err, res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
path = require("path") | ||
Helper = require("hubot-test-helper") | ||
expect = require("chai").expect | ||
nock = require("nock") | ||
|
||
helper = new Helper("./../src/index.coffee") | ||
|
||
describe "bip", -> | ||
room = null | ||
|
||
beforeEach -> | ||
room = helper.createRoom() | ||
nock.disableNetConnect() | ||
|
||
afterEach -> | ||
room.destroy() | ||
nock.cleanAll() | ||
|
||
context "number valid", -> | ||
number = "11111111" | ||
|
||
beforeEach (done) -> | ||
nock("http://www.metrosantiago.cl") | ||
.get("/contents/guia-viajero/includes/consultarTarjeta/#{number}") | ||
.reply(200, [ | ||
{ | ||
"estado": 0, | ||
"mensaje": "Tarjeta Valida" | ||
}, | ||
{ | ||
"salida": true, | ||
"tarjeta": "11111111", | ||
"saldo": "1180", | ||
"fecha": "02\/01\/2016 20:59" | ||
} | ||
]) | ||
room.user.say("leon", "hubot bip #{number}") | ||
setTimeout(done, 100) | ||
|
||
it "should return a balance data (valid)", -> | ||
expect(room.messages).to.eql([ | ||
["leon", "hubot bip #{number}"], | ||
["hubot", "Número: 11111111\nSaldo: $1180\nFecha: 02/01/2016 20:59\nMensaje: Tarjeta Valida"] | ||
]) | ||
|
||
context "number invalid", -> | ||
number = "11111111" | ||
|
||
beforeEach (done) -> | ||
nock("http://www.metrosantiago.cl") | ||
.get("/contents/guia-viajero/includes/consultarTarjeta/#{number}") | ||
.reply(200, [ | ||
{ | ||
"estado": 1, | ||
"mensaje": "Esta tarjeta no se puede cargar" | ||
}, | ||
{ | ||
"salida": false, | ||
"tarjeta": "11111111" | ||
} | ||
]) | ||
room.user.say("leon", "hubot bip #{number}") | ||
setTimeout(done, 100) | ||
|
||
it "should return a balance data (invalid)", -> | ||
expect(room.messages).to.eql([ | ||
["leon", "hubot bip #{number}"], | ||
["hubot", "Número: 11111111\nSaldo: $0\nMensaje: Esta tarjeta no se puede cargar"] | ||
]) |