Class: Nahook::Resources::Endpoints

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

Overview

Resource for managing webhook endpoints via the Management API.

Examples:

mgmt = Nahook::Management.new("nhm_token")
mgmt.endpoints.list("ws_abc123")
mgmt.endpoints.create("ws_abc123", url: "https://example.com/webhook")

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Endpoints

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

Parameters:



16
17
18
# File 'lib/nahook/resources/endpoints.rb', line 16

def initialize(http)
  @http = http
end

Instance Method Details

#create(workspace_id, url:, type: nil, description: nil, metadata: nil, config: nil, auth_username: nil, auth_password: nil) ⇒ Hash

Create a new endpoint.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • url (String)

    the endpoint URL

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

    endpoint type (“webhook” or “slack”)

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

    human-readable description

  • metadata (Hash, nil) (defaults to: nil)

    arbitrary key-value metadata

  • config (Hash, nil) (defaults to: nil)

    endpoint-specific configuration

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

    basic auth username

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

    basic auth password

Returns:

  • (Hash)

    the created endpoint



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/nahook/resources/endpoints.rb', line 43

def create(workspace_id, url:, type: nil, description: nil, metadata: nil, config: nil,
           auth_username: nil, auth_password: nil)
  body = { "url" => url }
  body["type"]         = type         if type
  body["description"]  = description  if description
  body["metadata"]     =      if 
  body["config"]       = config       if config
  body["authUsername"]  = auth_username if auth_username
  body["authPassword"] = auth_password if auth_password

  @http.request(
    method: :post,
    path: "/management/v1/workspaces/#{e(workspace_id)}/endpoints",
    body: body
  )
end

#delete(workspace_id, id) ⇒ nil

Delete an endpoint.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • id (String)

    the endpoint public ID

Returns:

  • (nil)


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

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

#get(workspace_id, id) ⇒ Hash

Get a single endpoint by ID.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • id (String)

    the endpoint public ID

Returns:

  • (Hash)

    the endpoint



65
66
67
68
69
70
# File 'lib/nahook/resources/endpoints.rb', line 65

def get(workspace_id, id)
  @http.request(
    method: :get,
    path: "/management/v1/workspaces/#{e(workspace_id)}/endpoints/#{e(id)}"
  )
end

#list(workspace_id) ⇒ Hash

List all endpoints in a workspace.

Parameters:

  • workspace_id (String)

    the workspace public ID

Returns:

  • (Hash)

    response with “data” key containing an array of endpoints



24
25
26
27
28
29
30
# File 'lib/nahook/resources/endpoints.rb', line 24

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

#update(workspace_id, id, url: nil, description: nil, metadata: nil, is_active: nil) ⇒ Hash

Update an existing endpoint.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • id (String)

    the endpoint public ID

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

    updated URL

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

    updated description

  • metadata (Hash, nil) (defaults to: nil)

    updated metadata

  • is_active (Boolean, nil) (defaults to: nil)

    whether the endpoint is active

Returns:

  • (Hash)

    the updated endpoint



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/nahook/resources/endpoints.rb', line 81

def update(workspace_id, id, url: nil, description: nil, metadata: nil, is_active: nil)
  body = {}
  body["url"]         = url         unless url.nil?
  body["description"] = description unless description.nil?
  body["metadata"]    =     unless .nil?
  body["isActive"]    = is_active   unless is_active.nil?

  @http.request(
    method: :patch,
    path: "/management/v1/workspaces/#{e(workspace_id)}/endpoints/#{e(id)}",
    body: body
  )
end