Never been to DZone Snippets before?

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

Get a bible passage from the Living Stones / Seek-First Web Service with Ruby (See related posts)

   1  
   2  require 'net/http'
   3  
   4  LS_BASE_URL = 'http://www.seek-first.com/Bible.php?q=&passage=Seek'
   5  
   6  def lookup_ls(reference, translation) # living stones (KJV, ASV, YLT, AKJV, WEB)
   7    return if reference.nil? or reference.empty?
   8    url = LS_BASE_URL + '&p=' + URI.escape(reference) + '&version=' + translation
   9    result = Net::HTTP.get(URI.parse(url))
  10    url = /<!\-\-\s*(http:\/\/api\.seek\-first\.com.+?)\s*\-\->/.match(result)[1]
  11    result = Net::HTTP.get(URI.parse(url)).gsub(/\s+/, ' ').gsub(/“|�/, '"').gsub(/‘|’/, "'").gsub('*', '')
  12    text = result.scan(/<Text>(.+?)<\/Text>/).map { |p| p[0].strip.gsub(/<.+?>/, '') }.join(' ') rescue nil
  13    return {:reference => reference, :text => text}
  14  end

You need to create an account or log in to post comments to this site.


Click here to browse all 5545 code snippets

Related Posts