DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Get A Bible Passage From The Living Stones / Seek-First Web Service With Ruby

06.14.2006
| 3271 views |
  • submit to reddit
        
require 'net/http'

LS_BASE_URL = 'http://www.seek-first.com/Bible.php?q=&passage=Seek'

def lookup_ls(reference, translation) # living stones (KJV, ASV, YLT, AKJV, WEB)
  return if reference.nil? or reference.empty?
  url = LS_BASE_URL + '&p=' + URI.escape(reference) + '&version=' + translation
  result = Net::HTTP.get(URI.parse(url))
  url = /<!\-\-\s*(http:\/\/api\.seek\-first\.com.+?)\s*\-\->/.match(result)[1]
  result = Net::HTTP.get(URI.parse(url)).gsub(/\s+/, ' ').gsub(/“|�/, '"').gsub(/‘|’/, "'").gsub('*', '')
  text = result.scan(/<Text>(.+?)<\/Text>/).map { |p| p[0].strip.gsub(/<.+?>/, '') }.join(' ') rescue nil
  return {:reference => reference, :text => text}
end