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
|