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.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -1
  3. data/.travis.yml +10 -0
  4. data/Guardfile +28 -0
  5. data/HISTORY.md +4 -3
  6. data/README.md +32 -25
  7. data/Rakefile +28 -9
  8. data/biblesearch-api.gemspec +4 -2
  9. data/lib/biblesearch-api.rb +39 -34
  10. data/lib/biblesearch-api/client_version.rb +1 -1
  11. data/lib/biblesearch-api/endpoints/books.rb +41 -16
  12. data/lib/biblesearch-api/endpoints/chapters.rb +33 -27
  13. data/lib/biblesearch-api/endpoints/passages.rb +7 -6
  14. data/lib/biblesearch-api/endpoints/verses.rb +38 -24
  15. data/lib/biblesearch-api/endpoints/versions.rb +7 -2
  16. data/spec/README.md +32 -0
  17. data/spec/biblesearch-api/endpoints/books_spec.rb +42 -17
  18. data/spec/biblesearch-api/endpoints/chapters_spec.rb +53 -27
  19. data/spec/biblesearch-api/endpoints/fumsify_for_all_endpoints_spec.rb +22 -22
  20. data/spec/biblesearch-api/endpoints/passages_spec.rb +36 -4
  21. data/spec/biblesearch-api/endpoints/search_spec.rb +1 -1
  22. data/spec/biblesearch-api/endpoints/verses_spec.rb +53 -19
  23. data/spec/biblesearch-api/endpoints/versions_spec.rb +10 -4
  24. data/spec/biblesearch-api_spec.rb +1 -1
  25. data/spec/cassettes/biblesearch-api_spec-test_0001_has_a_http_response_code_other_than_200.yml +644 -0
  26. data/spec/cassettes/biblesearch-api_spec-test_0001_has_a_nil_fums_same_singular_and_plural_behavior_as_good_.yml +329 -0
  27. data/spec/cassettes/biblesearch-api_spec-test_0001_has_fums_in_the_metadata.yml +318 -0
  28. data/spec/cassettes/biblesearch-api_spec-test_0001_has_metadata.yml +318 -0
  29. data/spec/cassettes/biblesearch-api_spec-test_0001_returns_a_mash_with_a_collection_and_a_fums.yml +318 -0
  30. data/spec/cassettes/biblesearch-api_spec-test_0001_returns_a_mash_with_a_value_and_a_fums.yml +318 -0
  31. data/spec/cassettes/biblesearch-api_spec-test_0002_has_a_http_response_code_in_the_metadata.yml +318 -0
  32. data/spec/cassettes/biblesearch-api_spec-test_0002_has_a_message_in_the_metadata.yml +644 -0
  33. data/spec/cassettes/biblesearch-api_spec-test_0002_has_a_real_response.yml +318 -0
  34. data/spec/cassettes/biblesearch-api_spec-test_0003_has_a_nil_response.yml +644 -0
  35. data/spec/cassettes/biblesearch-api_spec-test_0003_has_a_response.yml +318 -0
  36. data/spec/cassettes/endpoint-books_spec-test_0001_has_a_book_value.yml +51 -0
  37. data/spec/cassettes/endpoint-books_spec-test_0001_has_a_collection.yml +704 -0
  38. data/spec/cassettes/endpoint-books_spec-test_0001_requires_a_version_id.yml +347 -0
  39. data/spec/cassettes/endpoint-books_spec-test_0001_returns_nil.yml +330 -0
  40. data/spec/cassettes/endpoint-books_spec-test_0001_returns_the_same_thing_as_the_equivalent_string_sig.yml +99 -0
  41. data/spec/cassettes/endpoint-books_spec-test_0002_accepts_an_optional_testament_id.yml +182 -0
  42. data/spec/cassettes/endpoint-books_spec-test_0002_contains_books_with_chapters.yml +360 -0
  43. data/spec/cassettes/endpoint-books_spec-test_0002_contains_books_without_chapters.yml +347 -0
  44. data/spec/cassettes/endpoint-chapters_spec-test_0001_doesn_t_raise_an_ArgumentError.yml +328 -0
  45. data/spec/cassettes/endpoint-chapters_spec-test_0001_has_a_chapter_value.yml +103 -0
  46. data/spec/cassettes/endpoint-chapters_spec-test_0001_has_a_collection.yml +72 -0
  47. data/spec/cassettes/endpoint-chapters_spec-test_0001_returns_an_empty_array.yml +332 -0
  48. data/spec/cassettes/endpoint-chapters_spec-test_0001_returns_nil.yml +332 -0
  49. data/spec/cassettes/endpoint-chapters_spec-test_0001_returns_the_same_thing_as_the_equivalent_string_sig.yml +341 -0
  50. data/spec/cassettes/endpoint-chapters_spec-test_0002_has_verses.yml +103 -0
  51. data/spec/cassettes/endpoint-chapters_spec-test_0002_should_contain_chapters.yml +72 -0
  52. data/spec/cassettes/endpoint-chapters_spec-test_0003_can_be_requested_without_marginalia.yml +103 -0
  53. data/spec/cassettes/endpoint-chapters_spec-test_0004_can_be_requested_with_marginalia.yml +118 -0
  54. data/spec/cassettes/endpoint-passages_spec-test_0001_has_a_collection.yml +310 -0
  55. data/spec/cassettes/endpoint-passages_spec-test_0001_should_provide_the_passage_for_each_version_specified.yml +94 -0
  56. data/spec/cassettes/endpoint-passages_spec-test_0002_can_include_marginalia.yml +186 -0
  57. data/spec/cassettes/endpoint-passages_spec-test_0002_should_contain_a_single_passage.yml +90 -0
  58. data/spec/cassettes/endpoint-passages_spec-test_0002_should_contain_no_passages.yml +84 -0
  59. data/spec/cassettes/endpoint-passages_spec-test_0002_should_contain_passages.yml +142 -0
  60. data/spec/cassettes/endpoint-passages_spec-test_0003_can_include_marginalia.yml +457 -0
  61. data/spec/cassettes/endpoint-search_spec-test_0001_has_a_Hashie_Mash_value.yml +316 -0
  62. data/spec/cassettes/endpoint-search_spec-test_0001_returns_passages.yml +192 -0
  63. data/spec/cassettes/endpoint-search_spec-test_0001_returns_verses.yml +127 -0
  64. data/spec/cassettes/endpoint-verses_spec-test_0001_doesn_t_raise_an_ArgumentError.yml +386 -0
  65. data/spec/cassettes/endpoint-verses_spec-test_0001_has_a_collection.yml +119 -0
  66. data/spec/cassettes/endpoint-verses_spec-test_0001_has_a_verse_value.yml +55 -0
  67. data/spec/cassettes/endpoint-verses_spec-test_0001_returns_an_empty_array.yml +338 -0
  68. data/spec/cassettes/endpoint-verses_spec-test_0001_returns_nil.yml +331 -0
  69. data/spec/cassettes/endpoint-verses_spec-test_0001_returns_the_same_thing_as_the_equivalent_string_sig.yml +107 -0
  70. data/spec/cassettes/endpoint-verses_spec-test_0002_can_include_marginalia.yml +109 -0
  71. data/spec/cassettes/endpoint-verses_spec-test_0002_should_contain_one_verse.yml +57 -0
  72. data/spec/cassettes/endpoint-verses_spec-test_0002_should_contain_the_proper_number_of_verses.yml +65 -0
  73. data/spec/cassettes/endpoint-verses_spec-test_0003_can_include_marginalia.yml +235 -0
  74. data/spec/cassettes/endpoint-versions_spec-test_0001_a_nonexistent_version_with_a_language_code_returns_nil.yml +41 -0
  75. data/spec/cassettes/endpoint-versions_spec-test_0001_has_a_collection.yml +362 -0
  76. data/spec/cassettes/endpoint-versions_spec-test_0001_has_a_version_value.yml +54 -0
  77. data/spec/cassettes/endpoint-versions_spec-test_0001_should_return_only_those_representative_versions.yml +388 -0
  78. data/spec/cassettes/endpoint-versions_spec-test_0002_should_be_empty.yml +362 -0
  79. data/spec/cassettes/endpoint-versions_spec-test_0002_should_contain_versions.yml +318 -0
  80. data/spec/cassettes/fumsify_for_all_endpoints_spec-test_0001_has_real_fums_for_all_requests.yml +473 -0
  81. data/spec/cassettes/fumsify_for_all_endpoints_spec-test_0001_has_real_fums_for_all_valid_requests.yml +1036 -0
  82. data/spec/spec_helper.rb +39 -3
  83. metadata +173 -37
