diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5760be5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..07e6e47 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/node_modules diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8e2ea8f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: node_js +node_js: + - "0.12" + - "0.10" + - "iojs" +sudo: false +cache: + directories: + - node_modules +notifications: + email: false diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..30deb8a --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,33 @@ +'use strict'; + +module.exports = function (grunt) { + + grunt.initConfig({ + mochaTest: { + test: { + options: { + reporter: 'spec', + require: 'coffee-script' + }, + src: ['test/**/*.coffee'] + } + }, + release: { + options: { + tagName: 'v<%= version %>', + commitMessage: 'Prepared to release <%= version %>.' + } + }, + watch: { + files: ['Gruntfile.js', 'src/**/*.coffee', 'test/**/*.coffee'], + tasks: ['test'] + } + }); + + // load all grunt tasks + require('matchdep').filterDev(['grunt-*', '!grunt-cli']).forEach(grunt.loadNpmTasks); + + grunt.registerTask('test', ['mochaTest']); + grunt.registerTask('test:watch', ['watch']); + grunt.registerTask('default', ['test']); +}; diff --git a/README.md b/README.md new file mode 100644 index 0000000..70f3864 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# hubot-esv + +Simple ESV passage lookup based on api.esv.org. + +See [`src/esv.coffee`](src/esv.coffee) for full documentation. + +## Installation + +In hubot project repo, run: + +`npm install hubot-esv --save` + +Then add **hubot-esv** to your `external-scripts.json`: + +```json +[ + "hubot-esv" +] +``` + +## Sample Interaction + +``` +user1>> hubot hello +hubot>> hello! +``` + +## NPM Module + +https://www.npmjs.com/package/hubot-esv diff --git a/index.coffee b/index.coffee new file mode 100644 index 0000000..41c1e13 --- /dev/null +++ b/index.coffee @@ -0,0 +1,11 @@ +fs = require 'fs' +path = require 'path' + +module.exports = (robot, scripts) -> + scriptsPath = path.resolve(__dirname, 'src') + if fs.existsSync scriptsPath + for script in fs.readdirSync(scriptsPath).sort() + if scripts? and '*' not in scripts + robot.loadFile(scriptsPath, script) if script in scripts + else + robot.loadFile(scriptsPath, script) diff --git a/package.json b/package.json new file mode 100644 index 0000000..bc2ce94 --- /dev/null +++ b/package.json @@ -0,0 +1,47 @@ +{ + "name": "hubot-esv", + "description": "Simple ESV passage lookup based on api.esv.org", + "version": "0.0.1", + "author": "Scott A. Williams ", + "license": "MIT", + + "keywords": "hubot, hubot-scripts, bible, esv", + + "repository": { + "type": "git", + "url": "git://github.com/hubot-scripts/hubot-esv.git" + }, + + "bugs": { + "url": "https://github.com/hubot-scripts/hubot-esv/issues" + }, + + "dependencies": { + }, + + "peerDependencies": { + "hubot": "2.x" + }, + + "devDependencies": { + "hubot-test-helper": "^1.3.0", + "chai": "^2.1.1", + "coffee-script": "1.6.3", + "grunt": "^0.4.5", + "grunt-cli": "^0.1.13", + "grunt-contrib-watch": "~0.6.1", + "grunt-mocha-test": "~0.12.7", + "grunt-release": "~0.11.0", + "hubot": "2.x", + "matchdep": "~0.3.0", + "mocha": "^2.1.0", + "sinon": "^1.13.0", + "sinon-chai": "^2.7.0" + }, + + "main": "index.coffee", + + "scripts": { + "test": "grunt test" + } +} diff --git a/script/bootstrap b/script/bootstrap new file mode 100755 index 0000000..4c5c66e --- /dev/null +++ b/script/bootstrap @@ -0,0 +1,18 @@ +#!/bin/bash + +# Make sure everything is development forever +export NODE_ENV=development + +# Load environment specific environment variables +if [ -f .env ]; then + source .env +fi + +if [ -f .env.${NODE_ENV} ]; then + source .env.${NODE_ENV} +fi + +npm install + +# Make sure coffee and mocha are on the path +export PATH="node_modules/.bin:$PATH" \ No newline at end of file diff --git a/script/test b/script/test new file mode 100755 index 0000000..e142362 --- /dev/null +++ b/script/test @@ -0,0 +1,6 @@ +#!/bin/bash + +# bootstrap environment +source script/bootstrap + +mocha --compilers coffee:coffee-script \ No newline at end of file diff --git a/src/esv.coffee b/src/esv.coffee new file mode 100644 index 0000000..fc28f61 --- /dev/null +++ b/src/esv.coffee @@ -0,0 +1,35 @@ +# Description: +# Simple ESV passage lookup based on esv-api.org +# +# Commands: +# hubot esv +# +# Configuration: +# HUBOT_ESV_API_KEY (Authorization token header value without "Token") +# +# Notes: +# An API key from api.esv.org is required. +# Obtain one from https://api.esv.org/account/create-application/ +# See https://api.esv.org/docs/passage-text/#required-parameters for syntax +# +# Author: +# Scott A. Williams + +module.exports = (robot) -> + robot.respond /esv\s+(.*)/i, (msg) -> + if not msg.match[1] + msg.send "Please provide a Bible passage for lookup" + return + else + passage = msg.match[1] + url = "https://api.esv.org/v3/passage/text/?q=" + passage + "&output-format=plain-text&include-footnotes=false&include-passage-horizontal-lines=false&include-heading-horizontal-lines=false&include-headings=false&include-subheadings=false&include-footnotes=false" + robot.http(url) + .header("Authorization","Token #{process.env.HUBOT_ESV_API_KEY}") + .get() (err, res, body) -> + if err + msg.send "We have a problem: #{err}" + return + else + data = JSON.parse body + msg.send passage for passage in data.passages + return diff --git a/test/esv-test.coffee b/test/esv-test.coffee new file mode 100644 index 0000000..1ca6106 --- /dev/null +++ b/test/esv-test.coffee @@ -0,0 +1,27 @@ +Helper = require('hubot-test-helper') +chai = require 'chai' + +expect = chai.expect + +helper = new Helper('../src/esv.coffee') + +describe 'esv', -> + beforeEach -> + @room = helper.createRoom() + + afterEach -> + @room.destroy() + + it 'responds to hello', -> + @room.user.say('alice', '@hubot hello').then => + expect(@room.messages).to.eql [ + ['alice', '@hubot hello'] + ['hubot', '@alice hello!'] + ] + + it 'hears orly', -> + @room.user.say('bob', 'just wanted to say orly').then => + expect(@room.messages).to.eql [ + ['bob', 'just wanted to say orly'] + ['hubot', 'yarly'] + ]