Module: BibleSearch::Books

Defined in:
lib/biblesearch-api/endpoints/books.rb

Instance Method Summary collapse

Instance Method Details

#book(book_sig) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/biblesearch-api/endpoints/books.rb', line 47

def book(book_sig)
  book_sig = valid_book(book_sig)

  api_result = get_mash("/books/#{book_sig}.js")
  if api_result.meta.http_code == 200
    book = nil
    book = api_result.response.books.first
    fumsify(api_result, book)
  else
    nil
  end

end

#books(version_id, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/biblesearch-api/endpoints/books.rb', line 22

def books(version_id, options={})
  defaults = {testament_id: nil, include_chapters: false}
  options = defaults.merge(options)
  testament_id = options[:testament_id]
  include_chapters = options[:include_chapters]

  api_endpoint = "/versions/#{version_id}/books.js"
  api_endpoint += "?testament=#{testament_id}" unless testament_id.nil?
  api_endpoint += "?include_chapters=true" if include_chapters

  unless @version_re.match(version_id)
    raise ArgumentError.new('version_id must be in the form "LANGUAGE_CODE-VERSION_ID:BOOK_ID"')
  end

  api_result = get_mash(api_endpoint)

  if api_result.meta.http_code == 200
    books = []
    books = pluralize_result(api_result.response.books)
    fumsify(api_result, books)
  else
    []
  end
end