esvbible 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ === 0.0.1 / 2008-08-05
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/esv_bible
6
+ lib/esv_bible.rb
7
+ spec/esv_bible_spec.rb
@@ -0,0 +1,55 @@
1
+ = EsvBible
2
+
3
+ * Wrapper for English Standard Version (ESV) Bible Web Service
4
+
5
+ == DESCRIPTION:
6
+
7
+ See ESV API docs http://www.esvapi.org/
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ bible = EsvBible.new('YOUR API KEY HERE')
16
+
17
+ verse = bible.verse 'Gen 1:1'
18
+ passage = bible.passage 'Gen 1'
19
+
20
+ verse = bible.verse 'John 1:1', {:output_format => :text, :include_headings => false}
21
+
22
+ == REQUIREMENTS:
23
+
24
+ * rspec - for testing
25
+
26
+ == INSTALL:
27
+
28
+ * sudo gem install esv_bible
29
+
30
+ source is hosted at https://github.com/gdagley/esv_bible
31
+
32
+ == LICENSE:
33
+
34
+ The MIT License
35
+
36
+ Copyright (c) 2008 Geoffrey Dagley
37
+
38
+ Permission is hereby granted, free of charge, to any person obtaining
39
+ a copy of this software and associated documentation files (the
40
+ 'Software'), to deal in the Software without restriction, including
41
+ without limitation the rights to use, copy, modify, merge, publish,
42
+ distribute, sublicense, and/or sell copies of the Software, and to
43
+ permit persons to whom the Software is furnished to do so, subject to
44
+ the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be
47
+ included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
50
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
52
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
53
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
54
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
55
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+ require 'spec/version'
4
+ require 'spec/rake/spectask'
5
+ require './lib/esv_bible'
6
+
7
+ Hoe.new('esvbible', EsvBible::VERSION) do |p|
8
+ p.rubyforge_name = 'esvbible' # if different than lowercase project name
9
+ p.remote_rdoc_dir = ""
10
+ p.developer('Geoffrey Dagley', 'gdagley@gmail.com')
11
+ end
12
+
13
+ task :default => :spec
14
+
15
+ desc "Run all specs"
16
+ Spec::Rake::SpecTask.new do |t|
17
+ t.spec_files = FileList['spec/**/*_spec.rb']
18
+ t.spec_opts = ['--options', 'spec/spec.opts']
19
+ unless ENV['NO_RCOV']
20
+ t.rcov = true
21
+ t.rcov_dir = 'coverage'
22
+ t.rcov_opts = ['--exclude', 'lib/spec.rb,lib/spec/runner.rb,spec\/spec,bin\/spec,examples,\/var\/lib\/gems,\/Library\/Ruby,\.autotest']
23
+ end
24
+ end
File without changes
@@ -0,0 +1,102 @@
1
+ require 'net/http'
2
+
3
+ class EsvBibleError < StandardError; end
4
+
5
+ class EsvBible
6
+ VERSION = '0.0.1'
7
+ BASE_URL = 'http://www.esvapi.org/v2/rest'
8
+ VALID_FORMATS = [:plain_text, :html, :xml]
9
+ VALID_HTML_OPTIONS = [:include_passage_references, :include_first_verse_numbers,
10
+ :include_verse_numbers, :include_headings, :include_subheadings, :include_footnotes, :include_footnote_links,
11
+ :include_surrounding_chapters, :include_word_ids, :include_audio_link, :audio_format, :audio_version,
12
+ :include_copyright, :include_short_copyright]
13
+ VALID_TEXT_OPTIONS = [:include_passage_references, :include_first_verse_numbers,
14
+ :include_verse_numbers, :include_headings, :include_subheadings, :include_selahs,
15
+ :include_passage_horizontal_lines, :include_heading_horizontal_lines, :include_footnotes,
16
+ :include_copyright, :include_short_copyright, :include_content_type, :line_length]
17
+ VALID_XML_OPTIONS = []
18
+
19
+ attr_accessor :key
20
+
21
+ class << self
22
+ def formats
23
+ VALID_FORMATS
24
+ end
25
+
26
+ def html_options
27
+ VALID_HTML_OPTIONS
28
+ end
29
+
30
+ def text_options
31
+ VALID_TEXT_OPTIONS
32
+ end
33
+
34
+ def xml_options
35
+ VALID_XML_OPTIONS
36
+ end
37
+ end
38
+
39
+ def initialize(key = 'IP')
40
+ @key = key
41
+ end
42
+
43
+ def passage(passage, options = {})
44
+ cleanse! options
45
+ url = build_url("passageQuery", options.merge(:passage => passage))
46
+ open_bible(url)
47
+ end
48
+
49
+ def verse(verse, options = {})
50
+ cleanse! options
51
+ url = build_url("verse", options.merge(:passage => verse))
52
+ open_bible(url)
53
+ end
54
+
55
+ def search(query, options = {})
56
+ cleanse! options
57
+ url = build_url("query", options.merge(:q => query))
58
+ open_bible(url)
59
+ end
60
+
61
+ def build_url(action, options = {})
62
+ url = "#{BASE_URL}/#{action}?"
63
+ options.each_pair do |key, value|
64
+ param = convert_to_param(key)
65
+ url << "#{param}=#{value}&"
66
+ end
67
+ url << "key=#{self.key}"
68
+ end
69
+
70
+ def open_bible(url, limit = 10)
71
+ raise EsvBibleError, 'HTTP redirect too deep' if limit == 0
72
+
73
+ url = URI.escape(url)
74
+
75
+ response = Net::HTTP.get_response(URI.parse(url))
76
+ case response
77
+ when Net::HTTPSuccess
78
+ response.body
79
+ when Net::HTTPRedirection
80
+ open_passage(response['location'], limit - 1)
81
+ else
82
+ raise "#{rsp.code} #{rsp.message}"
83
+ end
84
+ end
85
+
86
+ def cleanse! options
87
+ format = options[:output_format] || :html
88
+ raise EsvBibleError unless VALID_FORMATS.include?(format)
89
+
90
+ valid_format_attributes = case format
91
+ when :html then VALID_HTML_OPTIONS
92
+ when :plain_text then VALID_TEXT_OPTIONS
93
+ when :xml then VALID_XML_OPTIONS
94
+ end
95
+ options.reject! { |key, value| !valid_format_attributes.include?(key) }
96
+ end
97
+
98
+ def convert_to_param(symbol)
99
+ symbol.to_s.gsub('_', '-')
100
+ end
101
+
102
+ end
@@ -0,0 +1,74 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require File.dirname(__FILE__) + '/../lib/esv_bible'
4
+
5
+ describe 'Initializing and configuring ESV API' do
6
+ it "should default to 'IP' key" do
7
+ bible = EsvBible.new
8
+ bible.key.should == 'IP'
9
+ end
10
+
11
+ it "should allow setting a key" do
12
+ bible = EsvBible.new('TEST')
13
+ bible.key.should == 'TEST'
14
+ end
15
+ end
16
+
17
+ describe 'Showing a passage' do
18
+ before(:each) do
19
+ @bible = EsvBible.new('TEST')
20
+ end
21
+
22
+ it "should retrieve a passage" do
23
+ @bible.should_receive(:open_bible).with("http://www.esvapi.org/v2/rest/passageQuery?passage=Gen 1&key=TEST")
24
+ @bible.passage 'Gen 1'
25
+ end
26
+ end
27
+
28
+ describe 'Showing a verse' do
29
+ before(:each) do
30
+ @bible = EsvBible.new('TEST')
31
+ end
32
+
33
+ it "should retrieve a verse" do
34
+ @bible.should_receive(:open_bible).with("http://www.esvapi.org/v2/rest/verse?passage=Gen 1:1&key=TEST")
35
+ @bible.verse 'Gen 1:1'
36
+ end
37
+ end
38
+
39
+ describe 'Searching' do
40
+ before(:each) do
41
+ @bible = EsvBible.new('TEST')
42
+ end
43
+
44
+ it "search for a phrase" do
45
+ @bible.should_receive(:open_bible).with("http://www.esvapi.org/v2/rest/query?q=Some phrase&key=TEST")
46
+ @bible.search 'Some phrase'
47
+ end
48
+ end
49
+
50
+ describe "The inner workings of the library" do
51
+ before(:each) do
52
+ @bible = EsvBible.new('TEST')
53
+ end
54
+
55
+ it "should convert symbols to strings for params" do
56
+ @bible.convert_to_param(:symbol).should == 'symbol'
57
+ end
58
+
59
+ it "should convert symbol underscores to hyphens" do
60
+ @bible.convert_to_param(:symbol_with_underscore).should == 'symbol-with-underscore'
61
+ end
62
+
63
+ it "should build the url for action" do
64
+ @bible.build_url(:action).should include("http://www.esvapi.org/v2/rest/action?key=TEST")
65
+ end
66
+
67
+ it "should build the url for action and param" do
68
+ @bible.build_url(:action, :q => 'value').should include("http://www.esvapi.org/v2/rest/action?q=value&key=TEST")
69
+ end
70
+
71
+ it "should build the url for action and multiple params" do
72
+ @bible.build_url(:action, :q => 'value', :something => true).should include("http://www.esvapi.org/v2/rest/action?something=true&q=value&key=TEST")
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: esvbible
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Geoffrey Dagley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-06 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.7.0
24
+ version:
25
+ description: See ESV API docs http://www.esvapi.org/
26
+ email:
27
+ - gdagley@gmail.com
28
+ executables:
29
+ - esv_bible
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - README.txt
40
+ - Rakefile
41
+ - bin/esv_bible
42
+ - lib/esv_bible.rb
43
+ - spec/esv_bible_spec.rb
44
+ has_rdoc: true
45
+ homepage: Wrapper for English Standard Version (ESV) Bible Web Service
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --main
49
+ - README.txt
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project: esvbible
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: See ESV API docs http://www.esvapi.org/
71
+ test_files: []
72
+