Add RentCast & Realie integration for automatic property data and valuations

Merged
KI
4mo ago
+1812-27

Enter an address. Get the whole property.

Today, adding a property to Sure means a three-step manual wizard: type the
details, estimate your own market value, enter the address. This PR adds a
second path — pick an AVM (Automated Valuation Model) provider, enter a name
and a US address, and Sure fetches everything else for you in a single API
request:

  • šŸ  Property type (single family, condo, townhouse, multi-family, land, …)
  • šŸ“… Year built
  • šŸ“ Living area (square footage)
  • šŸ’° Current market value estimate — set as the account balance automatically

The account is created fully active with the address saved — no wizard steps,
no guessing your home's value from a listings site.

Two US providers are supported at launch, both with free tiers:

ProviderFree tierData source
RentCast50 requests/moAVM value estimate + property record in one call
Realie25 requests/moFull property record incl. model value in one call

Screenshots

API Keys Add Property RentCast Provider Address Entry Property Value 1 Property Value 2

How it works

  • Setup: Settings → Self-Hosting gets a "Property Valuation Providers"
    section. Keys are encrypted at rest, ENV-overridable
    (RENTCAST_API_KEY / REALIE_API_KEY), and show live monthly usage.
  • Add a property: when a key is configured, the existing "How would you
    like to add it?" selector offers Add via RentCast/Realie alongside manual
    entry. The lookup form reuses the manual flow's localized address fields.
  • One request per property: RentCast's /v1/avm/value is called with
    lookupSubjectAttributes=true so the value estimate and property record
    arrive together; Realie's address lookup returns the full record including
    its model value. No secondary calls.
  • Daily refresh, never hourly: a new SyncPropertyValuationsJob
    (daily, config/schedule.yml) keeps linked valuations current. It is
    deliberately excluded from hourly and manual family syncs.
  • Hard monthly caps: every request (lookup or refresh) counts against a
    per-provider monthly budget (50/25). At the cap, Sure stops calling the
    provider until the month rolls over — your quota can't be burned by the
    background job. Paid plans can raise the cap via
    RENTCAST_MAX_REQUESTS_PER_MONTH / REALIE_MAX_REQUESTS_PER_MONTH.
  • Manual entry is completely unchanged, and nothing changes for instances
    with no AVM keys configured.

Implementation notes

  • New :property_valuations registry concept with a shared
    Provider::PropertyValuationConcept interface — adding future AVM
    providers is a single class + registry entry
  • Property::AvmImport maps provider payloads onto the existing
    account/property/address models; unmapped property types leave the
    subtype blank rather than guessing
  • Two new columns on properties (avm_provider, avm_last_synced_on)
  • Follows existing provider conventions throughout (Faraday client,
    with_provider_response, RateLimitable, encrypted Setting fields,
    AlphaVantage-style limit counters)

Limitations

  • US addresses only (both providers are US-based)
  • Realie lookups filter by street + state (its API requires a county to
    filter by city, which the form doesn't collect)

Testing

  • 24 new/updated tests: provider clients (stubbed HTTP), rate-limit
    enforcement, ENV overrides, daily job behavior, controller create/error
    flows, view rendering — all green, rubocop + erb_lint clean

šŸ¤– Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added AVM valuation support with RentCast and Realie, including an AVM method selector and provider-specific address dialogs to create properties from valuations.
    • Added RentCast/Realie API key fields to hosting settings with masked inputs and monthly usage visibility.
    • Introduced a daily scheduled sync to refresh eligible AVM valuations.
  • Bug Fixes
    • Improved sync reliability: failed valuation balance updates no longer mark properties as synced; failures are recorded with provider/account context.
  • Tests
    • Expanded coverage for the AVM wizard flow, provider mapping, sync behavior (including rate limits/budgeting), and error handling paths.