biblesearch-api 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/HISTORY.md +3 -0
- data/LICENSE +22 -0
- data/README.md +91 -0
- data/Rakefile +24 -0
- data/biblesearch-api.gemspec +25 -0
- data/lib/biblesearch-api.rb +87 -0
- data/lib/biblesearch-api/api_interface.rb +58 -0
- data/lib/biblesearch-api/client_version.rb +3 -0
- data/lib/biblesearch-api/endpoints/books.rb +38 -0
- data/lib/biblesearch-api/endpoints/chapters.rb +47 -0
- data/lib/biblesearch-api/endpoints/passages.rb +22 -0
- data/lib/biblesearch-api/endpoints/search.rb +24 -0
- data/lib/biblesearch-api/endpoints/verses.rb +42 -0
- data/lib/biblesearch-api/endpoints/versions.rb +28 -0
- data/spec/biblesearch-api/endpoints/books_spec.rb +128 -0
- data/spec/biblesearch-api/endpoints/chapters_spec.rb +154 -0
- data/spec/biblesearch-api/endpoints/fumsify_for_all_endpoints_spec.rb +75 -0
- data/spec/biblesearch-api/endpoints/passages_spec.rb +85 -0
- data/spec/biblesearch-api/endpoints/search_spec.rb +36 -0
- data/spec/biblesearch-api/endpoints/verses_spec.rb +152 -0
- data/spec/biblesearch-api/endpoints/versions_spec.rb +91 -0
- data/spec/biblesearch-api/pathtest.rb +1 -0
- data/spec/biblesearch-api_spec.rb +137 -0
- data/spec/spec_helper.rb +12 -0
- metadata +199 -0
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'biblesearch-api'
|
3
|
+
|
4
|
+
describe BibleSearch do
|
5
|
+
before do
|
6
|
+
VCR.insert_cassette %{endpoint-#{File.basename(__FILE__, '.rb')}-#{__name__}}
|
7
|
+
@biblesearch = BibleSearch.new('DUMMY_API_KEY')
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
VCR.eject_cassette
|
12
|
+
end
|
13
|
+
|
14
|
+
describe %{#passages} do
|
15
|
+
describe %{when returning no passages} do
|
16
|
+
before do
|
17
|
+
@passages = @biblesearch.passages('Batman 1:1-16', :version => 'KJV')
|
18
|
+
end
|
19
|
+
it %{has a collection} do
|
20
|
+
@passages.collection.must_be_instance_of Array
|
21
|
+
end
|
22
|
+
|
23
|
+
it %{should contain no passages} do
|
24
|
+
@passages.collection.length.must_equal 0
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe %{when returning a single passage} do
|
29
|
+
before do
|
30
|
+
@passages = @biblesearch.passages('John 3:16', :version => 'KJV')
|
31
|
+
end
|
32
|
+
it %{has a collection} do
|
33
|
+
@passages.collection.must_be_instance_of Array
|
34
|
+
end
|
35
|
+
|
36
|
+
it %{should contain a single passage} do
|
37
|
+
@passages.collection.size.must_equal 1
|
38
|
+
@passages.collection.first.tap do |passage|
|
39
|
+
passage.must_respond_to :display
|
40
|
+
passage.must_respond_to :version
|
41
|
+
passage.must_respond_to :version_abbreviation
|
42
|
+
passage.must_respond_to :path
|
43
|
+
passage.must_respond_to :start_verse_id
|
44
|
+
passage.must_respond_to :end_verse_id
|
45
|
+
passage.must_respond_to :text
|
46
|
+
passage.must_respond_to :copyright
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe %{when returning multiple passages} do
|
52
|
+
before do
|
53
|
+
@passages = @biblesearch.passages('')
|
54
|
+
end
|
55
|
+
it %{has a collection} do
|
56
|
+
@passages.collection.must_be_instance_of Array
|
57
|
+
end
|
58
|
+
it %{should contain passages} do
|
59
|
+
@passages.collection.each do |passage|
|
60
|
+
passage.must_respond_to :display
|
61
|
+
passage.must_respond_to :version
|
62
|
+
passage.must_respond_to :version_abbreviation
|
63
|
+
passage.must_respond_to :path
|
64
|
+
passage.must_respond_to :start_verse_id
|
65
|
+
passage.must_respond_to :end_verse_id
|
66
|
+
passage.must_respond_to :text
|
67
|
+
passage.must_respond_to :copyright
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe %{when passing a list of bible version ids} do
|
73
|
+
before do
|
74
|
+
@versions = ['KJV', 'CEV']
|
75
|
+
@passages = @biblesearch.passages('John 3:16', :versions => @versions)
|
76
|
+
end
|
77
|
+
|
78
|
+
it %{should provide the passage for each version specified} do
|
79
|
+
@passages.collection.each do |passage|
|
80
|
+
@versions.must_include passage.version
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'biblesearch-api'
|
3
|
+
|
4
|
+
describe BibleSearch do
|
5
|
+
before do
|
6
|
+
VCR.insert_cassette %{endpoint-#{File.basename(__FILE__, '.rb')}-#{__name__}}
|
7
|
+
@biblesearch = BibleSearch.new('DUMMY_API_KEY')
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
VCR.eject_cassette
|
12
|
+
end
|
13
|
+
|
14
|
+
describe %{#search} do
|
15
|
+
it %{has a Hashie::Mash value} do
|
16
|
+
@biblesearch.search('john 3:16').value.must_be_instance_of Hashie::Mash
|
17
|
+
@biblesearch.search('Mahershalalhashbaz').value.must_be_instance_of Hashie::Mash
|
18
|
+
end
|
19
|
+
|
20
|
+
describe %{when doing a passage search} do
|
21
|
+
it %{returns passages} do
|
22
|
+
result = @biblesearch.search('john 3:16').value
|
23
|
+
result.type.must_equal 'passages'
|
24
|
+
result.must_respond_to(:passages)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe %{when doing a keyword search} do
|
29
|
+
it %{returns verses} do
|
30
|
+
result = @biblesearch.search('Mahershalalhashbaz').value
|
31
|
+
result.type.must_equal 'verses'
|
32
|
+
result.must_respond_to(:verses)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'biblesearch-api'
|
3
|
+
|
4
|
+
describe BibleSearch do
|
5
|
+
before do
|
6
|
+
VCR.insert_cassette %{endpoint-#{File.basename(__FILE__, '.rb')}-#{__name__}}
|
7
|
+
@biblesearch = BibleSearch.new('DUMMY_API_KEY')
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
VCR.eject_cassette
|
12
|
+
end
|
13
|
+
|
14
|
+
describe %{#verses} do
|
15
|
+
describe %{when returning no verses} do
|
16
|
+
before do
|
17
|
+
@verses = @biblesearch.verses('KJV:Batman.1', '1', '16')
|
18
|
+
end
|
19
|
+
|
20
|
+
it %{has a collection} do
|
21
|
+
@verses.collection.must_be_instance_of Array
|
22
|
+
end
|
23
|
+
|
24
|
+
it %{should contain no verses} do
|
25
|
+
@verses.collection.size.must_equal 0
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe %{when returning one verse} do
|
30
|
+
before do
|
31
|
+
@verses = @biblesearch.verses('KJV:John.3', '16', '16')
|
32
|
+
end
|
33
|
+
|
34
|
+
it %{has a collection} do
|
35
|
+
@verses.collection.must_be_instance_of Array
|
36
|
+
end
|
37
|
+
|
38
|
+
it %{should contain one verse} do
|
39
|
+
@verses.collection.length.must_equal 1
|
40
|
+
@verses.collection.each do |verse|
|
41
|
+
verse.must_respond_to(:auditid)
|
42
|
+
verse.must_respond_to(:copyright)
|
43
|
+
verse.must_respond_to(:id)
|
44
|
+
verse.must_respond_to(:label)
|
45
|
+
verse.must_respond_to(:lastverse)
|
46
|
+
verse.must_respond_to(:next)
|
47
|
+
verse.must_respond_to(:osis_end)
|
48
|
+
verse.must_respond_to(:parent)
|
49
|
+
verse.must_respond_to(:previous)
|
50
|
+
verse.must_respond_to(:reference)
|
51
|
+
verse.must_respond_to(:text)
|
52
|
+
verse.must_respond_to(:verse)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe %{when returning multiple verses} do
|
58
|
+
before do
|
59
|
+
@start_verse = 16
|
60
|
+
@end_verse = 17
|
61
|
+
@verses = @biblesearch.verses('KJV:John.3', @start_verse, @end_verse)
|
62
|
+
end
|
63
|
+
|
64
|
+
it %{has a collection} do
|
65
|
+
@verses.collection.must_be_instance_of Array
|
66
|
+
end
|
67
|
+
|
68
|
+
it %{should contain the proper number of verses} do
|
69
|
+
@verses.collection.length.must_equal(1 + @end_verse - @start_verse)
|
70
|
+
@verses.collection.each do |verse|
|
71
|
+
verse.must_respond_to(:auditid)
|
72
|
+
verse.must_respond_to(:copyright)
|
73
|
+
verse.must_respond_to(:id)
|
74
|
+
verse.must_respond_to(:label)
|
75
|
+
verse.must_respond_to(:lastverse)
|
76
|
+
verse.must_respond_to(:next)
|
77
|
+
verse.must_respond_to(:osis_end)
|
78
|
+
verse.must_respond_to(:parent)
|
79
|
+
verse.must_respond_to(:previous)
|
80
|
+
verse.must_respond_to(:reference)
|
81
|
+
verse.must_respond_to(:text)
|
82
|
+
verse.must_respond_to(:verse)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe %{#verse} do
|
89
|
+
describe %{given verse signature} do
|
90
|
+
describe %{as a string} do
|
91
|
+
it %{raises an argument error for bad input} do
|
92
|
+
bad_verse_string = lambda { @biblesearch.verse('SupDawg') }
|
93
|
+
bad_verse_string.must_raise ArgumentError
|
94
|
+
(bad_verse_string.call rescue $!).message.must_equal 'Verse signature must be in the form "VERSION_ID:BOOK_ID.CHAPTER_NUMBER.VERSE_NUMBER"'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe %{as a hash} do
|
99
|
+
before do
|
100
|
+
@options = {
|
101
|
+
:version_id => 'GNT',
|
102
|
+
:book_id => 'Acts',
|
103
|
+
:chapter => '8',
|
104
|
+
:verse => '34'
|
105
|
+
}
|
106
|
+
end
|
107
|
+
describe %{if any pieces are missing} do
|
108
|
+
it %{raises an argument error} do
|
109
|
+
@options.keys.each do |key|
|
110
|
+
options = @options
|
111
|
+
options.delete(key)
|
112
|
+
bad_verse_hash = lambda { @biblesearch.verse(options) }
|
113
|
+
bad_verse_hash.must_raise ArgumentError
|
114
|
+
(bad_verse_hash.call rescue $!).message.must_equal 'Verse signature hash must include :version_id, :book_id, :chapter, and :verse'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe %{with a complete hash} do
|
120
|
+
it %{returns the same thing as the equivalent string sig} do
|
121
|
+
@biblesearch.verse(@options).value.must_equal @biblesearch.verse('GNT:Acts.8.34').value
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe %{when requesting a valid verse} do
|
128
|
+
it %{has a verse value} do
|
129
|
+
result = @biblesearch.verse('GNT:Acts.8.34').value
|
130
|
+
result.must_be_instance_of Hashie::Mash
|
131
|
+
result.must_respond_to(:auditid)
|
132
|
+
result.must_respond_to(:copyright)
|
133
|
+
result.must_respond_to(:id)
|
134
|
+
result.must_respond_to(:label)
|
135
|
+
result.must_respond_to(:lastverse)
|
136
|
+
result.must_respond_to(:next)
|
137
|
+
result.must_respond_to(:osis_end)
|
138
|
+
result.must_respond_to(:parent)
|
139
|
+
result.must_respond_to(:previous)
|
140
|
+
result.must_respond_to(:reference)
|
141
|
+
result.must_respond_to(:text)
|
142
|
+
result.must_respond_to(:verse)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe %{when requesting an invalid verse} do
|
147
|
+
it %{has a nil value} do
|
148
|
+
@biblesearch.verse('KJV:Batman.1.1').value.must_be_nil
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'biblesearch-api'
|
3
|
+
|
4
|
+
describe BibleSearch do
|
5
|
+
before do
|
6
|
+
VCR.insert_cassette %{endpoint-#{File.basename(__FILE__, '.rb')}-#{__name__}}
|
7
|
+
@biblesearch = BibleSearch.new('DUMMY_API_KEY')
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
VCR.eject_cassette
|
12
|
+
end
|
13
|
+
|
14
|
+
describe %{#versions} do
|
15
|
+
before do
|
16
|
+
@versions = @biblesearch.versions
|
17
|
+
end
|
18
|
+
|
19
|
+
it %{has a collection} do
|
20
|
+
@versions.collection.must_be_instance_of Array
|
21
|
+
end
|
22
|
+
|
23
|
+
it %{should contain versions} do
|
24
|
+
@versions.collection.length.must_be :>, 0
|
25
|
+
@versions.collection.each do |version|
|
26
|
+
version.must_respond_to(:id)
|
27
|
+
version.must_respond_to(:name)
|
28
|
+
version.must_respond_to(:lang)
|
29
|
+
version.must_respond_to(:lang_code)
|
30
|
+
version.must_respond_to(:lang_name_eng)
|
31
|
+
version.must_respond_to(:abbreviation)
|
32
|
+
version.must_respond_to(:copyright)
|
33
|
+
version.must_respond_to(:contact_url)
|
34
|
+
version.must_respond_to(:info)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe %{when I provide a language} do
|
39
|
+
describe %{that has representative versions on the remote end} do
|
40
|
+
before do
|
41
|
+
@spanish_versions = @biblesearch.versions(:language => 'spa')
|
42
|
+
end
|
43
|
+
it 'should return only those representative versions' do
|
44
|
+
@spanish_versions.collection.each do |version|
|
45
|
+
version.lang.must_equal 'spa'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe %{that has no representative versions on the remote end} do
|
51
|
+
before do
|
52
|
+
@klingon_versions = @biblesearch.versions(:language => 'klingon')
|
53
|
+
end
|
54
|
+
it %{has a collection} do
|
55
|
+
@klingon_versions.collection.must_be_instance_of Array
|
56
|
+
end
|
57
|
+
it %{should be empty} do
|
58
|
+
@klingon_versions.collection.length.must_equal 0
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe %{#version} do
|
65
|
+
it %{requires a version id} do
|
66
|
+
lambda { @biblesearch.version }.must_raise ArgumentError
|
67
|
+
end
|
68
|
+
|
69
|
+
describe %{with a valid version id} do
|
70
|
+
it %{has a version value} do
|
71
|
+
result = @biblesearch.version('GNT').value
|
72
|
+
result.must_be_instance_of Hashie::Mash
|
73
|
+
result.must_respond_to(:id)
|
74
|
+
result.must_respond_to(:name)
|
75
|
+
result.must_respond_to(:lang)
|
76
|
+
result.must_respond_to(:lang_code)
|
77
|
+
result.must_respond_to(:lang_name_eng)
|
78
|
+
result.must_respond_to(:abbreviation)
|
79
|
+
result.must_respond_to(:copyright)
|
80
|
+
result.must_respond_to(:contact_url)
|
81
|
+
result.must_respond_to(:info)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe %{with an invalid version id} do
|
86
|
+
it %{has a nil value} do
|
87
|
+
@biblesearch.version('JIMBOB').value.must_be_nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
puts %{#{RUBY_VERSION}: #{__FILE__}}
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'biblesearch-api'
|
3
|
+
|
4
|
+
describe BibleSearch do
|
5
|
+
before do
|
6
|
+
VCR.insert_cassette %{#{File.basename(__FILE__, '.rb')}-#{__name__}}
|
7
|
+
@biblesearch = BibleSearch.new('DUMMY_API_KEY')
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
VCR.eject_cassette
|
12
|
+
end
|
13
|
+
|
14
|
+
describe %{.new} do
|
15
|
+
it %{requires an API key as its first argument} do
|
16
|
+
lambda {BibleSearch.new}.must_raise ArgumentError
|
17
|
+
rigamaroe = BibleSearch.new('rigamaroe')
|
18
|
+
rigamaroe.api_key.must_equal 'rigamaroe'
|
19
|
+
end
|
20
|
+
it %{accepts a base_uri as its second argument} do
|
21
|
+
whatever = BibleSearch.new('whatever', 'lookatmybible.com')
|
22
|
+
whatever.wont_be_nil
|
23
|
+
whatever.class.base_uri.must_equal 'http://lookatmybible.com'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe %{#get_mash} do
|
28
|
+
before do
|
29
|
+
@api_result = @biblesearch.instance_eval('get_mash("/versions.js")')
|
30
|
+
end
|
31
|
+
|
32
|
+
it %{has metadata} do
|
33
|
+
@api_result.must_respond_to(:meta)
|
34
|
+
@api_result.meta.must_be_instance_of Hashie::Mash
|
35
|
+
end
|
36
|
+
|
37
|
+
it %{has a http response code in the metadata} do
|
38
|
+
@api_result.meta.http_code.wont_be_nil
|
39
|
+
@api_result.meta.http_code.must_be_kind_of Integer
|
40
|
+
end
|
41
|
+
|
42
|
+
it %{has a response} do
|
43
|
+
@api_result.must_respond_to(:response)
|
44
|
+
end
|
45
|
+
|
46
|
+
describe %{in the sunny day scenario} do
|
47
|
+
it %{has fums in the metadata} do
|
48
|
+
@api_result.meta.must_respond_to(:fums)
|
49
|
+
@api_result.meta.fums.wont_be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it %{has a real response} do
|
53
|
+
@api_result.response.wont_be_nil
|
54
|
+
@api_result.must_be_instance_of Hashie::Mash
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe %{when something goes wrong} do
|
59
|
+
before do
|
60
|
+
@api_result = @biblesearch.instance_eval('get_mash("/my-pokemons.js")')
|
61
|
+
end
|
62
|
+
|
63
|
+
it %{has a http response code other than 200} do
|
64
|
+
@api_result.meta.http_code.wont_equal 200
|
65
|
+
end
|
66
|
+
|
67
|
+
it %{has a message in the metadata} do
|
68
|
+
@api_result.meta.message.wont_be_nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it %{has a nil response} do
|
72
|
+
@api_result.response.must_be_nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe %{#pluralize_result} do
|
78
|
+
describe %{returns an array} do
|
79
|
+
it %{containing the contents of a passed array} do
|
80
|
+
result = [1, 2, 3, 4]
|
81
|
+
@biblesearch.instance_eval(%{pluralize_result([#{result.join(', ')}])}).must_equal result
|
82
|
+
end
|
83
|
+
|
84
|
+
it %{containing the singular value passed} do
|
85
|
+
result = 1
|
86
|
+
@biblesearch.instance_eval(%{pluralize_result(#{result})}).must_equal [result]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe %{#fumsify} do
|
92
|
+
describe %{given a good API Result} do
|
93
|
+
before do
|
94
|
+
@api_result = @biblesearch.send(:get_mash, '/versions.js')
|
95
|
+
end
|
96
|
+
|
97
|
+
describe %{and a plural value} do
|
98
|
+
it %{returns a mash with a collection and a fums} do
|
99
|
+
fumsified = @biblesearch.send(:fumsify, @api_result, [])
|
100
|
+
fumsified.must_be_instance_of Hashie::Mash
|
101
|
+
fumsified.fums.wont_be_nil
|
102
|
+
fumsified.collection.must_be_kind_of(Array)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe %{and a singular value} do
|
107
|
+
it %{returns a mash with a value and a fums} do
|
108
|
+
[1, 'a', Hashie::Mash.new({:foo => 'bar'})].each do |value|
|
109
|
+
fumsified = @biblesearch.send(:fumsify, @api_result, value)
|
110
|
+
fumsified.must_be_instance_of Hashie::Mash
|
111
|
+
fumsified.fums.wont_be_nil
|
112
|
+
fumsified.value.must_equal value
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe %{given a negative API Result} do
|
119
|
+
before do
|
120
|
+
@api_result = @biblesearch.send(:get_mash, '/my-pokemons.js')
|
121
|
+
end
|
122
|
+
|
123
|
+
it %{has a nil fums (same singular and plural behavior as good)} do
|
124
|
+
collection = [1, 2, 3, 4]
|
125
|
+
value = 1
|
126
|
+
fumsified_plural = @biblesearch.send(:fumsify, @api_result, collection)
|
127
|
+
fumsified_singular = @biblesearch.send(:fumsify, @api_result, value)
|
128
|
+
|
129
|
+
fumsified_plural.fums.must_be_nil
|
130
|
+
fumsified_plural.collection.must_equal collection
|
131
|
+
|
132
|
+
fumsified_singular.fums.must_be_nil
|
133
|
+
fumsified_singular.value.must_equal value
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|