-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
34 lines (28 loc) · 946 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'sinatra'
require "sinatra/json"
require "sqlite3"
require "active_record"
set :bind, '0.0.0.0'
set :port, 3000
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'db/KJV-PCE.db'
)
class Bible < ActiveRecord::Base
self.table_name = "Bible"
end
get '/' do
erb :index
end
get '/book/:book/chapter/:chapter' do
book = Bible.find_by(BookAbr: params['book'], Chapter: params['chapter'])
verses = Bible.where(["BookAbr = ?", params['book']])
.where(["Chapter = ?", params['chapter']])
.select("Verse as verse, VText as text")
.all
json :book => book.BookName, :chapter => book.Chapter, :verses => verses
end
get '/book/:book/chapter/:chapter/verse/:verse' do
book = Bible.find_by(BookAbr: params['book'], Chapter: params['chapter'],Verse: params['verse'])
json :book => book.BookName, :chapter => book.Chapter, :verse => book.Verse, :text => book.VText
end