@@ -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
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  *.rbc
3
+ *.log
3
4
  .bundle
4
5
  .config
5
6
  .yardoc
@@ -12,9 +13,11 @@ lib/bundler/man
12
13
  pkg
13
14
  rdoc
14
15
  spec/reports
15
- spec/cassettes
16
+ #spec/cassettes
16
17
  test/tmp
17
18
  test/version_tmp
18
19
  tmp
19
20
  *~
20
21
  *.swp
22
+ .idea
23
+ API_KEY
@@ -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}'
@@ -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.3 - Client now uses version 2 of the API, all calls now mostly uniform.
2
- 0.0.2 - #versions and #verses now always respond in the plural, tested
3
- 0.0.1 - Basic functionality, no tests
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
- version = biblesearch.version('GNT')
28
- # You can also add a language to a singular version
29
- spanish_version = biblesearch.version('spa-GNT')
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('GNT')
39
+ books = biblesearch.books('spa-TLA')
33
40
  # You can also provide a testament
34
- old_testament_books = biblsearch.books('GNT', 'OT')
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 => 'GNT', :book_id => '2Tim')
43
+ book = biblesearch.book(:version_id => 'spa-TLA', :book_id => '2Tim')
37
44
  # ... or as a string
38
- book = biblesearch.book('GNT:2Tim')
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 => 'GNT', :book_id => '2Tim')
48
+ chapters = biblesearch.chapters(:version_id => 'spa-TLA', :book_id => '2Tim')
42
49
  # ... or string
