biblesearch-api 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -1
- data/.travis.yml +10 -0
- data/Guardfile +28 -0
- data/HISTORY.md +4 -3
- data/README.md +32 -25
- data/Rakefile +28 -9
- data/biblesearch-api.gemspec +4 -2
- data/lib/biblesearch-api.rb +39 -34
- data/lib/biblesearch-api/client_version.rb +1 -1
- data/lib/biblesearch-api/endpoints/books.rb +41 -16
- data/lib/biblesearch-api/endpoints/chapters.rb +33 -27
- data/lib/biblesearch-api/endpoints/passages.rb +7 -6
- data/lib/biblesearch-api/endpoints/verses.rb +38 -24
- data/lib/biblesearch-api/endpoints/versions.rb +7 -2
- data/spec/README.md +32 -0
- data/spec/biblesearch-api/endpoints/books_spec.rb +42 -17
- data/spec/biblesearch-api/endpoints/chapters_spec.rb +53 -27
- data/spec/biblesearch-api/endpoints/fumsify_for_all_endpoints_spec.rb +22 -22
- data/spec/biblesearch-api/endpoints/passages_spec.rb +36 -4
- data/spec/biblesearch-api/endpoints/search_spec.rb +1 -1
- data/spec/biblesearch-api/endpoints/verses_spec.rb +53 -19
- data/spec/biblesearch-api/endpoints/versions_spec.rb +10 -4
- data/spec/biblesearch-api_spec.rb +1 -1
- data/spec/cassettes/biblesearch-api_spec-test_0001_has_a_http_response_code_other_than_200.yml +644 -0
- data/spec/cassettes/biblesearch-api_spec-test_0001_has_a_nil_fums_same_singular_and_plural_behavior_as_good_.yml +329 -0
- data/spec/cassettes/biblesearch-api_spec-test_0001_has_fums_in_the_metadata.yml +318 -0
- data/spec/cassettes/biblesearch-api_spec-test_0001_has_metadata.yml +318 -0
- data/spec/cassettes/biblesearch-api_spec-test_0001_returns_a_mash_with_a_collection_and_a_fums.yml +318 -0
- data/spec/cassettes/biblesearch-api_spec-test_0001_returns_a_mash_with_a_value_and_a_fums.yml +318 -0
- data/spec/cassettes/biblesearch-api_spec-test_0002_has_a_http_response_code_in_the_metadata.yml +318 -0
- data/spec/cassettes/biblesearch-api_spec-test_0002_has_a_message_in_the_metadata.yml +644 -0
- data/spec/cassettes/biblesearch-api_spec-test_0002_has_a_real_response.yml +318 -0
- data/spec/cassettes/biblesearch-api_spec-test_0003_has_a_nil_response.yml +644 -0
- data/spec/cassettes/biblesearch-api_spec-test_0003_has_a_response.yml +318 -0
- data/spec/cassettes/endpoint-books_spec-test_0001_has_a_book_value.yml +51 -0
- data/spec/cassettes/endpoint-books_spec-test_0001_has_a_collection.yml +704 -0
- data/spec/cassettes/endpoint-books_spec-test_0001_requires_a_version_id.yml +347 -0
- data/spec/cassettes/endpoint-books_spec-test_0001_returns_nil.yml +330 -0
- data/spec/cassettes/endpoint-books_spec-test_0001_returns_the_same_thing_as_the_equivalent_string_sig.yml +99 -0
- data/spec/cassettes/endpoint-books_spec-test_0002_accepts_an_optional_testament_id.yml +182 -0
- data/spec/cassettes/endpoint-books_spec-test_0002_contains_books_with_chapters.yml +360 -0
- data/spec/cassettes/endpoint-books_spec-test_0002_contains_books_without_chapters.yml +347 -0
- data/spec/cassettes/endpoint-chapters_spec-test_0001_doesn_t_raise_an_ArgumentError.yml +328 -0
- data/spec/cassettes/endpoint-chapters_spec-test_0001_has_a_chapter_value.yml +103 -0
- data/spec/cassettes/endpoint-chapters_spec-test_0001_has_a_collection.yml +72 -0
- data/spec/cassettes/endpoint-chapters_spec-test_0001_returns_an_empty_array.yml +332 -0
- data/spec/cassettes/endpoint-chapters_spec-test_0001_returns_nil.yml +332 -0
- data/spec/cassettes/endpoint-chapters_spec-test_0001_returns_the_same_thing_as_the_equivalent_string_sig.yml +341 -0
- data/spec/cassettes/endpoint-chapters_spec-test_0002_has_verses.yml +103 -0
- data/spec/cassettes/endpoint-chapters_spec-test_0002_should_contain_chapters.yml +72 -0
- data/spec/cassettes/endpoint-chapters_spec-test_0003_can_be_requested_without_marginalia.yml +103 -0
- data/spec/cassettes/endpoint-chapters_spec-test_0004_can_be_requested_with_marginalia.yml +118 -0
- data/spec/cassettes/endpoint-passages_spec-test_0001_has_a_collection.yml +310 -0
- data/spec/cassettes/endpoint-passages_spec-test_0001_should_provide_the_passage_for_each_version_specified.yml +94 -0
- data/spec/cassettes/endpoint-passages_spec-test_0002_can_include_marginalia.yml +186 -0
- data/spec/cassettes/endpoint-passages_spec-test_0002_should_contain_a_single_passage.yml +90 -0
- data/spec/cassettes/endpoint-passages_spec-test_0002_should_contain_no_passages.yml +84 -0
- data/spec/cassettes/endpoint-passages_spec-test_0002_should_contain_passages.yml +142 -0
- data/spec/cassettes/endpoint-passages_spec-test_0003_can_include_marginalia.yml +457 -0
- data/spec/cassettes/endpoint-search_spec-test_0001_has_a_Hashie_Mash_value.yml +316 -0
- data/spec/cassettes/endpoint-search_spec-test_0001_returns_passages.yml +192 -0
- data/spec/cassettes/endpoint-search_spec-test_0001_returns_verses.yml +127 -0
- data/spec/cassettes/endpoint-verses_spec-test_0001_doesn_t_raise_an_ArgumentError.yml +386 -0
- data/spec/cassettes/endpoint-verses_spec-test_0001_has_a_collection.yml +119 -0
- data/spec/cassettes/endpoint-verses_spec-test_0001_has_a_verse_value.yml +55 -0
- data/spec/cassettes/endpoint-verses_spec-test_0001_returns_an_empty_array.yml +338 -0
- data/spec/cassettes/endpoint-verses_spec-test_0001_returns_nil.yml +331 -0
- data/spec/cassettes/endpoint-verses_spec-test_0001_returns_the_same_thing_as_the_equivalent_string_sig.yml +107 -0
- data/spec/cassettes/endpoint-verses_spec-test_0002_can_include_marginalia.yml +109 -0
- data/spec/cassettes/endpoint-verses_spec-test_0002_should_contain_one_verse.yml +57 -0
- data/spec/cassettes/endpoint-verses_spec-test_0002_should_contain_the_proper_number_of_verses.yml +65 -0
- data/spec/cassettes/endpoint-verses_spec-test_0003_can_include_marginalia.yml +235 -0
- data/spec/cassettes/endpoint-versions_spec-test_0001_a_nonexistent_version_with_a_language_code_returns_nil.yml +41 -0
- data/spec/cassettes/endpoint-versions_spec-test_0001_has_a_collection.yml +362 -0
- data/spec/cassettes/endpoint-versions_spec-test_0001_has_a_version_value.yml +54 -0
- data/spec/cassettes/endpoint-versions_spec-test_0001_should_return_only_those_representative_versions.yml +388 -0
- data/spec/cassettes/endpoint-versions_spec-test_0002_should_be_empty.yml +362 -0
- data/spec/cassettes/endpoint-versions_spec-test_0002_should_contain_versions.yml +318 -0
- data/spec/cassettes/fumsify_for_all_endpoints_spec-test_0001_has_real_fums_for_all_requests.yml +473 -0
- data/spec/cassettes/fumsify_for_all_endpoints_spec-test_0001_has_real_fums_for_all_valid_requests.yml +1036 -0
- data/spec/spec_helper.rb +39 -3
- metadata +173 -37
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ea80ca9332cf2efd85b7e0bafe26cda4502cf137
|
4
|
+
data.tar.gz: 5721a597d24d248254a58b182b6f0cd6e514c61b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5027d70b070bb8af63ab66368973a153d163e6b47083067173966432759300c90081af263487bba384bf23c374f2e2ea69774bf6561eb67201db449fc89a0b79
|
7
|
+
data.tar.gz: 86e5223f125886015391a65c631e7cf3ad35d87f7cdb70d43828ca907656823043599f5571d173b1ef2974ec81430aa0bdfc1015e30ab13552c9646e9b3cd788
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
notifications:
|
6
|
+
hipchat:
|
7
|
+
rooms:
|
8
|
+
secure: WfUu7pViMsCPwe/eGKViF0y37PnqiyLWzxr+OAn4GHWmSKpbdBtzBy/QbPVuxzERMjAQFljt+U7f9Ix8PjQHN3tuDJuLxVhv+8yYiQf1yvFbSuMV9Sk/hJdSUu6itW6tb5sm75fHxe//UuJT03qS0N1vRXbZwPu6hrt6UOsmie4=
|
9
|
+
template:
|
10
|
+
- '%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message}'
|
data/Guardfile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :minitest do
|
5
|
+
# with Minitest::Unit
|
6
|
+
# watch(%r{^test/(.*)\/?test_(.*)\.rb})
|
7
|
+
# watch(%r{^lib/(.*/)?([^/]+)\.rb}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
8
|
+
# watch(%r{^test/test_helper\.rb}) { 'test' }
|
9
|
+
|
10
|
+
# with Minitest::Spec
|
11
|
+
watch(%r{^spec/(.*)_spec\.rb})
|
12
|
+
watch(%r{^lib/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
|
13
|
+
watch(%r{^spec/spec_helper\.rb}) { 'spec' }
|
14
|
+
|
15
|
+
# Rails 4
|
16
|
+
# watch(%r{^app/(.+)\.rb}) { |m| "test/#{m[1]}_test.rb" }
|
17
|
+
# watch(%r{^app/controllers/application_controller\.rb}) { 'test/controllers' }
|
18
|
+
# watch(%r{^app/controllers/(.+)_controller\.rb}) { |m| "test/integration/#{m[1]}_test.rb" }
|
19
|
+
# watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
|
20
|
+
# watch(%r{^lib/(.+)\.rb}) { |m| "test/lib/#{m[1]}_test.rb" }
|
21
|
+
# watch(%r{^test/.+_test\.rb})
|
22
|
+
# watch(%r{^test/test_helper\.rb}) { 'test' }
|
23
|
+
|
24
|
+
# Rails < 4
|
25
|
+
# watch(%r{^app/controllers/(.*)\.rb}) { |m| "test/functional/#{m[1]}_test.rb" }
|
26
|
+
# watch(%r{^app/helpers/(.*)\.rb}) { |m| "test/helpers/#{m[1]}_test.rb" }
|
27
|
+
# watch(%r{^app/models/(.*)\.rb}) { |m| "test/unit/#{m[1]}_test.rb" }
|
28
|
+
end
|
data/HISTORY.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
-
1.0
|
2
|
-
|
3
|
-
0.0.
|
1
|
+
* 1.1.0 - now enables include_marginalia and include_chapters
|
2
|
+
* 1.0.3 - Client now uses version 2 of the API, all calls now mostly uniform.
|
3
|
+
* 0.0.2 - #versions and #verses now always respond in the plural, tested
|
4
|
+
* 0.0.1 - Basic functionality, no tests
|
data/README.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# BibleSearch::API
|
2
2
|
|
3
|
-
Ruby wrapper for BibleSearch API (bibles.org)
|
3
|
+
Ruby wrapper for [BibleSearch API (bibles.org)](http://bibles.org).
|
4
|
+
|
5
|
+
## Status
|
6
|
+
|
7
|
+
Gem hosted at [RubyGems](http://rubygems.org/gems/biblesearch-api), API docs at [RubyDoc](http://rubydoc.info/gems/biblesearch-api).
|
8
|
+
|
9
|
+
* Stable Version (1.1.0): [![Build Status](https://travis-ci.org/americanbible/biblesearch-api-ruby.png?branch=master)](https://travis-ci.org/americanbible/biblesearch-api-ruby)
|
10
|
+
* Development Version: [![Build Status](https://travis-ci.org/americanbible/biblesearch-api-ruby.png?branch=develop)](https://travis-ci.org/americanbible/biblesearch-api-ruby)
|
4
11
|
|
5
12
|
## Installation
|
6
13
|
|
@@ -24,43 +31,43 @@ biblesearch = BibleSearch.new('YOUR_API_KEY')
|
|
24
31
|
# Let's get some versions
|
25
32
|
versions = biblesearch.versions
|
26
33
|
spanish_versions = biblesearch.versions(:language => 'spa')
|
27
|
-
|
28
|
-
#
|
29
|
-
|
34
|
+
|
35
|
+
# When you request a version, you'll need to include it's language-code prefix
|
36
|
+
version = biblesearch.version('spa-TLA')
|
30
37
|
|
31
38
|
# Let's get some books
|
32
|
-
books = biblesearch.books('
|
39
|
+
books = biblesearch.books('spa-TLA')
|
33
40
|
# You can also provide a testament
|
34
|
-
old_testament_books = biblsearch.books('
|
41
|
+
old_testament_books = biblsearch.books('spa-TLA', 'OT')
|
35
42
|
# A single book can be specified as a hash ...
|
36
|
-
book = biblesearch.book(:version_id => '
|
43
|
+
book = biblesearch.book(:version_id => 'spa-TLA', :book_id => '2Tim')
|
37
44
|
# ... or as a string
|
38
|
-
book = biblesearch.book('
|
45
|
+
book = biblesearch.book('spa-TLA:2Tim')
|
39
46
|
|
40
47
|
# Let's get some chapters for the book, either via hash ...
|
41
|
-
chapters = biblesearch.chapters(:version_id => '
|
48
|
+
chapters = biblesearch.chapters(:version_id => 'spa-TLA', :book_id => '2Tim')
|
42
49
|
# ... or string
|
43
|
-
chapters = biblesearch.chapters('
|
50
|
+
chapters = biblesearch.chapters('spa-TLA:2Tim')
|
44
51
|
# A single chapter can be specified as a hash ...
|
45
|
-
chapter = biblesearch.chapter(:version_id => '
|
52
|
+
chapter = biblesearch.chapter(:version_id => 'spa-TLA', :book_id => '2Tim', :chapter => 1)
|
46
53
|
# ... or as a string
|
47
|
-
chatper = biblesearch.chapter('
|
54
|
+
chatper = biblesearch.chapter('spa-TLA:2Tim.1')
|
48
55
|
|
49
56
|
# Let's get some verses
|
50
|
-
verses = biblesearch.verses("CEV:John.1","16","17")
|
57
|
+
verses = biblesearch.verses("eng-CEV:John.1","16","17")
|
51
58
|
# A single verse can be specified as a hash ...
|
52
|
-
verse = biblesearch.verse(:version_id => '
|
59
|
+
verse = biblesearch.verse(:version_id => 'spa-TLA', :book_id => 'Acts', :chapter => '8', :verse => '34')
|
53
60
|
# ... or as a string
|
54
|
-
verse = biblesearch.verse('
|
61
|
+
verse = biblesearch.verse('spa-TLA:Acts.8.34')
|
55
62
|
|
56
63
|
# Let's do a search
|
57
64
|
results = biblesearch.search('john 3:16') #passage search
|
58
65
|
results = biblesearch.search('mary') #keyword search
|
59
66
|
|
60
67
|
# Let's get some passages for a single version ...
|
61
|
-
passages = biblesearch.passages('john 3:16', :version => '
|
68
|
+
passages = biblesearch.passages('john 3:16', :version => 'eng-KJVA')
|
62
69
|
# ... or for multiple versions
|
63
|
-
passages = biblesearch.passages('john 3:16', :versions => ['
|
70
|
+
passages = biblesearch.passages('john 3:16', :versions => ['eng-KJVA', 'eng-CEV'])
|
64
71
|
```
|
65
72
|
|
66
73
|
### Return values
|
@@ -74,18 +81,18 @@ Singular calls (#version, #verse, etc) respond to #value with a mash.
|
|
74
81
|
## Contributing
|
75
82
|
|
76
83
|
1. Fork it
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
84
|
+
1. Create your feature branch (`git checkout -b my-new-feature`)
|
85
|
+
1. Frequently test your code with `rake test:all`, adding tests for your new features. (*Note* that this Gem uses the `minitest` framework, not `RSpec`, despite the `spec/` directory name.)
|
86
|
+
1. Test against all supported rubies (`rake test:overtest` (see below))
|
87
|
+
1. Commit your changes (`git commit -am 'Added some feature'`)
|
88
|
+
1. Push to the branch (`git push origin my-new-feature`)
|
89
|
+
1. Create new Pull Request
|
82
90
|
|
83
91
|
### Supported Rubies
|
84
92
|
|
85
93
|
As of this release, the following MRI versions are verified as supported:
|
86
94
|
|
87
|
-
* 1.8.7
|
88
|
-
* 1.9.2-p180
|
89
95
|
* 1.9.3
|
96
|
+
* 2.0.0
|
90
97
|
|
91
|
-
In order to test against all of them, an "overtest" rake task is supplied that uses RVM to test against each of the supported versions. You will, however, have to bundle against each of them independently.
|
98
|
+
In order to test against all of them, an "test:overtest" rake task is supplied that uses RVM to test against each of the supported versions. You will, however, have to bundle against each of them independently.
|
data/Rakefile
CHANGED
@@ -3,6 +3,11 @@ require 'bundler'
|
|
3
3
|
Bundler::GemHelper.install_tasks
|
4
4
|
require "bundler/gem_tasks"
|
5
5
|
require 'rake/testtask'
|
6
|
+
require 'rake/clean'
|
7
|
+
|
8
|
+
# one way to remove cassette files
|
9
|
+
# require 'rake/clean'
|
10
|
+
CLOBBER.include('spec/cassettes/*.yml')
|
6
11
|
|
7
12
|
RUBY_TEST_VERSIONS = [
|
8
13
|
'1.8.7',
|
@@ -10,15 +15,29 @@ RUBY_TEST_VERSIONS = [
|
|
10
15
|
'1.9.3'
|
11
16
|
]
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
namespace "test" do
|
19
|
+
|
20
|
+
desc 'Run all of the gem minitests.'
|
21
|
+
Rake::TestTask.new(:all) do |t|
|
22
|
+
t.libs.push "spec"
|
23
|
+
t.pattern = 'spec/**/*_spec.rb'
|
24
|
+
t.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'Focus on a particular test file (hardcoded for now).'
|
28
|
+
Rake::TestTask.new(:focus) do |t|
|
29
|
+
t.libs.push "spec"
|
30
|
+
t.pattern = 'spec/**/chapters_spec.rb'
|
31
|
+
t.verbose = true
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'Tests the library against several rubies'
|
35
|
+
task :overtest do
|
36
|
+
system "rvm #{RUBY_TEST_VERSIONS.map{|x| "#{x}@biblesearch-api"}.join(',')} do bundle exec rake test"
|
37
|
+
end
|
18
38
|
|
19
|
-
task :default => :test
|
20
39
|
|
21
|
-
desc 'Tests the library against several rubies'
|
22
|
-
task :overtest do
|
23
|
-
system "rvm #{RUBY_TEST_VERSIONS.map{|x| "#{x}@biblesearch-api"}.join(',')} do bundle exec rake test"
|
24
40
|
end
|
41
|
+
|
42
|
+
task :default => "test:all"
|
43
|
+
|
data/biblesearch-api.gemspec
CHANGED
@@ -18,8 +18,10 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_dependency "oj"
|
19
19
|
gem.add_dependency "hashie"
|
20
20
|
gem.add_dependency "httparty"
|
21
|
-
gem.add_development_dependency 'vcr'
|
22
|
-
gem.add_development_dependency 'webmock'
|
21
|
+
gem.add_development_dependency 'vcr', '= 2.6.0'
|
22
|
+
gem.add_development_dependency 'webmock' , '>= 1.8.0', '< 1.14'
|
23
23
|
gem.add_development_dependency 'minitest', '= 3.3.0'
|
24
24
|
gem.add_development_dependency 'rake', '= 0.9.2.2'
|
25
|
+
gem.add_development_dependency 'minitest-reporters', '>= 0.5.0'
|
26
|
+
gem.add_development_dependency 'guard-minitest'
|
25
27
|
end
|
data/lib/biblesearch-api.rb
CHANGED
@@ -37,51 +37,56 @@ class BibleSearch
|
|
37
37
|
format :json
|
38
38
|
|
39
39
|
attr_accessor :api_key
|
40
|
+
|
40
41
|
def initialize(api_key, base_uri = 'bibles.org/v2')
|
41
42
|
self.class.base_uri base_uri
|
42
43
|
self.class.basic_auth(@api_key = api_key, 'X')
|
44
|
+
@version_re = /[A-Za-z]{3}+-[A-Za-z0-9]+/
|
45
|
+
@book_re = /[A-Za-z]{3}+-[A-Za-z0-9]+:[A-Za-z0-9]+/
|
46
|
+
@chapter_re = /[A-Za-z]{3}+-[A-Za-z0-9]+:[A-Za-z0-9]+\.[A-Za-z0-9]+/
|
47
|
+
@verse_re = /[A-Za-z]{3}+-[A-Za-z0-9]+:[A-Za-z0-9]+\.[A-Za-z0-9]+\.[A-Za-z0-9]+/
|
43
48
|
end
|
44
49
|
|
45
50
|
private
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
def required_keys_present?(hash, required)
|
53
|
-
hash.keys.sort_by {|key| key.to_s} == required.sort_by {|key| key.to_s}
|
54
|
-
end
|
51
|
+
def mashup(response)
|
52
|
+
response = Hashie::Mash.new(response)
|
53
|
+
# => raise BibleSearchError.new("Code #{response.code} -- #{response.desc}") unless response.stat == "ok"
|
54
|
+
response
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
result['meta'] = {}
|
60
|
-
begin
|
61
|
-
result['meta'] = api_response['response'].delete('meta')
|
62
|
-
result['response'] = api_response['response']
|
63
|
-
rescue MultiJson::LoadError
|
64
|
-
result['meta']['message'] = api_response.body
|
65
|
-
ensure
|
66
|
-
result['meta']['http_code'] = api_response.code
|
67
|
-
return mashup(result)
|
68
|
-
end
|
69
|
-
end
|
57
|
+
def required_keys_only?(hash, required)
|
58
|
+
hash.keys.sort_by { |key| key.to_s } == required.sort_by { |key| key.to_s }
|
59
|
+
end
|
70
60
|
|
71
|
-
|
72
|
-
|
61
|
+
def get_mash(*args)
|
62
|
+
api_response = self.class.get(*args)
|
63
|
+
result = {}
|
64
|
+
result['meta'] = {}
|
65
|
+
begin
|
66
|
+
result['meta'] = api_response['response'].delete('meta')
|
67
|
+
result['response'] = api_response['response']
|
68
|
+
rescue JSON::JSONError #MultiJSON dropped from httpparty 14JUN2013
|
69
|
+
result['meta']['message'] = api_response.body
|
70
|
+
ensure
|
71
|
+
result['meta']['http_code'] = api_response.code
|
72
|
+
return mashup(result)
|
73
73
|
end
|
74
|
+
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
76
|
+
def pluralize_result(result)
|
77
|
+
result.kind_of?(Array) ? result : [result]
|
78
|
+
end
|
78
79
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
fumsified.value = value
|
83
|
-
end
|
80
|
+
def fumsify(api_result, value)
|
81
|
+
fumsified = Hashie::Mash.new
|
82
|
+
fumsified.fums = api_result.meta.fums
|
84
83
|
|
85
|
-
|
84
|
+
if value.kind_of?(Array)
|
85
|
+
fumsified.collection = value
|
86
|
+
else
|
87
|
+
fumsified.value = value
|
86
88
|
end
|
89
|
+
|
90
|
+
fumsified
|
91
|
+
end
|
87
92
|
end
|
@@ -1,38 +1,63 @@
|
|
1
1
|
class BibleSearch
|
2
|
+
|
3
|
+
# accept a hash or string book signature, validate it, and return a string
|
4
|
+
def valid_book(book_sig)
|
5
|
+
# if it's a hash, convert it to a string
|
6
|
+
if book_sig.is_a?(Hash)
|
7
|
+
begin
|
8
|
+
book_sig = "#{book_sig.fetch(:version_id)}:#{book_sig.fetch(:book_id)}"
|
9
|
+
rescue
|
10
|
+
raise ArgumentError.new('Book signature hash must include :version_id and :book_id')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# then check
|
15
|
+
unless book_sig.match(@book_re)
|
16
|
+
raise ArgumentError.new('Book signature must be in the form "LANGUAGE_ID-VERSION_ID:BOOK_ID"')
|
17
|
+
end
|
18
|
+
book_sig
|
19
|
+
end
|
20
|
+
|
2
21
|
module Books
|
3
|
-
def books(version_id,
|
22
|
+
def books(version_id, options={})
|
23
|
+
defaults = {testament_id: nil, include_chapters: false}
|
24
|
+
options = defaults.merge(options)
|
25
|
+
testament_id = options[:testament_id]
|
26
|
+
include_chapters = options[:include_chapters]
|
27
|
+
|
4
28
|
api_endpoint = "/versions/#{version_id}/books.js"
|
5
29
|
api_endpoint += "?testament=#{testament_id}" unless testament_id.nil?
|
30
|
+
api_endpoint += "?include_chapters=true" if include_chapters
|
31
|
+
|
32
|
+
unless @version_re.match(version_id)
|
33
|
+
raise ArgumentError.new('version_id must be in the form "LANGUAGE_CODE-VERSION_ID:BOOK_ID"')
|
34
|
+
end
|
6
35
|
|
7
36
|
api_result = get_mash(api_endpoint)
|
8
37
|
|
9
|
-
books = []
|
10
38
|
if api_result.meta.http_code == 200
|
39
|
+
books = []
|
11
40
|
books = pluralize_result(api_result.response.books)
|
41
|
+
fumsify(api_result, books)
|
42
|
+
else
|
43
|
+
[]
|
12
44
|
end
|
13
|
-
|
14
|
-
fumsify(api_result, books)
|
15
45
|
end
|
16
46
|
|
17
47
|
def book(book_sig)
|
18
|
-
|
19
|
-
unless required_keys_present?(book_sig, [:version_id, :book_id])
|
20
|
-
raise ArgumentError.new('Book signature hash must include :version_id and :book_id')
|
21
|
-
end
|
22
|
-
return book("#{book_sig[:version_id]}:#{book_sig[:book_id]}")
|
23
|
-
end
|
48
|
+
book_sig = valid_book(book_sig)
|
24
49
|
|
25
|
-
unless book_sig.match(/([A-Za-z0-9]+-)?[A-Za-z0-9]+:[A-Za-z0-9]+/)
|
26
|
-
raise ArgumentError.new('Book signature must be in the form "VERSION_ID:BOOK_ID"')
|
27
|
-
end
|
28
|
-
|
29
|
-
book = nil
|
30
50
|
api_result = get_mash("/books/#{book_sig}.js")
|
31
51
|
if api_result.meta.http_code == 200
|
52
|
+
book = nil
|
32
53
|
book = api_result.response.books.first
|
54
|
+
fumsify(api_result, book)
|
55
|
+
else
|
56
|
+
nil
|
33
57
|
end
|
34
58
|
|
35
|
-
fumsify(api_result, book)
|
36
59
|
end
|
60
|
+
|
61
|
+
|
37
62
|
end
|
38
63
|
end
|
@@ -1,47 +1,53 @@
|
|
1
1
|
class BibleSearch
|
2
|
-
module Chapters
|
3
|
-
def chapters(book_sig)
|
4
|
-
if book_sig.is_a?(Hash)
|
5
|
-
unless required_keys_present?(book_sig, [:version_id, :book_id])
|
6
|
-
raise ArgumentError.new('Book signature hash must include :version_id and :book_id')
|
7
|
-
end
|
8
2
|
|
9
|
-
|
3
|
+
def valid_chapter(chapter_sig)
|
4
|
+
if chapter_sig.is_a?(Hash)
|
5
|
+
begin
|
6
|
+
# chapter_sig = chapter_sig.fetch(:version_id) + ':' + chapter_sig.fetch(:book_id) + ".#{chapter_sig.fetch(:chapter)}"
|
7
|
+
chapter_sig = "#{valid_book(chapter_sig)}.#{chapter_sig.fetch(:chapter)}"
|
8
|
+
rescue
|
9
|
+
raise ArgumentError.new('Chapter signature hash must include :version_id, :book_id, and :chapter')
|
10
10
|
end
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
unless chapter_sig.match(@chapter_re)
|
14
|
+
raise ArgumentError.new('Chapter signature must be in the form "VERSION_ID:BOOK_ID.CHAPTER_NUMBER"')
|
15
|
+
end
|
16
|
+
chapter_sig
|
17
|
+
end
|
15
18
|
|
16
|
-
|
19
|
+
module Chapters
|
20
|
+
def chapters(book_sig)
|
21
|
+
book_sig = valid_book(book_sig)
|
17
22
|
api_result = get_mash("/books/#{book_sig}/chapters.js")
|
18
23
|
if api_result.meta.http_code == 200
|
24
|
+
chapters = []
|
19
25
|
chapters = pluralize_result(api_result.response.chapters)
|
26
|
+
fumsify(api_result, chapters)
|
27
|
+
else
|
28
|
+
# raise ArgumentError.new("Unrecognized book signature.")
|
29
|
+
[]
|
20
30
|
end
|
21
31
|
|
22
|
-
fumsify(api_result, chapters)
|
23
32
|
end
|
24
33
|
|
25
|
-
def chapter(chapter_sig)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
return chapter("#{chapter_sig[:version_id]}:#{chapter_sig[:book_id]}.#{chapter_sig[:chapter]}")
|
32
|
-
end
|
34
|
+
# def chapter(chapter_sig) #original
|
35
|
+
def chapter(chapter_sig, options={}) #option 1
|
36
|
+
# def chapter(options) #option 2 (options merged with sig, breaks string sig)
|
37
|
+
chapter_sig = valid_chapter(chapter_sig)
|
33
38
|
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
chapter = nil
|
39
|
-
api_result = get_mash("/chapters/#{chapter_sig}.js")
|
39
|
+
# uri += '?include_marginalia=true' if options.fetch(:include_marginalia, false)
|
40
|
+
api_result = get_mash("/chapters/#{chapter_sig}.js", query: options)
|
40
41
|
if api_result.meta.http_code == 200
|
42
|
+
chapter = nil
|
41
43
|
chapter = api_result.response.chapters.first
|
44
|
+
fumsify(api_result, chapter)
|
45
|
+
else
|
46
|
+
nil
|
42
47
|
end
|
43
48
|
|
44
|
-
fumsify(api_result, chapter)
|
45
49
|
end
|
50
|
+
|
51
|
+
|
46
52
|
end
|
47
53
|
end
|