PaperTiger.Hydrator (PaperTiger v1.0.2)

Copy Markdown View Source

Expands nested object references based on expand[] query parameters.

Stripe allows expanding related objects in responses. Instead of returning just an ID, the full object is returned.

Examples

# Without expansion
%Subscription{customer: "cus_123"}

# With expand[]=customer
%Subscription{customer: %Customer{id: "cus_123", email: "..."}}

# Nested expansion: expand[]=customer.default_source
%Subscription{
  customer: %Customer{
    id: "cus_123",
    default_source: %Card{id: "card_123", last4: "4242"}
  }
}

Usage

# In resource handlers
expand_params = parse_expand_params(conn.query_params)
hydrated = PaperTiger.Hydrator.hydrate(subscription, expand_params)

Summary

Functions

Fetches a resource by ID from the appropriate store.

Hydrates a resource by expanding specified fields. ...

Functions

fetch_by_id(id)

@spec fetch_by_id(String.t()) :: {:ok, map()} | {:error, :not_found | :unknown_prefix}

Fetches a resource by ID from the appropriate store.

Automatically determines the correct store based on the ID prefix.

hydrate(resource, expand_params)

@spec hydrate(map() | struct(), [String.t()]) :: map() | struct()

Hydrates a resource by expanding specified fields. ...