bibleql-ruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6d7b19f7f5f649f8a05b77edc0649af6fd8d36fa002627f5c514ec4b010dd40c
4
+ data.tar.gz: de3ae470eaafd050cb00982688c2bef14eba3be6dc0ee0131d7ce5a10be16a8a
5
+ SHA512:
6
+ metadata.gz: 6687cad36d04efe03e7f0be1bde2000497fc039619d395bb3394006a237a7f168d18afdbd2f1f39b6d19e2653ab560018beafe4bf7c3ab4d94328a6b2a787c32
7
+ data.tar.gz: f3859573ec3389c3f1a472f350b37765fb40078957a6f7c043ee9aa5dd6510badd330d49f4da3e9cb1aa6e1d0205808d567769301ec3e23cff604494f72f64cd
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-04-05
4
+
5
+ - Initial release
data/CLAUDE.md ADDED
@@ -0,0 +1,113 @@
1
+ # CLAUDE.md — BibleQL Ruby Gem
2
+
3
+ ## What is this project?
4
+
5
+ `bibleql-ruby` is a Ruby client gem for the BibleQL GraphQL API. It lets Ruby developers query Bible verses, passages, and translations without writing GraphQL directly.
6
+
7
+ - **Gem name**: `bibleql-ruby` (require as `bibleql`)
8
+ - **Top-level module**: `BibleQL` (capital Q, capital L)
9
+ - **HTTP client**: Faraday (~> 2.0)
10
+ - **Production API**: `https://bibleql-rails.onrender.com/graphql` (configurable, may change when domain is purchased)
11
+ - **Auth**: `Authorization: Bearer <api_key>` header on every request. API key is required.
12
+ - **Source GraphQL API**: lives at `/Users/lporras/apps/lporras/bibleql` — check there for schema changes
13
+
14
+ ## Commands
15
+
16
+ ```bash
17
+ bundle exec rspec # run all tests (49 specs)
18
+ bundle exec rspec spec/bibleql/client_spec.rb # run specific spec file
19
+ bundle exec rubocop # lint check
20
+ bundle exec rubocop -A # auto-fix lint issues
21
+ bundle exec rake # runs both rspec + rubocop (default task)
22
+ ```
23
+
24
+ ## Architecture
25
+
26
+ ```
27
+ lib/bibleql.rb # Entry point: BibleQL.configure, .client, .reset!
28
+ lib/bibleql/version.rb # BibleQL::VERSION
29
+ lib/bibleql/configuration.rb # Holds api_key, api_url, default_translation, timeout
30
+ lib/bibleql/errors.rb # Error hierarchy (see below)
31
+ lib/bibleql/resource.rb # Base class: to_h, ==, inspect for all resources
32
+ lib/bibleql/resources/*.rb # Data objects: Verse, Passage, Translation, Book, Language, LocalizedBook, Chapter, SearchResult
33
+ lib/bibleql/query_builder.rb # Module with class methods returning {query:, variables:} hashes
34
+ lib/bibleql/client.rb # Main class: 11 public methods, each calls QueryBuilder -> execute -> map to resources
35
+ ```
36
+
37
+ ### Data flow for a client method
38
+
39
+ 1. **Client public method** (e.g. `#passage`) resolves translation, calls `QueryBuilder.passage(...)`.
40
+ 2. **QueryBuilder** returns `{ query: "...", variables: { ... } }` with hardcoded GraphQL string.
41
+ 3. **Client#execute** POSTs to API via Faraday, parses JSON, checks for HTTP/GraphQL errors.
42
+ 4. **Client#map_* methods** convert camelCase JSON keys to snake_case hashes.
43
+ 5. **Resource constructor** receives the hash, sets attributes via `attr_accessor`.
44
+
45
+ ### Error hierarchy
46
+
47
+ ```
48
+ BibleQL::Error < StandardError
49
+ ├── ConfigurationError # missing api_key
50
+ ├── ConnectionError # network failures
51
+ │ └── TimeoutError # request timeout
52
+ ├── APIError (status, body) # generic HTTP error
53
+ │ ├── AuthenticationError # 401
54
+ │ ├── RateLimitError # 429
55
+ │ └── ServerError # 5xx
56
+ └── QueryError (errors array) # GraphQL errors in response
57
+ └── NotFoundError # "not found" in error message
58
+ ```
59
+
60
+ ### Naming conventions
61
+
62
+ - **GraphQL fields**: camelCase (e.g. `bookId`, `translationName`, `verseCount`)
63
+ - **Ruby attributes**: snake_case (e.g. `book_id`, `translation_name`, `verse_count`)
64
+ - **Mapping**: done in `Client#map_*` private methods (e.g. `map_verse`, `map_passage`)
65
+
66
+ ## How to add a new API query
67
+
68
+ 1. **Check the GraphQL schema** at `/Users/lporras/apps/lporras/bibleql/app/graphql/types/query_type.rb` for the query name, arguments, and return type.
69
+ 2. **Add a method to `QueryBuilder`** (`lib/bibleql/query_builder.rb`): return `{ query: "...", variables: { ... } }`. Use camelCase in the GraphQL string.
70
+ 3. **Add a public method to `Client`** (`lib/bibleql/client.rb`): call the QueryBuilder, execute, map response to resource objects. Add a `map_*` private method if the response has a new shape.
71
+ 4. **Add/update Resource** if needed (`lib/bibleql/resources/`): create a new class extending `Resource` with `attr_accessor` for each field. For nested objects, define a custom setter (see `Passage#verses=`).
72
+ 5. **Register the resource** in `lib/bibleql.rb` with `require_relative`.
73
+ 6. **Write tests**:
74
+ - `spec/bibleql/query_builder_spec.rb` — verify variables and query string.
75
+ - `spec/bibleql/client_spec.rb` — stub with `stub_graphql_success(...)` helper, assert return types.
76
+ - `spec/bibleql/resources/*_spec.rb` — if new resource, test construction and nested wrapping.
77
+
78
+ ## How to add a new Resource
79
+
80
+ 1. Create `lib/bibleql/resources/my_thing.rb`:
81
+ ```ruby
82
+ module BibleQL
83
+ class MyThing < Resource
84
+ attr_accessor :field_one, :field_two
85
+ end
86
+ end
87
+ ```
88
+ 2. For nested resources, define a custom setter:
89
+ ```ruby
90
+ attr_reader :items
91
+ def items=(list)
92
+ @items = (list || []).map { |i| i.is_a?(Item) ? i : Item.new(i) }
93
+ end
94
+ ```
95
+ 3. Add `require_relative "bibleql/resources/my_thing"` to `lib/bibleql.rb`.
96
+
97
+ ## Testing patterns
98
+
99
+ - **WebMock** blocks all real HTTP. Specs use three helpers in `client_spec.rb`:
100
+ - `stub_graphql_success(data_hash)` — 200 with `{"data": ...}`
101
+ - `stub_graphql_errors(errors_array)` — 200 with `{"data": null, "errors": [...]}`
102
+ - `stub_graphql_http_error(status)` — non-200 HTTP response
103
+ - **BibleQL.reset!** is called `before(:each)` in `spec_helper.rb`.
104
+ - Client specs must pass `api_key: "test_key"` to `Client.new`.
105
+ - Use `expect_with :rspec` syntax only (no `should`).
106
+
107
+ ## Style
108
+
109
+ - `frozen_string_literal: true` on every Ruby file.
110
+ - Double quotes for strings (enforced by rubocop).
111
+ - No documentation cops (Style/Documentation is disabled).
112
+ - `query_builder.rb` is exempt from MethodLength (GraphQL strings are long).
113
+ - Specs are exempt from BlockLength and LineLength.
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "bibleql-ruby" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["lporras16@gmail.com"](mailto:"lporras16@gmail.com").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Luis Porras
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # BibleQL Ruby
2
+
3
+ An idiomatic Ruby client for the [BibleQL](https://bibleql-rails.onrender.com) GraphQL API. Query Bible verses, passages, and translations across ~43 translations without writing GraphQL.
4
+
5
+ ## Installation
6
+
7
+ Add to your Gemfile:
8
+
9
+ ```ruby
10
+ gem "bibleql-ruby"
11
+ ```
12
+
13
+ Then run `bundle install`, or install directly:
14
+
15
+ ```
16
+ gem install bibleql-ruby
17
+ ```
18
+
19
+ ## Configuration
20
+
21
+ ```ruby
22
+ require "bibleql"
23
+
24
+ BibleQL.configure do |config|
25
+ config.api_key = "bql_live_..." # required - your BibleQL API key
26
+ config.default_translation = "spa-bes" # optional, defaults to "eng-web"
27
+ config.api_url = "https://custom-host.com/graphql" # optional, defaults to production
28
+ config.timeout = 60 # optional, defaults to 30 seconds
29
+ end
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ```ruby
35
+ client = BibleQL.client
36
+ # or with per-instance config:
37
+ client = BibleQL::Client.new(api_key: "bql_live_...", default_translation: "spa-bes")
38
+ ```
39
+
40
+ ### Passages
41
+
42
+ ```ruby
43
+ passage = client.passage("John 3:16")
44
+ passage.reference # => "John 3:16"
45
+ passage.text # => "For God so loved the world..."
46
+ passage.verses # => [#<BibleQL::Verse ...>]
47
+ passage.translation_id # => "eng-web"
48
+
49
+ # With a specific translation
50
+ client.passage("Juan 3:16", translation: "spa-bes")
51
+ ```
52
+
53
+ ### Verses
54
+
55
+ ```ruby
56
+ verse = client.verse("MAT", 5, 3)
57
+ verse.book_name # => "Matthew"
58
+ verse.chapter # => 5
59
+ verse.verse # => 3
60
+ verse.text # => "Blessed are the poor in spirit..."
61
+ ```
62
+
63
+ ### Chapters
64
+
65
+ ```ruby
66
+ verses = client.chapter("MAT", 5)
67
+ # => [#<BibleQL::Verse ...>, ...]
68
+ ```
69
+
70
+ ### Random Verse
71
+
72
+ ```ruby
73
+ client.random_verse
74
+ client.random_verse(testament: "NT")
75
+ client.random_verse(books: "PSA")
76
+ ```
77
+
78
+ ### Search
79
+
80
+ ```ruby
81
+ results = client.search("love", limit: 10)
82
+ # => [#<BibleQL::Verse ...>, ...]
83
+ ```
84
+
85
+ ### Verse of the Day
86
+
87
+ ```ruby
88
+ passage = client.verse_of_the_day
89
+ passage = client.verse_of_the_day(date: "2026-01-01")
90
+ ```
91
+
92
+ ### Translations
93
+
94
+ ```ruby
95
+ translations = client.translations
96
+ # => [#<BibleQL::Translation identifier="eng-web" ...>, ...]
97
+
98
+ translation = client.translation("eng-web")
99
+ translation.name # => "World English Bible"
100
+ translation.books # => [#<BibleQL::LocalizedBook ...>, ...]
101
+ ```
102
+
103
+ ### Languages
104
+
105
+ ```ruby
106
+ languages = client.languages
107
+ languages.first.code # => "eng"
108
+ languages.first.translation_count # => 5
109
+ languages.first.translations # => [#<BibleQL::Translation ...>, ...]
110
+ ```
111
+
112
+ ### Books
113
+
114
+ ```ruby
115
+ books = client.books
116
+ # => [#<BibleQL::Book book_id="GEN" name="Genesis" ...>, ...]
117
+ ```
118
+
119
+ ### Bible Index
120
+
121
+ ```ruby
122
+ index = client.bible_index
123
+ # => [#<BibleQL::LocalizedBook ...>, ...]
124
+ index.first.chapters # => [#<BibleQL::Chapter number=1 verse_count=31>, ...]
125
+ ```
126
+
127
+ ## Error Handling
128
+
129
+ ```ruby
130
+ begin
131
+ client.passage("Invalid Reference")
132
+ rescue BibleQL::NotFoundError => e
133
+ puts "Not found: #{e.message}"
134
+ rescue BibleQL::AuthenticationError
135
+ puts "Invalid API key"
136
+ rescue BibleQL::RateLimitError
137
+ puts "Too many requests"
138
+ rescue BibleQL::ServerError
139
+ puts "Server error"
140
+ rescue BibleQL::TimeoutError
141
+ puts "Request timed out"
142
+ rescue BibleQL::ConnectionError
143
+ puts "Connection failed"
144
+ rescue BibleQL::QueryError => e
145
+ puts "GraphQL error: #{e.message}"
146
+ puts e.errors # raw error array from GraphQL
147
+ end
148
+ ```
149
+
150
+ ## Development
151
+
152
+ ```bash
153
+ bundle install
154
+ bundle exec rspec # run tests
155
+ bundle exec rubocop # run linter
156
+ ```
157
+
158
+ ## License
159
+
160
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,202 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "json"
5
+
6
+ module BibleQL
7
+ class Client
8
+ def initialize(api_key: nil, default_translation: nil, api_url: nil, timeout: nil)
9
+ config = BibleQL.configuration
10
+ @api_key = api_key || config.api_key
11
+ @default_translation = default_translation || config.default_translation
12
+ @api_url = api_url || config.api_url
13
+ @timeout = timeout || config.timeout
14
+
15
+ raise ConfigurationError, "api_key is required. Set it via BibleQL.configure or pass it to Client.new" unless @api_key
16
+
17
+ @connection = Faraday.new(url: @api_url) do |f|
18
+ f.options.timeout = @timeout
19
+ f.options.open_timeout = @timeout
20
+ f.headers["Content-Type"] = "application/json"
21
+ f.headers["Authorization"] = "Bearer #{@api_key}"
22
+ end
23
+ end
24
+
25
+ def translations
26
+ data = execute(QueryBuilder.translations, "translations")
27
+ data["translations"].map { |t| Translation.new(map_translation(t)) }
28
+ end
29
+
30
+ def translation(identifier)
31
+ data = execute(QueryBuilder.translation(identifier), "translation")
32
+ Translation.new(map_translation(data["translation"]))
33
+ end
34
+
35
+ def books
36
+ data = execute(QueryBuilder.books, "books")
37
+ data["books"].map { |b| Book.new(map_book(b)) }
38
+ end
39
+
40
+ def languages
41
+ data = execute(QueryBuilder.languages, "languages")
42
+ data["languages"].map { |l| Language.new(map_language(l)) }
43
+ end
44
+
45
+ def passage(reference, translation: nil)
46
+ t = translation || @default_translation
47
+ data = execute(QueryBuilder.passage(reference, translation: t), "passage")
48
+ Passage.new(map_passage(data["passage"]))
49
+ end
50
+
51
+ def chapter(book, chapter_num, translation: nil)
52
+ t = translation || @default_translation
53
+ data = execute(QueryBuilder.chapter(book, chapter_num, translation: t), "chapter")
54
+ data["chapter"].map { |v| Verse.new(map_verse(v)) }
55
+ end
56
+
57
+ def verse(book, chapter_num, verse_num, translation: nil)
58
+ t = translation || @default_translation
59
+ data = execute(QueryBuilder.verse(book, chapter_num, verse_num, translation: t), "verse")
60
+ Verse.new(map_verse(data["verse"]))
61
+ end
62
+
63
+ def random_verse(translation: nil, testament: nil, books: nil)
64
+ t = translation || @default_translation
65
+ data = execute(QueryBuilder.random_verse(translation: t, testament: testament, books: books), "randomVerse")
66
+ Verse.new(map_verse(data["randomVerse"]))
67
+ end
68
+
69
+ def search(query_text, translation: nil, limit: nil)
70
+ t = translation || @default_translation
71
+ data = execute(QueryBuilder.search(query_text, translation: t, limit: limit), "search")
72
+ data["search"].map { |v| Verse.new(map_verse(v)) }
73
+ end
74
+
75
+ def verse_of_the_day(translation: nil, date: nil)
76
+ t = translation || @default_translation
77
+ data = execute(QueryBuilder.verse_of_the_day(translation: t, date: date), "verseOfTheDay")
78
+ Passage.new(map_passage(data["verseOfTheDay"]))
79
+ end
80
+
81
+ def bible_index(translation: nil)
82
+ t = translation || @default_translation
83
+ data = execute(QueryBuilder.bible_index(translation: t), "bibleIndex")
84
+ data["bibleIndex"].map { |b| LocalizedBook.new(map_localized_book(b)) }
85
+ end
86
+
87
+ private
88
+
89
+ def execute(query_hash, _query_name)
90
+ response = @connection.post do |req|
91
+ req.body = JSON.generate(query: query_hash[:query], variables: query_hash[:variables])
92
+ end
93
+
94
+ handle_http_errors(response)
95
+
96
+ body = JSON.parse(response.body)
97
+
98
+ handle_graphql_errors(body["errors"]) if body["errors"] && !body["errors"].empty?
99
+
100
+ body["data"]
101
+ rescue Faraday::TimeoutError => e
102
+ raise TimeoutError, "Request timed out: #{e.message}"
103
+ rescue Faraday::ConnectionFailed, Faraday::Error => e
104
+ raise ConnectionError, "Connection failed: #{e.message}"
105
+ end
106
+
107
+ def handle_http_errors(response)
108
+ return if response.status >= 200 && response.status < 300
109
+
110
+ message = "HTTP #{response.status}"
111
+ case response.status
112
+ when 401
113
+ raise AuthenticationError.new(message, status: response.status, body: response.body)
114
+ when 429
115
+ raise RateLimitError.new(message, status: response.status, body: response.body)
116
+ when 500..599
117
+ raise ServerError.new(message, status: response.status, body: response.body)
118
+ else
119
+ raise APIError.new(message, status: response.status, body: response.body)
120
+ end
121
+ end
122
+
123
+ def handle_graphql_errors(errors)
124
+ messages = errors.map { |e| e["message"] }
125
+ full_message = messages.join("; ")
126
+
127
+ raise NotFoundError.new(full_message, errors: errors) if messages.any? { |m| m.downcase.include?("not found") }
128
+
129
+ raise QueryError.new(full_message, errors: errors)
130
+ end
131
+
132
+ def map_verse(data)
133
+ {
134
+ book_id: data["bookId"],
135
+ book_name: data["bookName"],
136
+ chapter: data["chapter"],
137
+ verse: data["verse"],
138
+ text: data["text"]
139
+ }
140
+ end
141
+
142
+ def map_passage(data)
143
+ {
144
+ reference: data["reference"],
145
+ translation_id: data["translationId"],
146
+ translation_name: data["translationName"],
147
+ translation_note: data["translationNote"],
148
+ text: data["text"],
149
+ verses: (data["verses"] || []).map { |v| map_verse(v) }
150
+ }
151
+ end
152
+
153
+ def map_translation(data)
154
+ result = {
155
+ identifier: data["identifier"],
156
+ name: data["name"],
157
+ language: data["language"],
158
+ note: data["note"]
159
+ }
160
+ result[:books] = data["books"].map { |b| map_localized_book(b) } if data["books"]
161
+ result
162
+ end
163
+
164
+ def map_book(data)
165
+ {
166
+ book_id: data["bookId"],
167
+ name: data["name"],
168
+ testament: data["testament"],
169
+ position: data["position"]
170
+ }
171
+ end
172
+
173
+ def map_language(data)
174
+ {
175
+ code: data["code"],
176
+ translation_count: data["translationCount"],
177
+ translations: (data["translations"] || []).map { |t| map_translation(t) }
178
+ }
179
+ end
180
+
181
+ def map_localized_book(data)
182
+ result = {
183
+ book_id: data["bookId"],
184
+ name: data["name"],
185
+ testament: data["testament"],
186
+ position: data["position"],
187
+ chapter_count: data["chapterCount"]
188
+ }
189
+ result[:chapters] = data["chapters"].map { |c| map_chapter(c) } if data["chapters"]
190
+ result
191
+ end
192
+
193
+ def map_chapter(data)
194
+ result = {
195
+ number: data["number"],
196
+ verse_count: data["verseCount"]
197
+ }
198
+ result[:verses] = data["verses"].map { |v| map_verse(v) } if data["verses"]
199
+ result
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BibleQL
4
+ class Configuration
5
+ attr_accessor :api_key, :api_url, :default_translation, :timeout
6
+
7
+ DEFAULT_API_URL = "https://bibleql-rails.onrender.com/graphql"
8
+ DEFAULT_TRANSLATION = "eng-web"
9
+ DEFAULT_TIMEOUT = 30
10
+
11
+ def initialize
12
+ @api_key = nil
13
+ @api_url = DEFAULT_API_URL
14
+ @default_translation = DEFAULT_TRANSLATION
15
+ @timeout = DEFAULT_TIMEOUT
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BibleQL
4
+ class Error < StandardError; end
5
+
6
+ class ConfigurationError < Error; end
7
+
8
+ class ConnectionError < Error; end
9
+
10
+ class TimeoutError < ConnectionError; end
11
+
12
+ class APIError < Error
13
+ attr_reader :status, :body
14
+
15
+ def initialize(message = nil, status: nil, body: nil)
16
+ @status = status
17
+ @body = body
18
+ super(message)
19
+ end
20
+ end
21
+
22
+ class AuthenticationError < APIError; end
23
+
24
+ class RateLimitError < APIError; end
25
+
26
+ class ServerError < APIError; end
27
+
28
+ class QueryError < Error
29
+ attr_reader :errors
30
+
31
+ def initialize(message = nil, errors: [])
32
+ @errors = errors
33
+ super(message)
34
+ end
35
+ end
36
+
37
+ class NotFoundError < QueryError; end
38
+ end
@@ -0,0 +1,219 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BibleQL
4
+ module QueryBuilder
5
+ module_function
6
+
7
+ def translations
8
+ {
9
+ query: <<~GQL,
10
+ query {
11
+ translations {
12
+ identifier
13
+ name
14
+ language
15
+ note
16
+ }
17
+ }
18
+ GQL
19
+ variables: {}
20
+ }
21
+ end
22
+
23
+ def translation(identifier)
24
+ {
25
+ query: <<~GQL,
26
+ query($identifier: String!) {
27
+ translation(identifier: $identifier) {
28
+ identifier
29
+ name
30
+ language
31
+ note
32
+ books {
33
+ bookId
34
+ name
35
+ testament
36
+ position
37
+ chapterCount
38
+ }
39
+ }
40
+ }
41
+ GQL
42
+ variables: { identifier: identifier }
43
+ }
44
+ end
45
+
46
+ def books
47
+ {
48
+ query: <<~GQL,
49
+ query {
50
+ books {
51
+ bookId
52
+ name
53
+ testament
54
+ position
55
+ }
56
+ }
57
+ GQL
58
+ variables: {}
59
+ }
60
+ end
61
+
62
+ def languages
63
+ {
64
+ query: <<~GQL,
65
+ query {
66
+ languages {
67
+ code
68
+ translationCount
69
+ translations {
70
+ identifier
71
+ name
72
+ language
73
+ note
74
+ }
75
+ }
76
+ }
77
+ GQL
78
+ variables: {}
79
+ }
80
+ end
81
+
82
+ def passage(reference, translation:)
83
+ {
84
+ query: <<~GQL,
85
+ query($reference: String!, $translation: String) {
86
+ passage(reference: $reference, translation: $translation) {
87
+ reference
88
+ translationId
89
+ translationName
90
+ translationNote
91
+ text
92
+ verses {
93
+ bookId
94
+ bookName
95
+ chapter
96
+ verse
97
+ text
98
+ }
99
+ }
100
+ }
101
+ GQL
102
+ variables: { reference: reference, translation: translation }
103
+ }
104
+ end
105
+
106
+ def chapter(book, chapter, translation:)
107
+ {
108
+ query: <<~GQL,
109
+ query($book: String!, $chapter: Int!, $translation: String) {
110
+ chapter(book: $book, chapter: $chapter, translation: $translation) {
111
+ bookId
112
+ bookName
113
+ chapter
114
+ verse
115
+ text
116
+ }
117
+ }
118
+ GQL
119
+ variables: { book: book, chapter: chapter, translation: translation }
120
+ }
121
+ end
122
+
123
+ def verse(book, chapter, verse, translation:)
124
+ {
125
+ query: <<~GQL,
126
+ query($book: String!, $chapter: Int!, $verse: Int!, $translation: String) {
127
+ verse(book: $book, chapter: $chapter, verse: $verse, translation: $translation) {
128
+ bookId
129
+ bookName
130
+ chapter
131
+ verse
132
+ text
133
+ }
134
+ }
135
+ GQL
136
+ variables: { book: book, chapter: chapter, verse: verse, translation: translation }
137
+ }
138
+ end
139
+
140
+ def random_verse(translation:, testament: nil, books: nil)
141
+ {
142
+ query: <<~GQL,
143
+ query($translation: String, $testament: String, $books: String) {
144
+ randomVerse(translation: $translation, testament: $testament, books: $books) {
145
+ bookId
146
+ bookName
147
+ chapter
148
+ verse
149
+ text
150
+ }
151
+ }
152
+ GQL
153
+ variables: { translation: translation, testament: testament, books: books }.compact
154
+ }
155
+ end
156
+
157
+ def search(query_text, translation:, limit: nil)
158
+ {
159
+ query: <<~GQL,
160
+ query($query: String!, $translation: String, $limit: Int) {
161
+ search(query: $query, translation: $translation, limit: $limit) {
162
+ bookId
163
+ bookName
164
+ chapter
165
+ verse
166
+ text
167
+ }
168
+ }
169
+ GQL
170
+ variables: { query: query_text, translation: translation, limit: limit }.compact
171
+ }
172
+ end
173
+
174
+ def verse_of_the_day(translation:, date: nil)
175
+ {
176
+ query: <<~GQL,
177
+ query($translation: String, $date: ISO8601Date) {
178
+ verseOfTheDay(translation: $translation, date: $date) {
179
+ reference
180
+ translationId
181
+ translationName
182
+ translationNote
183
+ text
184
+ verses {
185
+ bookId
186
+ bookName
187
+ chapter
188
+ verse
189
+ text
190
+ }
191
+ }
192
+ }
193
+ GQL
194
+ variables: { translation: translation, date: date }.compact
195
+ }
196
+ end
197
+
198
+ def bible_index(translation:)
199
+ {
200
+ query: <<~GQL,
201
+ query($translation: String) {
202
+ bibleIndex(translation: $translation) {
203
+ bookId
204
+ name
205
+ testament
206
+ position
207
+ chapterCount
208
+ chapters {
209
+ number
210
+ verseCount
211
+ }
212
+ }
213
+ }
214
+ GQL
215
+ variables: { translation: translation }
216
+ }
217
+ end
218
+ end
219
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BibleQL
4
+ class Resource
5
+ def initialize(attributes = {})
6
+ attributes.each do |key, value|
7
+ setter = "#{key}="
8
+ public_send(setter, value) if respond_to?(setter)
9
+ end
10
+ end
11
+
12
+ def to_h
13
+ instance_variables.each_with_object({}) do |ivar, hash|
14
+ key = ivar.to_s.delete_prefix("@").to_sym
15
+ value = instance_variable_get(ivar)
16
+ hash[key] = value.is_a?(Resource) ? value.to_h : value
17
+ end
18
+ end
19
+
20
+ def ==(other)
21
+ other.is_a?(self.class) && to_h == other.to_h
22
+ end
23
+
24
+ def to_s
25
+ "#<#{self.class.name} #{to_h.map { |k, v| "#{k}=#{v.inspect}" }.join(", ")}>"
26
+ end
27
+
28
+ alias inspect to_s
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BibleQL
4
+ class Book < Resource
5
+ attr_accessor :book_id, :name, :testament, :position
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BibleQL
4
+ class Chapter < Resource
5
+ attr_accessor :number, :verse_count
6
+
7
+ attr_reader :verses
8
+
9
+ def verses=(list)
10
+ @verses = (list || []).map do |v|
11
+ v.is_a?(Verse) ? v : Verse.new(v)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BibleQL
4
+ class Language < Resource
5
+ attr_accessor :code, :translation_count
6
+
7
+ attr_reader :translations
8
+
9
+ def translations=(list)
10
+ @translations = (list || []).map do |t|
11
+ t.is_a?(Translation) ? t : Translation.new(t)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BibleQL
4
+ class LocalizedBook < Resource
5
+ attr_accessor :book_id, :name, :testament, :position, :chapter_count
6
+
7
+ attr_reader :chapters
8
+
9
+ def chapters=(list)
10
+ @chapters = (list || []).map do |c|
11
+ c.is_a?(Chapter) ? c : Chapter.new(c)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BibleQL
4
+ class Passage < Resource
5
+ attr_accessor :reference, :translation_id, :translation_name, :translation_note, :text
6
+
7
+ attr_reader :verses
8
+
9
+ def verses=(list)
10
+ @verses = (list || []).map do |v|
11
+ v.is_a?(Verse) ? v : Verse.new(v)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BibleQL
4
+ class SearchResult < Resource
5
+ attr_accessor :total_count
6
+
7
+ attr_reader :verses
8
+
9
+ def verses=(list)
10
+ @verses = (list || []).map do |v|
11
+ v.is_a?(Verse) ? v : Verse.new(v)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BibleQL
4
+ class Translation < Resource
5
+ attr_accessor :identifier, :name, :language, :note
6
+
7
+ attr_reader :books
8
+
9
+ def books=(list)
10
+ @books = (list || []).map do |b|
11
+ b.is_a?(LocalizedBook) ? b : LocalizedBook.new(b)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BibleQL
4
+ class Verse < Resource
5
+ attr_accessor :book_id, :book_name, :chapter, :verse, :text
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BibleQL
4
+ VERSION = "0.1.0"
5
+ end
data/lib/bibleql.rb ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "bibleql/version"
4
+ require_relative "bibleql/configuration"
5
+ require_relative "bibleql/errors"
6
+ require_relative "bibleql/resource"
7
+ require_relative "bibleql/resources/verse"
8
+ require_relative "bibleql/resources/passage"
9
+ require_relative "bibleql/resources/translation"
10
+ require_relative "bibleql/resources/book"
11
+ require_relative "bibleql/resources/language"
12
+ require_relative "bibleql/resources/localized_book"
13
+ require_relative "bibleql/resources/chapter"
14
+ require_relative "bibleql/resources/search_result"
15
+ require_relative "bibleql/query_builder"
16
+ require_relative "bibleql/client"
17
+
18
+ module BibleQL
19
+ class << self
20
+ def configure
21
+ yield(configuration)
22
+ end
23
+
24
+ def configuration
25
+ @configuration ||= Configuration.new
26
+ end
27
+
28
+ def client
29
+ Client.new
30
+ end
31
+
32
+ def reset!
33
+ @configuration = Configuration.new
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,6 @@
1
+ module Bibleql
2
+ module Ruby
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bibleql-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luis Porras
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ description: An idiomatic Ruby client for querying Bible verses, passages, and translations
27
+ via the BibleQL GraphQL API.
28
+ email:
29
+ - lporras16@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - CLAUDE.md
36
+ - CODE_OF_CONDUCT.md
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - lib/bibleql.rb
41
+ - lib/bibleql/client.rb
42
+ - lib/bibleql/configuration.rb
43
+ - lib/bibleql/errors.rb
44
+ - lib/bibleql/query_builder.rb
45
+ - lib/bibleql/resource.rb
46
+ - lib/bibleql/resources/book.rb
47
+ - lib/bibleql/resources/chapter.rb
48
+ - lib/bibleql/resources/language.rb
49
+ - lib/bibleql/resources/localized_book.rb
50
+ - lib/bibleql/resources/passage.rb
51
+ - lib/bibleql/resources/search_result.rb
52
+ - lib/bibleql/resources/translation.rb
53
+ - lib/bibleql/resources/verse.rb
54
+ - lib/bibleql/version.rb
55
+ - sig/bibleql/ruby.rbs
56
+ homepage: https://github.com/lporras/bibleql-ruby
57
+ licenses:
58
+ - MIT
59
+ metadata:
60
+ homepage_uri: https://github.com/lporras/bibleql-ruby
61
+ source_code_uri: https://github.com/lporras/bibleql-ruby
62
+ changelog_uri: https://github.com/lporras/bibleql-ruby/blob/main/CHANGELOG.md
63
+ rubygems_mfa_required: 'true'
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 3.1.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 4.0.6
79
+ specification_version: 4
80
+ summary: Ruby client for the BibleQL GraphQL API
81
+ test_files: []