Skip to content

Commit

Permalink
chore(src): first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed Aug 29, 2016
0 parents commit 57fdcb2
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
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
27 changes: 27 additions & 0 deletions .gitignore
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
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
coverage
test
LICENSE
.*
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v6
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
node_js:
- "4"
- "5"
- "6"
notifications:
email: false
after_success:
- npm run coveralls
- npm run codeclimate
Empty file added CHANGELOG.md
Empty file.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2016 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.

28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# hubot-m2m-status

[![npm version](https://img.shields.io/npm/v/hubot-m2m-status.svg?style=flat-square)](https://www.npmjs.com/package/hubot-m2m-status)
[![npm downloads](https://img.shields.io/npm/dm/hubot-m2m-status.svg?style=flat-square)](https://www.npmjs.com/package/hubot-m2m-status)
[![Build Status](https://img.shields.io/travis/lgaticaq/hubot-m2m-status.svg?style=flat-square)](https://travis-ci.org/lgaticaq/hubot-m2m-status)
[![Coverage Status](https://img.shields.io/coveralls/lgaticaq/hubot-m2m-status/master.svg?style=flat-square)](https://coveralls.io/github/lgaticaq/hubot-m2m-status?branch=master)
[![Code Climate](https://img.shields.io/codeclimate/github/lgaticaq/hubot-m2m-status.svg?style=flat-square)](https://codeclimate.com/github/lgaticaq/hubot-m2m-status)
[![dependency Status](https://img.shields.io/david/lgaticaq/hubot-m2m-status.svg?style=flat-square)](https://david-dm.org/lgaticaq/hubot-m2m-status#info=dependencies)
[![devDependency Status](https://img.shields.io/david/dev/lgaticaq/hubot-m2m-status.svg?style=flat-square)](https://david-dm.org/lgaticaq/hubot-m2m-status#info=devDependencies)

> A Hubot script to check status of your m2mdataglobal sims
## Installation
```bash
npm i -S hubot-m2m-status
```

Set environment variable *M2M_USER* and *M2M_PASS* to login and get info sim.

add `["hubot-m2m-status"]` to `external-scripts.json`.

## Examples

`hubot m2m check <sim>` -> `Check status of sim`

## License

[MIT](https://tldrlegal.com/license/mit-license)
51 changes: 51 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "hubot-m2m-status",
"version": "0.0.0",
"description": "A Hubot script to check status of your m2mdataglobal sims",
"main": "src",
"scripts": {
"pretest": "coffeelint src test",
"test": "mocha --compilers coffee:coffee-script/register --require coffee-coverage/register-istanbul",
"posttest": "istanbul report text-summary lcov",
"coveralls": "coveralls < coverage/lcov.info",
"codeclimate": "codeclimate-test-reporter < coverage/lcov.info",
"release:major": "changelog -M && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version major && git push origin && git push origin --tags && npm publish",
"release:minor": "changelog -m && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version minor && git push origin && git push origin --tags && npm publish",
"release:patch": "changelog -p && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version patch && git push origin && git push origin --tags && npm publish"
},
"engines": {
"node": ">=4"
},
"repository": {
"type": "git",
"url": "git://github.com/lgaticaq/hubot-m2m-status.git"
},
"keywords": [
"hubot",
"hubot-scripts",
"m2m",
"sim"
],
"author": "Leonardo Gatica <lgatica@protonmail.com> (https://about.me/lgatica)",
"license": "MIT",
"bugs": {
"url": "https://github.com/lgaticaq/hubot-m2m-status/issues"
},
"homepage": "https://github.com/lgaticaq/hubot-m2m-status#readme",
"dependencies": {
"m2m-status": "0.0.2"
},
"devDependencies": {
"chai": "^3.5.0",
"codeclimate-test-reporter": "^0.3.3",
"coffee-coverage": "^1.0.1",
"coffee-script": "^1.10.0",
"coffeelint": "^1.15.7",
"coveralls": "^2.11.12",
"generate-changelog": "^1.0.2",
"hubot-test-helper": "^1.5.0",
"istanbul": "^0.4.5",
"mocha": "^3.0.2",
"proxyquire": "^1.7.10"
}
}
2 changes: 2 additions & 0 deletions src/index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module.exports = (robot) ->
robot.loadFile __dirname, "script.coffee"
33 changes: 33 additions & 0 deletions src/script.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Description
# A Hubot script to check status of your m2m-status sims
#
# Dependencies:
# "simple-encryptor": "0.0.2"
#
# Configuration:
# M2M_USER, M2M_PASS
#
# Commands:
# hubot m2m check <sim> - Check status of sim
#
# Author:
# lgaticaq

m2m = require "m2m-status"

module.exports = (robot) ->
robot.respond /m2m check (\+\d{11})/, (res) ->
sim = res.match[1]
res.send "Checking status..."
client = new m2m({
user: process.env.M2M_USER,
password: process.env.M2M_PASS
})
client.checkStatus(sim).then (result) ->
msg = "Administration: #{if result.admin then 'OK' else 'Error'}\n"
msg += "GSM: #{if result.gsm then 'OK' else 'Error'}\n"
msg += "GPRS: #{if result.gprs then 'OK' else 'Error'}"
res.send(msg)
.catch (err) ->
res.send "Error: #{err.message}"
robot.emit "error", err
72 changes: 72 additions & 0 deletions test/test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
Helper = require("hubot-test-helper")
expect = require("chai").expect
proxyquire = require("proxyquire")

process.env.M2M_USER = "user"
process.env.M2M_PASS = "password"

class M2m
constructor: ->
checkStatus: (sim) ->
return new Promise (resolve, reject) ->
if sim is "+56999999999"
resolve({admin: true, gsm: true, gprs: true})
else if sim is "+56888888888"
resolve({admin: false, gsm: false, gprs: false})
else
reject(new Error("Sim #{sim} not found or not active"))

proxyquire("./../src/script.coffee", {"m2m-status": M2m})

helper = new Helper("./../src/index.coffee")

describe "hubot-m2m-status", ->
room = null

beforeEach ->
room = helper.createRoom({name: "user"})

afterEach ->
room.destroy()

context "invalid", ->
beforeEach (done) ->
room.user.say("user", "hubot m2m check +56111111111")
setTimeout(done, 100)

it "should get a error", ->
expect(room.messages).to.eql([
["user", "hubot m2m check +56111111111"]
["hubot", "Checking status..."]
["hubot", "Error: Sim +56111111111 not found or not active"]
])

context "valid data false", ->
beforeEach (done) ->
room.user.say("user", "hubot m2m check +56888888888")
setTimeout(done, 100)

it "should get a sim status", ->
message = "Administration: Error\n"
message += "GSM: Error\n"
message += "GPRS: Error"
expect(room.messages).to.eql([
["user", "hubot m2m check +56888888888"]
["hubot", "Checking status..."]
["hubot", message]
])

context "valid data true", ->
beforeEach (done) ->
room.user.say("user", "hubot m2m check +56999999999")
setTimeout(done, 100)

it "should get a sim status", ->
message = "Administration: OK\n"
message += "GSM: OK\n"
message += "GPRS: OK"
expect(room.messages).to.eql([
["user", "hubot m2m check +56999999999"]
["hubot", "Checking status..."]
["hubot", message]
])

0 comments on commit 57fdcb2

Please sign in to comment.