anvil-ruby is a Ruby gem providing a client for the Anvil API — a document automation platform for PDF filling, PDF generation, e-signatures, and webhooks.
- Version: 0.1.0
- Ruby: >= 2.5.0 (developed on 3.4.8 via rbenv)
- License: MIT
- Repo: https://github.com/nickMarz/Ruby-Anvil
- API coverage: ~30% implemented
bundle install # Install dependencies
bundle exec rspec # Run tests
bundle exec rspec --format documentation # Verbose test output
bundle exec rubocop # Lint / style check
bundle exec rake install # Install gem locally
gem build anvil-ruby.gemspec # Build the gemAlways run bundle exec rubocop and bundle exec rspec before committing.
lib/
anvil.rb # Entry point, module-level configuration
anvil/
version.rb # VERSION constant
configuration.rb # Configuration class (api_key, environment, timeouts)
client.rb # HTTP client (Net::HTTP), auth, request building
errors.rb # Error hierarchy (APIError, ValidationError, etc.)
rate_limiter.rb # Retry with exponential backoff
response.rb # Response wrapper (JSON parsing, rate-limit headers)
env_loader.rb # Custom .env file parser (no dotenv dependency)
resources/
base.rb # Base resource class (ActiveRecord-like attributes)
pdf.rb # PDF.fill, PDF.generate, PDF.generate_from_html/markdown
signature.rb # Signature packets (create, find, list) via GraphQL
webhook.rb # Webhook parsing, token verification, decryption
- Resource-based architecture — resources inherit from
Resources::Basewhich provides attribute accessors viamethod_missing, serialization, and a class-levelclient. - Zero runtime dependencies — only Ruby stdlib (
net/http,json,base64,uri,openssl). Thebase64gem is added for Ruby 3.4+ compatibility. - GraphQL for signatures —
Signatureresource posts tohttps://graphql.useanvil.com/(full URL, not relative path). - REST for PDFs —
PDFresource uses REST endpoints athttps://app.useanvil.com/api/v1/. - Multi-tenancy — per-request
api_key:override on resource methods. - Configuration — three methods:
Anvil.configureblock,Anvil.api_key=, orANVIL_API_KEYenv var.
- Framework: RSpec (with
--format documentationand--colorvia.rspec) - HTTP mocking: WebMock + VCR (optional; loaded if available)
- Spec structure mirrors
lib/— e.g.,spec/anvil/resources/pdf_spec.rb - Config is reset before each test;
ANVIL_API_KEYis stubbed to'test_api_key' - Use
:configuredmetadata tag for tests that needAnvil.configurecalled
- RuboCop with
rubocop-rspec(see.rubocop.yml) - Single quotes for strings
frozen_string_literal: truein every file- Max line length: 120
- Max method length: 25
- No
Style/Documentationenforcement - Idiomatic Ruby: predicate methods (
complete?,draft?), bang methods (reload!,save_as!)
Anvil::Error
├── ConfigurationError
├── APIError
│ ├── ValidationError
│ ├── AuthenticationError
│ ├── RateLimitError
│ ├── NotFoundError
│ └── ServerError
├── NetworkError
│ ├── TimeoutError
│ └── ConnectionError
├── FileError
│ ├── FileNotFoundError
│ └── FileTooLargeError
└── WebhookError
└── WebhookVerificationError
| Variable | Purpose |
|---|---|
ANVIL_API_KEY |
API key for Anvil |
ANVIL_WEBHOOK_TOKEN |
Token for webhook verification |
ANVIL_TEMPLATE_ID |
Template EID for testing |
ANVIL_ENV |
Environment override (development / production) |
ANVIL_RSA_PRIVATE_KEY_PATH |
RSA key for webhook decryption |
- GitHub Actions — CI pipeline in
.github/workflows/ci.yml(tests, lint, security) - Gem publishing —
.github/workflows/gem-push.yml(triggered by version tags likev0.2.0) - Dependabot — weekly dependency updates
- Update
lib/anvil/version.rb - Update
CHANGELOG.md - Commit and tag:
git tag v0.x.x - Push:
git push origin main --tags
- Zero runtime dependencies — use only Ruby stdlib
- Rails-friendly but framework-agnostic
- Semantic versioning; all new features are additive (no breaking changes)
- Document new features in CHANGELOG.md and API_COVERAGE.md
- Write RSpec tests for all new functionality