Class: Nahook::Resources::Applications

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

Overview

Resource for managing applications via the Management API.

Applications group endpoints for multi-tenant use cases. Each application can have its own set of endpoints and a developer portal.

Examples:

mgmt = Nahook::Management.new("nhm_token")
mgmt.applications.list("ws_abc123", limit: 10)
mgmt.applications.create("ws_abc123", name: "Acme Corp")

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Applications

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

Parameters:



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

def initialize(http)
  @http = http
end

Instance Method Details

#create(workspace_id, name:, external_id: nil, metadata: nil) ⇒ Hash

Create a new application.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • name (String)

    the application name

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

    an external identifier for your system

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

    arbitrary key-value metadata

Returns:

  • (Hash)

    the created application



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/nahook/resources/applications.rb', line 49

def create(workspace_id, name:, external_id: nil, metadata: nil)
  body = { "name" => name }
  body["externalId"] = external_id if external_id
  body["metadata"]   =     if 

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

#create_endpoint(workspace_id, app_id, url:, type: nil, description: nil, metadata: nil, config: nil) ⇒ Hash

Create an endpoint within an application.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • app_id (String)

    the application 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

Returns:

  • (Hash)

    the created endpoint



127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/nahook/resources/applications.rb', line 127

def create_endpoint(workspace_id, app_id, url:, type: nil, description: nil, metadata: nil, config: nil)
  body = { "url" => url }
  body["type"]        = type        if type
  body["description"] = description if description
  body["metadata"]    =     if 
  body["config"]      = config      if config

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

#delete(workspace_id, id) ⇒ nil

Delete an application.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • id (String)

    the application public ID

Returns:

  • (nil)


97
98
99
100
101
102
# File 'lib/nahook/resources/applications.rb', line 97

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

#get(workspace_id, id) ⇒ Hash

Get a single application by ID.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • id (String)

    the application public ID

Returns:

  • (Hash)

    the application



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

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

#list(workspace_id, limit: nil, offset: nil) ⇒ Hash

List applications in a workspace with optional pagination.

Parameters:

  • workspace_id (String)

    the workspace public ID

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

    maximum number of results

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

    number of results to skip

Returns:

  • (Hash)

    response with “data” key containing an array of applications



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/nahook/resources/applications.rb', line 29

def list(workspace_id, limit: nil, offset: nil)
  query = {}
  query["limit"]  = limit  if limit
  query["offset"] = offset if offset

  data = @http.request(
    method: :get,
    path: "/management/v1/workspaces/#{e(workspace_id)}/applications",
    query: query.empty? ? nil : query
  )
  { "data" => data }
end

#list_endpoints(workspace_id, app_id) ⇒ Hash

List endpoints belonging to an application.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • app_id (String)

    the application public ID

Returns:

  • (Hash)

    response with “data” key containing an array of endpoints



109
110
111
112
113
114
115
# File 'lib/nahook/resources/applications.rb', line 109

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

#update(workspace_id, id, name: nil, metadata: nil) ⇒ Hash

Update an existing application.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • id (String)

    the application public ID

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

    updated name

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

    updated metadata

Returns:

  • (Hash)

    the updated application



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/nahook/resources/applications.rb', line 80

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

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