Class: Nahook::Management

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

Overview

Client for the Nahook Management API.

Provides programmatic access to manage workspaces, endpoints, event types, applications, subscriptions, and portal sessions. Intended for server-side use with a management token.

Unlike Client, the Management client does not support retries – management operations are not idempotent by default.

Examples:

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

# List endpoints
result = mgmt.endpoints.list("ws_abc123")
result["data"].each { |ep| puts ep["url"] }

# Create an endpoint
endpoint = mgmt.endpoints.create("ws_abc123",
  url: "https://example.com/webhook",
  description: "Production webhook"
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, base_url: HttpClient::DEFAULT_BASE_URL, timeout_ms: HttpClient::DEFAULT_TIMEOUT_MS, adapter: nil, connection: nil) ⇒ Management

Returns a new instance of Management.

Parameters:

  • token (String)

    management token (must start with “nhm_”)

  • base_url (String) (defaults to: HttpClient::DEFAULT_BASE_URL)

    API base URL

  • timeout_ms (Integer) (defaults to: HttpClient::DEFAULT_TIMEOUT_MS)

    request timeout in milliseconds (default: 30000)

  • adapter (Symbol, nil) (defaults to: nil)

    Faraday adapter to use (defaults to ‘:net_http_persistent` for keep-alive). See Client#initialize.

  • connection (Faraday::Connection, nil) (defaults to: nil)

    a fully-configured Faraday connection. When supplied, ‘base_url`, `timeout_ms`, and `adapter` are ignored.

Raises:

  • (ArgumentError)

    if the token does not start with “nhm_”



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/nahook/management.rb', line 56

def initialize(token, base_url: HttpClient::DEFAULT_BASE_URL, timeout_ms: HttpClient::DEFAULT_TIMEOUT_MS,
               adapter: nil, connection: nil)
  unless token.start_with?("nhm_")
    raise ArgumentError, "Invalid management token: must start with 'nhm_'"
  end

  http_kwargs = { token: token, base_url: base_url, timeout_ms: timeout_ms }
  http_kwargs[:adapter]    = adapter    if adapter
  http_kwargs[:connection] = connection if connection

  http = HttpClient.new(**http_kwargs)

  @endpoints       = Resources::Endpoints.new(http)
  @event_types     = Resources::EventTypes.new(http)
  @applications    = Resources::Applications.new(http)
  @subscriptions   = Resources::Subscriptions.new(http)
  @portal_sessions = Resources::PortalSessions.new(http)
  @environments    = Resources::Environments.new(http)
  @deliveries      = Resources::Deliveries.new(http)
end

Instance Attribute Details

#applicationsResources::Applications (readonly)



33
34
35
# File 'lib/nahook/management.rb', line 33

def applications
  @applications
end

#deliveriesResources::Deliveries (readonly)



45
46
47
# File 'lib/nahook/management.rb', line 45

def deliveries
  @deliveries
end

#endpointsResources::Endpoints (readonly)



27
28
29
# File 'lib/nahook/management.rb', line 27

def endpoints
  @endpoints
end

#environmentsResources::Environments (readonly)



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

def environments
  @environments
end

#event_typesResources::EventTypes (readonly)



30
31
32
# File 'lib/nahook/management.rb', line 30

def event_types
  @event_types
end

#portal_sessionsResources::PortalSessions (readonly)



39
40
41
# File 'lib/nahook/management.rb', line 39

def portal_sessions
  @portal_sessions
end

#subscriptionsResources::Subscriptions (readonly)



36
37
38
# File 'lib/nahook/management.rb', line 36

def subscriptions
  @subscriptions
end