Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit edca7cf
Showing
7 changed files
with
66,253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bible_api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ruby-2.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'sinatra' | ||
gem 'sequel' | ||
gem 'mysql2' | ||
gem 'usfx' | ||
gem 'bible_ref' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
bible_ref (0.1.0) | ||
parslet (~> 1.6) | ||
blankslate (2.1.2.4) | ||
mini_portile (0.6.0) | ||
mysql2 (0.3.16) | ||
nokogiri (1.6.2.1) | ||
mini_portile (= 0.6.0) | ||
parslet (1.6.1) | ||
blankslate (~> 2.0) | ||
rack (1.5.2) | ||
rack-protection (1.5.3) | ||
rack | ||
sequel (4.12.0) | ||
sinatra (1.4.5) | ||
rack (~> 1.4) | ||
rack-protection (~> 1.4) | ||
tilt (~> 1.3, >= 1.3.4) | ||
tilt (1.4.1) | ||
usfx (0.1.3) | ||
nokogiri (>= 1.6.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
bible_ref | ||
mysql2 | ||
sequel | ||
sinatra | ||
usfx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'bundler' | ||
require 'json' | ||
|
||
Bundler.require | ||
|
||
DB = Sequel.connect(ENV['BIBLE_API_DB']) | ||
|
||
def get_verse_id(ref) | ||
DB[ | ||
'select id from verses where book_id = ? and chapter = ? and verse = ?', | ||
ref[:book], | ||
ref[:chapter], | ||
ref[:verse] | ||
].first[:id] | ||
end | ||
|
||
def get_verses(ranges) | ||
all = [] | ||
ranges.each do |(ref_from, ref_to)| | ||
start_id = get_verse_id(ref_from) | ||
stop_id = get_verse_id(ref_to) | ||
all += DB['select * from verses where id between ? and ?', start_id, stop_id].to_a | ||
end | ||
all | ||
end | ||
|
||
get '/:ref' do | ||
ref = params[:ref].gsub(/\+/, ' ') | ||
if ranges = BibleRef::Reference.new(ref).ranges | ||
verses = get_verses(ranges).map do |v| | ||
{ | ||
book_id: v[:book_id], | ||
book_name: v[:book], | ||
chapter: v[:chapter], | ||
verse: v[:verse], | ||
text: v[:text] | ||
} | ||
end | ||
{ | ||
reference: ref, | ||
verses: verses, | ||
text: verses.map { |v| v[:text] }.join | ||
}.to_json | ||
else | ||
status 404 | ||
{ error: 'not found' }.to_json | ||
end | ||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'bundler' | ||
require 'sequel' | ||
require 'mysql2' | ||
require 'usfx' | ||
|
||
class Seed | ||
DB = Sequel.connect(ENV['BIBLE_API_DB']) | ||
|
||
class VerseDocument < USFX::Document | ||
def verse(data) | ||
data[:book].strip! | ||
print "#{data[:book]} #{data[:chapter]}:#{data[:verse]} \r" | ||
DB[:verses].insert(data) | ||
end | ||
end | ||
|
||
def import | ||
DB.create_table :verses do | ||
primary_key :id | ||
Fixnum :book_num | ||
String :book_id | ||
String :book | ||
Fixnum :chapter | ||
Fixnum :verse | ||
String :text | ||
end | ||
|
||
if DB[:verses].count > 0 | ||
puts 'data already present' | ||
exit(1) | ||
end | ||
|
||
parser = USFX::Parser.new(VerseDocument.new) | ||
parser.parse(File.open('eng-web_usfx.xml')) | ||
end | ||
end | ||
|
||
Seed.new.import |