Class: Axn::Webhooks::Outbound::Subscriber

Inherits:
Data
  • Object
show all
Defined in:
lib/axn/webhooks/outbound/subscriber.rb

Overview

A resolved fan-out target: a URL plus an optional subscriber identity. id is what survives the round trip through Deliver's call_async re-enqueue (see deliver.rb's subscriber_id expects) — it is NEVER a secret/token, which would otherwise sit plaintext in the queue backend for the life of a retry chain. Credentials are resolved per attempt from this identity instead (see Signer's subscriber: kwarg).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, id: nil) ⇒ Subscriber

Returns a new instance of Subscriber.



12
13
14
# File 'lib/axn/webhooks/outbound/subscriber.rb', line 12

def initialize(url:, id: nil)
  super
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



11
12
13
# File 'lib/axn/webhooks/outbound/subscriber.rb', line 11

def id
  @id
end

#urlObject (readonly)

Returns the value of attribute url

Returns:

  • (Object)

    the current value of url



11
12
13
# File 'lib/axn/webhooks/outbound/subscriber.rb', line 11

def url
  @url
end

Class Method Details

.coerce(raw) ⇒ Object

Normalizes whatever a static to: Array entry or a subscribers/to: lambda returned: already a Subscriber -> passed through; a bare String -> today's shape, id: nil; a Hash (Symbol or String keys) -> must include :url, may include :id (stringified so a caller can hand back an ActiveRecord id directly). Anything else -- including an unknown Hash key, e.g. { url:, secret: } -- raises loudly rather than silently dropping a field the caller thought they were setting (Codex-style finding this design heads off).



23
24
25
26
27
28
29
30
31
32
# File 'lib/axn/webhooks/outbound/subscriber.rb', line 23

def coerce(raw)
  case raw
  when Subscriber then coerce_subscriber(raw)
  when String then new(url: raw, id: nil)
  when Hash then coerce_hash(raw)
  else
    raise Axn::Webhooks::InvalidTarget,
          "must be a String URL or a Hash (got #{raw.class})"
  end
end