Class: BibleQL::Client
- Inherits:
-
Object
- Object
- BibleQL::Client
- Defined in:
- lib/bibleql/client.rb
Instance Method Summary collapse
- #bible_index(translation: nil) ⇒ Object
- #books ⇒ Object
- #chapter(book, chapter_num, translation: nil) ⇒ Object
-
#initialize(api_key: nil, default_translation: nil, api_url: nil, timeout: nil) ⇒ Client
constructor
A new instance of Client.
- #languages ⇒ Object
- #passage(reference, translation: nil) ⇒ Object
- #random_verse(translation: nil, testament: nil, books: nil) ⇒ Object
- #search(query_text, translation: nil, limit: nil) ⇒ Object
- #semantic_search(query_text, translation: nil, limit: nil) ⇒ Object
- #translation(identifier) ⇒ Object
- #translations ⇒ Object
- #verse(book, chapter_num, verse_num, translation: nil) ⇒ Object
- #verse_of_the_day(translation: nil, date: nil) ⇒ Object
Constructor Details
#initialize(api_key: nil, default_translation: nil, api_url: nil, timeout: nil) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bibleql/client.rb', line 8 def initialize(api_key: nil, default_translation: nil, api_url: nil, timeout: nil) config = BibleQL.configuration @api_key = api_key || config.api_key @default_translation = default_translation || config.default_translation @api_url = api_url || config.api_url @timeout = timeout || config.timeout raise ConfigurationError, "api_key is required. Set it via BibleQL.configure or pass it to Client.new" unless @api_key @connection = Faraday.new(url: @api_url) do |f| f..timeout = @timeout f..open_timeout = @timeout f.headers["Content-Type"] = "application/json" f.headers["Authorization"] = "Bearer #{@api_key}" end end |
Instance Method Details
#bible_index(translation: nil) ⇒ Object
87 88 89 90 91 |
# File 'lib/bibleql/client.rb', line 87 def bible_index(translation: nil) t = translation || @default_translation data = execute(QueryBuilder.bible_index(translation: t), "bibleIndex") data["bibleIndex"].map { |b| LocalizedBook.new(map_localized_book(b)) } end |
#books ⇒ Object
35 36 37 38 |
# File 'lib/bibleql/client.rb', line 35 def books data = execute(QueryBuilder.books, "books") data["books"].map { |b| Book.new(map_book(b)) } end |
#chapter(book, chapter_num, translation: nil) ⇒ Object
51 52 53 54 55 |
# File 'lib/bibleql/client.rb', line 51 def chapter(book, chapter_num, translation: nil) t = translation || @default_translation data = execute(QueryBuilder.chapter(book, chapter_num, translation: t), "chapter") data["chapter"].map { |v| Verse.new(map_verse(v)) } end |
#languages ⇒ Object
40 41 42 43 |
# File 'lib/bibleql/client.rb', line 40 def languages data = execute(QueryBuilder.languages, "languages") data["languages"].map { |l| Language.new(map_language(l)) } end |
#passage(reference, translation: nil) ⇒ Object
45 46 47 48 49 |
# File 'lib/bibleql/client.rb', line 45 def passage(reference, translation: nil) t = translation || @default_translation data = execute(QueryBuilder.passage(reference, translation: t), "passage") Passage.new(map_passage(data["passage"])) end |
#random_verse(translation: nil, testament: nil, books: nil) ⇒ Object
63 64 65 66 67 |
# File 'lib/bibleql/client.rb', line 63 def random_verse(translation: nil, testament: nil, books: nil) t = translation || @default_translation data = execute(QueryBuilder.random_verse(translation: t, testament: testament, books: books), "randomVerse") Verse.new(map_verse(data["randomVerse"])) end |
#search(query_text, translation: nil, limit: nil) ⇒ Object
69 70 71 72 73 |
# File 'lib/bibleql/client.rb', line 69 def search(query_text, translation: nil, limit: nil) t = translation || @default_translation data = execute(QueryBuilder.search(query_text, translation: t, limit: limit), "search") data["search"].map { |v| Verse.new(map_verse(v)) } end |
#semantic_search(query_text, translation: nil, limit: nil) ⇒ Object
75 76 77 78 79 |
# File 'lib/bibleql/client.rb', line 75 def semantic_search(query_text, translation: nil, limit: nil) t = translation || @default_translation data = execute(QueryBuilder.semantic_search(query_text, translation: t, limit: limit), "semanticSearch") data["semanticSearch"].map { |item| SemanticSearchResult.new(map_semantic_search_result(item)) } end |
#translation(identifier) ⇒ Object
30 31 32 33 |
# File 'lib/bibleql/client.rb', line 30 def translation(identifier) data = execute(QueryBuilder.translation(identifier), "translation") Translation.new(map_translation(data["translation"])) end |
#translations ⇒ Object
25 26 27 28 |
# File 'lib/bibleql/client.rb', line 25 def translations data = execute(QueryBuilder.translations, "translations") data["translations"].map { |t| Translation.new(map_translation(t)) } end |
#verse(book, chapter_num, verse_num, translation: nil) ⇒ Object
57 58 59 60 61 |
# File 'lib/bibleql/client.rb', line 57 def verse(book, chapter_num, verse_num, translation: nil) t = translation || @default_translation data = execute(QueryBuilder.verse(book, chapter_num, verse_num, translation: t), "verse") Verse.new(map_verse(data["verse"])) end |
#verse_of_the_day(translation: nil, date: nil) ⇒ Object
81 82 83 84 85 |
# File 'lib/bibleql/client.rb', line 81 def verse_of_the_day(translation: nil, date: nil) t = translation || @default_translation data = execute(QueryBuilder.verse_of_the_day(translation: t, date: date), "verseOfTheDay") Passage.new(map_passage(data["verseOfTheDay"])) end |