Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vwbusguy committed Feb 22, 2019
0 parents commit b6e9e8c
Show file tree
Hide file tree
Showing 11 changed files with 231 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: node_js
node_js:
- "0.12"
- "0.10"
- "iojs"
sudo: false
cache:
directories:
- node_modules
notifications:
email: false
33 changes: 33 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -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']);
};
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions index.coffee
Original file line number Diff line number Diff line change
@@ -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)
47 changes: 47 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"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"
}
}
18 changes: 18 additions & 0 deletions script/bootstrap
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 6 additions & 0 deletions script/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# bootstrap environment
source script/bootstrap

mocha --compilers coffee:coffee-script
35 changes: 35 additions & 0 deletions src/esv.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Description:
# Simple ESV passage lookup based on esv-api.org
#
# Commands:
# hubot esv <passage>
#
# 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 <[email protected]>

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
27 changes: 27 additions & 0 deletions test/esv-test.coffee
Original file line number Diff line number Diff line change
@@ -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']
]

0 comments on commit b6e9e8c

Please sign in to comment.