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.
- Gem name:
bibleql-ruby(require asbibleql) - Top-level module:
BibleQL(capital Q, capital L) - HTTP client: Faraday (~> 2.0)
- Production API:
https://bibleql-rails.onrender.com/graphql(configurable, may change when domain is purchased) - Auth:
Authorization: Bearer <api_key>header on every request. API key is required. - Source GraphQL API: lives at
/Users/lporras/apps/lporras/bibleql— check there for schema changes
bundle exec rspec # run all tests (49 specs)
bundle exec rspec spec/bibleql/client_spec.rb # run specific spec file
bundle exec rubocop # lint check
bundle exec rubocop -A # auto-fix lint issues
bundle exec rake # runs both rspec + rubocop (default task)lib/bibleql.rb # Entry point: BibleQL.configure, .client, .reset!
lib/bibleql/version.rb # BibleQL::VERSION
lib/bibleql/configuration.rb # Holds api_key, api_url, default_translation, timeout
lib/bibleql/errors.rb # Error hierarchy (see below)
lib/bibleql/resource.rb # Base class: to_h, ==, inspect for all resources
lib/bibleql/resources/*.rb # Data objects: Verse, Passage, Translation, Book, Language, LocalizedBook, Chapter, SearchResult
lib/bibleql/query_builder.rb # Module with class methods returning {query:, variables:} hashes
lib/bibleql/client.rb # Main class: 11 public methods, each calls QueryBuilder -> execute -> map to resources
- Client public method (e.g.
#passage) resolves translation, callsQueryBuilder.passage(...). - QueryBuilder returns
{ query: "...", variables: { ... } }with hardcoded GraphQL string. - Client#execute POSTs to API via Faraday, parses JSON, checks for HTTP/GraphQL errors.
- Client#map_ methods* convert camelCase JSON keys to snake_case hashes.
- Resource constructor receives the hash, sets attributes via
attr_accessor.
BibleQL::Error < StandardError
├── ConfigurationError # missing api_key
├── ConnectionError # network failures
│ └── TimeoutError # request timeout
├── APIError (status, body) # generic HTTP error
│ ├── AuthenticationError # 401
│ ├── RateLimitError # 429
│ └── ServerError # 5xx
└── QueryError (errors array) # GraphQL errors in response
└── NotFoundError # "not found" in error message
- GraphQL fields: camelCase (e.g.
bookId,translationName,verseCount) - Ruby attributes: snake_case (e.g.
book_id,translation_name,verse_count) - Mapping: done in
Client#map_*private methods (e.g.map_verse,map_passage)
- Check the GraphQL schema at
/Users/lporras/apps/lporras/bibleql/app/graphql/types/query_type.rbfor the query name, arguments, and return type. - Add a method to
QueryBuilder(lib/bibleql/query_builder.rb): return{ query: "...", variables: { ... } }. Use camelCase in the GraphQL string. - Add a public method to
Client(lib/bibleql/client.rb): call the QueryBuilder, execute, map response to resource objects. Add amap_*private method if the response has a new shape. - Add/update Resource if needed (
lib/bibleql/resources/): create a new class extendingResourcewithattr_accessorfor each field. For nested objects, define a custom setter (seePassage#verses=). - Register the resource in
lib/bibleql.rbwithrequire_relative. - Write tests:
spec/bibleql/query_builder_spec.rb— verify variables and query string.spec/bibleql/client_spec.rb— stub withstub_graphql_success(...)helper, assert return types.spec/bibleql/resources/*_spec.rb— if new resource, test construction and nested wrapping.
- Create
lib/bibleql/resources/my_thing.rb:module BibleQL class MyThing < Resource attr_accessor :field_one, :field_two end end
- For nested resources, define a custom setter:
attr_reader :items def items=(list) @items = (list || []).map { |i| i.is_a?(Item) ? i : Item.new(i) } end
- Add
require_relative "bibleql/resources/my_thing"tolib/bibleql.rb.
- WebMock blocks all real HTTP. Specs use three helpers in
client_spec.rb:stub_graphql_success(data_hash)— 200 with{"data": ...}stub_graphql_errors(errors_array)— 200 with{"data": null, "errors": [...]}stub_graphql_http_error(status)— non-200 HTTP response
- BibleQL.reset! is called
before(:each)inspec_helper.rb. - Client specs must pass
api_key: "test_key"toClient.new. - Use
expect_with :rspecsyntax only (noshould).
frozen_string_literal: trueon every Ruby file.- Double quotes for strings (enforced by rubocop).
- No documentation cops (Style/Documentation is disabled).
query_builder.rbis exempt from MethodLength (GraphQL strings are long).- Specs are exempt from BlockLength and LineLength.