Class: Nahook::Resources::Deliveries

Inherits:
Object
  • Object
show all
Defined in:
lib/nahook/resources/deliveries.rb

Overview

Read access to a workspace’s webhook deliveries via the Management API.

All methods are paginated or single-resource reads – this resource has no create/update/delete operations. Deliveries are produced by the ingestion path and consumed by the worker; the Management API exposes only their observable state.

Examples:

mgmt = Nahook::Management.new("nhm_token")

# List a page of deliveries for an endpoint
page = mgmt.deliveries.list("ws_abc123", "ep_def456", limit: 50)
page.data.each { |d| puts d["id"] }
next_page = mgmt.deliveries.list("ws_abc123", "ep_def456", cursor: page.next_cursor)

# Fetch a single delivery (metadata only)
delivery = mgmt.deliveries.get("ws_abc123", "del_xyz")

# Fetch with payload envelope
delivery = mgmt.deliveries.get("ws_abc123", "del_xyz", include_payload: true)

# List attempts (chronological order)
attempts = mgmt.deliveries.get_attempts("ws_abc123", "del_xyz")

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Deliveries

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Deliveries.

Parameters:



42
43
44
# File 'lib/nahook/resources/deliveries.rb', line 42

def initialize(http)
  @http = http
end

Instance Method Details

#get(workspace_id, delivery_id, include_payload: false) ⇒ Hash

Get a single delivery’s metadata, optionally including the payload envelope.

When include_payload is true, the response includes a “payload” envelope whose “status” is one of: “available”, “forbidden”, “processing”, “not_found”, “error”. The endpoint stays 200 for all 5 – the envelope status carries access-level reality. This method does NOT raise on “forbidden”/“processing”/“not_found”/“error”.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • delivery_id (String)

    the delivery public ID (starts with “del_”)

  • include_payload (Boolean) (defaults to: false)

    if true, sends ?include=payload and the response includes a “payload” envelope (default false).

Returns:

  • (Hash)

    the delivery; includes a “payload” envelope when include_payload is true.



81
82
83
84
85
86
87
88
# File 'lib/nahook/resources/deliveries.rb', line 81

def get(workspace_id, delivery_id, include_payload: false)
  query = include_payload ? { "include" => "payload" } : nil
  @http.request(
    method: :get,
    path: "/management/v1/workspaces/#{e(workspace_id)}/deliveries/#{e(delivery_id)}",
    query: query
  )
end

#get_attempts(workspace_id, delivery_id) ⇒ Array<Hash>

List delivery attempts for a single delivery, in chronological order (oldest first).

The attempt “status” field is an opaque string (“failed”, “success”, etc.) – treat it as a string, not an enum.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • delivery_id (String)

    the delivery public ID (starts with “del_”)

Returns:

  • (Array<Hash>)

    attempts in chronological order



99
100
101
102
103
104
# File 'lib/nahook/resources/deliveries.rb', line 99

def get_attempts(workspace_id, delivery_id)
  @http.request(
    method: :get,
    path: "/management/v1/workspaces/#{e(workspace_id)}/deliveries/#{e(delivery_id)}/attempts"
  )
end

#list(workspace_id, endpoint_id, limit: nil, cursor: nil, status: nil) ⇒ PaginatedResult

List deliveries for an endpoint, newest-first, with opaque cursor pagination.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • endpoint_id (String)

    the endpoint public ID

  • limit (Integer, nil) (defaults to: nil)

    page size, server-capped (default 50, max 100)

  • cursor (String, nil) (defaults to: nil)

    opaque cursor from a previous response’s PaginatedResult#next_cursor. Pass through unchanged.

  • status (String, nil) (defaults to: nil)

    filter by delivery status. One of: “pending”, “delivering”, “delivered”, “scheduled_retry”, “failed”, “dead_letter”.

Returns:

  • (PaginatedResult)

    paginated result whose data is an array of delivery hashes and next_cursor is a String or nil.



58
59
60
61
62
63
64
65
# File 'lib/nahook/resources/deliveries.rb', line 58

def list(workspace_id, endpoint_id, limit: nil, cursor: nil, status: nil)
  raw = @http.request(
    method: :get,
    path: "/management/v1/workspaces/#{e(workspace_id)}/endpoints/#{e(endpoint_id)}/deliveries",
    query: { "limit" => limit, "cursor" => cursor, "status" => status }
  )
  PaginatedResult.new(raw["deliveries"] || [], raw["nextCursor"])
end