43
- chapters = biblesearch.chapters('GNT:2Tim')
50
+ chapters = biblesearch.chapters('spa-TLA:2Tim')
44
51
  # A single chapter can be specified as a hash ...
45
- chapter = biblesearch.chapter(:version_id => 'GNT', :book_id => '2Tim', :chapter => 1)
52
+ chapter = biblesearch.chapter(:version_id => 'spa-TLA', :book_id => '2Tim', :chapter => 1)
46
53
  # ... or as a string
47
- chatper = biblesearch.chapter('GNT:2Tim.1')
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 => 'GNT', :book_id => 'Acts', :chapter => '8', :verse => '34')
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('GNT:Acts.8.34')
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 => 'KJV')
68
+ passages = biblesearch.passages('john 3:16', :version => 'eng-KJVA')
62
69
  # ... or for multiple versions
63
- passages = biblesearch.passages('john 3:16', :versions => ['KJV', 'CEV'])
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
- 2. Create your feature branch (`git checkout -b my-new-feature`)
78
- 3. Test against all supported rubies (`rake overtest` (see below))
79
- 4. Commit your changes (`git commit -am 'Added some feature'`)
80
- 5. Push to the branch (`git push origin my-new-feature`)
81
- 6. Create new Pull Request
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
- Rake::TestTask.new do |t|
14
- t.libs.push "spec"
15
- t.pattern = 'spec/**/*_spec.rb'
16
- t.verbose = true
17
- end
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
+
@@ -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
@@ -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
- def mashup(response)
47
- response = Hashie::Mash.new(response)
48
- # => raise BibleSearchError.new("Code #{response.code} -- #{response.desc}") unless response.stat == "ok"
49
- response
50
- end
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
- def get_mash(*args)
57
- api_response = self.class.get(*args)
58
- result = {}
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
- def pluralize_result(result)
72
- result.kind_of?(Array) ? result : [result]
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
- def fumsify(api_result, value)
76
- fumsified = Hashie::Mash.new
77
- fumsified.fums = api_result.meta.fums
76
+ def pluralize_result(result)
77
+ result.kind_of?(Array) ? result : [result]
78
+ end
78
79
 
79
- if value.kind_of?(Array)
80
- fumsified.collection = value
81
- else
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
- fumsified
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,3 +1,3 @@
1
1
  class BibleSearch
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  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, testament_id = nil)
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
- if book_sig.is_a?(Hash)
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
- return chapters("#{book_sig[:version_id]}:#{book_sig[:book_id]}")
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
- unless book_sig.match(/([A-Za-z0-9]+-)?[A-Za-z0-9]+:[A-Za-z0-9]+/)
13
- raise ArgumentError.new('Book signature must be in the form "VERSION_ID:BOOK_ID"')
14
- end
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
- chapters = []
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
- if chapter_sig.is_a?(Hash)
27
- unless required_keys_present?(chapter_sig, [:version_id, :book_id, :chapter])
28
- raise ArgumentError.new('Chapter signature hash must include :version_id, :book_id, and :chapter')
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
- unless chapter_sig.match(/([A-Za-z0-9]+-)?[A-Za-z0-9]+:[A-Za-z0-9]+\.[0-9]+/)
35
- raise ArgumentError.new('Chapter signature must be in the form "VERSION_ID:BOOK_ID.CHAPTER_NUMBER"')
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