Class: Nahook::Resources::Subscriptions

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

Overview

Resource for managing endpoint subscriptions via the Management API.

Subscriptions link event types to endpoints, controlling which events are delivered to which endpoint.

Examples:

mgmt = Nahook::Management.new("nhm_token")
mgmt.subscriptions.list("ws_abc123", "ep_def456")
mgmt.subscriptions.create("ws_abc123", "ep_def456", event_type_ids: ["evt_ghi789"])

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Subscriptions

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 Subscriptions.

Parameters:



19
20
21
# File 'lib/nahook/resources/subscriptions.rb', line 19

def initialize(http)
  @http = http
end

Instance Method Details

#create(workspace_id, endpoint_id, event_type_ids:) ⇒ Hash

Subscribe an endpoint to one or more event types.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • endpoint_id (String)

    the endpoint public ID

  • event_type_ids (Array<String>)

    event type public IDs to subscribe to

Returns:

  • (Hash)

    response with “subscribed” count



42
43
44
45
46
47
48
# File 'lib/nahook/resources/subscriptions.rb', line 42

def create(workspace_id, endpoint_id, event_type_ids:)
  @http.request(
    method: :post,
    path: "/management/v1/workspaces/#{e(workspace_id)}/endpoints/#{e(endpoint_id)}/subscriptions",
    body: { "eventTypeIds" => Array(event_type_ids) }
  )
end

#delete(workspace_id, endpoint_id, event_type_id) ⇒ nil

Delete a subscription.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • endpoint_id (String)

    the endpoint public ID

  • event_type_id (String)

    the event type public ID to unsubscribe

Returns:

  • (nil)


56
57
58
59
60
61
# File 'lib/nahook/resources/subscriptions.rb', line 56

def delete(workspace_id, endpoint_id, event_type_id)
  @http.request(
    method: :delete,
    path: "/management/v1/workspaces/#{e(workspace_id)}/endpoints/#{e(endpoint_id)}/subscriptions/#{e(event_type_id)}"
  )
end

#list(workspace_id, endpoint_id) ⇒ Hash

List subscriptions for an endpoint.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • endpoint_id (String)

    the endpoint public ID

Returns:

  • (Hash)

    response with “data” key containing an array of subscriptions



28
29
30
31
32
33
34
# File 'lib/nahook/resources/subscriptions.rb', line 28

def list(workspace_id, endpoint_id)
  data = @http.request(
    method: :get,
    path: "/management/v1/workspaces/#{e(workspace_id)}/endpoints/#{e(endpoint_id)}/subscriptions"
  )
  { "data" => data }
end