├── .gitignore ├── README.md ├── index.coffee ├── package.json ├── script ├── bootstrap └── test ├── src └── http-status.coffee └── test └── http-status_test.coffee /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | *.tgz 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Hubot HTTP Status/Error Script 2 | ============================= 3 | [![NPM version](https://badge.fury.io/js/hubot-http-status.svg)](http://badge.fury.io/js/hubot-http-status) 4 | 5 | Hubot script that pulls the `` definition and link from [Wikipedia](http://en.wikipedia.org/wiki/List_of_HTTP_status_codes "Status Codes"). Helpful if you get a strange code that you don't remember or if you are crafting an API and want to use specific HTTP codes. 6 | 7 | Usage 8 | ----- 9 | `hubot http status ` 10 | -------------------------------------------------------------------------------- /index.coffee: -------------------------------------------------------------------------------- 1 | fs = require 'fs' 2 | path = require 'path' 3 | 4 | module.exports = (robot, scripts) -> 5 | scriptsPath = path.resolve(__dirname, 'src') 6 | fs.exists scriptsPath, (exists) -> 7 | if exists 8 | for script in fs.readdirSync(scriptsPath) 9 | if scripts? and '*' not in scripts 10 | robot.loadFile(scriptsPath, script) if script in scripts 11 | else 12 | robot.loadFile(scriptsPath, script) 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hubot-http-status", 3 | "version": "0.2.2", 4 | "description": "Returns HTTP status/error code definitions from wikipedia.", 5 | "main": "index.coffee", 6 | "scripts": { 7 | "test": "script/test" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/hubot-scripts/hubot-http-status" 12 | }, 13 | "keywords": [ 14 | "hubot", 15 | "wikipedia", 16 | "api", 17 | "http", 18 | "error" 19 | ], 20 | "author": "Drew Delianides", 21 | "license": "MIT", 22 | "dependencies": { 23 | "coffee-script": "~1.6", 24 | "cheerio": "~0.19.0" 25 | }, 26 | "devDependencies": { 27 | "mocha": "*", 28 | "chai": "*", 29 | "sinon-chai": "*", 30 | "sinon": "*" 31 | }, 32 | "bugs": { 33 | "url": "https://github.com/hubot-scripts/hubot-http-status/issues" 34 | }, 35 | "homepage": "https://github.com/hubot-scripts/hubot-http-status" 36 | } 37 | -------------------------------------------------------------------------------- /script/bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Make sure everything is development forever 4 | export NODE_ENV=development 5 | 6 | # Load environment specific environment variables 7 | if [ -f .env ]; then 8 | source .env 9 | fi 10 | 11 | if [ -f .env.${NODE_ENV} ]; then 12 | source .env.${NODE_ENV} 13 | fi 14 | 15 | npm install 16 | 17 | # Make sure coffee and mocha are on the path 18 | export PATH="node_modules/.bin:$PATH" 19 | -------------------------------------------------------------------------------- /script/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # bootstrap environment 4 | source script/bootstrap 5 | 6 | mocha --compilers coffee:coffee-script 7 | -------------------------------------------------------------------------------- /src/http-status.coffee: -------------------------------------------------------------------------------- 1 | # Description: 2 | # Displays the description for the requested error code. 3 | # 4 | # Dependencies: 5 | # "cheerio": "~0.16.0" 6 | # 7 | # Configuration: 8 | # None 9 | # 10 | # Commands: 11 | # hubot http status 12 | # 13 | # Author: 14 | # delianides 15 | # 16 | 17 | cheerio = require 'cheerio' 18 | 19 | module.exports = (robot) -> 20 | robot.respond /http(s?) status (.*)/i, (msg) -> 21 | httpCode = msg.match[2] 22 | msg 23 | .http('https://en.wikipedia.org/wiki/List_of_HTTP_status_codes') 24 | .get() (err, res, body) -> 25 | $ = cheerio.load(body) 26 | statusCode = $('#'+httpCode).parent().text() 27 | if statusCode 28 | msg.send statusCode 29 | msg.send "http://en.wikipedia.org/wiki/List_of_HTTP_status_codes##{httpCode}" 30 | else 31 | msg.send "HTTP status code '#{httpCode}' doesn't exist. Ironically, this would be HTTP Error 404." 32 | -------------------------------------------------------------------------------- /test/http-status_test.coffee: -------------------------------------------------------------------------------- 1 | chai = require 'chai' 2 | sinon = require 'sinon' 3 | chai.use require 'sinon-chai' 4 | 5 | expect = chai.expect 6 | 7 | describe 'http-status', -> 8 | http_status_module = require "../src/http-status" 9 | 10 | beforeEach -> 11 | @robot = 12 | respond: sinon.spy() 13 | hear: sinon.spy() 14 | @msg = 15 | send: sinon.spy() 16 | @http_status = http_status_module(@robot) 17 | 18 | it 'responds to http status code', -> 19 | expect(@robot.respond).to.have.been.calledWith(/http status (.*)/i) 20 | 21 | it 'responds to https status code', -> 22 | expect(@robot.respond).to.have.been.calledWith(/https status (.*)/i) 23 | --------------------------------------------------------------------------------