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, max_endpoints: nil, show_event_types: 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

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

    cap on how many endpoints this application may have (disabled endpoints count); 0 makes it read-only, nil (default) means unlimited

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

    whether the Developer Portal exposes the event-type catalog (server defaults to true)

Returns:

  • (Hash)

    the created application



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/nahook/resources/applications.rb', line 54

def create(workspace_id, name:, external_id: nil, metadata: nil, max_endpoints: nil, show_event_types: nil)
  body = { "name" => name }
  body["externalId"] = external_id if external_id
  body["metadata"]   =     if 
  body["maxEndpoints"]   = max_endpoints    unless max_endpoints.nil?
  body["showEventTypes"] = show_event_types unless show_event_types.nil?

  @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



140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/nahook/resources/applications.rb', line 140

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)


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

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



73
74
75
76
77
78
# File 'lib/nahook/resources/applications.rb', line 73

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



122
123
124
125
126
127
128
# File 'lib/nahook/resources/applications.rb', line 122

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, max_endpoints: UNSET, show_event_types: UNSET) ⇒ 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

  • max_endpoints (Integer, nil, UNSET) (defaults to: UNSET)

    tri-state: leave as UNSET (default) to keep the current cap, pass nil to clear it (unlimited), or pass an Integer (>= 0) to set it

  • show_event_types (Boolean, UNSET) (defaults to: UNSET)

    omitted when UNSET

Returns:

  • (Hash)

    the updated application



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/nahook/resources/applications.rb', line 91

def update(workspace_id, id, name: nil, metadata: nil, max_endpoints: UNSET, show_event_types: UNSET)
  body = {}
  body["name"]     = name     unless name.nil?
  body["metadata"] =  unless .nil?
  body["maxEndpoints"]   = max_endpoints    unless max_endpoints.equal?(UNSET)
  body["showEventTypes"] = show_event_types unless show_event_types.equal?(UNSET)

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