Class: Nahook::Resources::Environments

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

Overview

Resource for managing environments via the Management API.

Examples:

mgmt = Nahook::Management.new("nhm_token")
mgmt.environments.list("ws_abc123")
mgmt.environments.create("ws_abc123", name: "Staging", slug: "staging")

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Environments

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

Parameters:



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

def initialize(http)
  @http = http
end

Instance Method Details

#create(workspace_id, name:, slug:) ⇒ Hash

Create a new environment.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • name (String)

    the environment name

  • slug (String)

    the environment slug

Returns:

  • (Hash)

    the created environment



38
39
40
41
42
43
44
# File 'lib/nahook/resources/environments.rb', line 38

def create(workspace_id, name:, slug:)
  @http.request(
    method: :post,
    path: "/management/v1/workspaces/#{e(workspace_id)}/environments",
    body: { "name" => name, "slug" => slug }
  )
end

#delete(workspace_id, id) ⇒ nil

Delete an environment.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • id (String)

    the environment ID

Returns:

  • (nil)


79
80
81
82
83
84
# File 'lib/nahook/resources/environments.rb', line 79

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

#get(workspace_id, id) ⇒ Hash

Get a single environment by ID.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • id (String)

    the environment ID

Returns:

  • (Hash)

    the environment



51
52
53
54
55
56
# File 'lib/nahook/resources/environments.rb', line 51

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

#list(workspace_id) ⇒ Hash

List all environments in a workspace.

Parameters:

  • workspace_id (String)

    the workspace public ID

Returns:

  • (Hash)

    response with “data” key containing an array of environments



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

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

#list_event_type_visibility(workspace_id, env_id) ⇒ Hash

List event type visibility for an environment.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • env_id (String)

    the environment ID

Returns:

  • (Hash)

    response with “data” key containing an array of event type visibility entries



91
92
93
94
95
96
97
# File 'lib/nahook/resources/environments.rb', line 91

def list_event_type_visibility(workspace_id, env_id)
  data = @http.request(
    method: :get,
    path: "/management/v1/workspaces/#{e(workspace_id)}/environments/#{e(env_id)}/event-types"
  )
  { "data" => data }
end

#set_event_type_visibility(workspace_id, env_id, event_type_id, published:) ⇒ Hash

Set event type visibility for an environment.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • env_id (String)

    the environment ID

  • event_type_id (String)

    the event type ID

  • published (Boolean)

    whether the event type is published in this environment

Returns:

  • (Hash)

    the updated visibility entry



106
107
108
109
110
111
112
# File 'lib/nahook/resources/environments.rb', line 106

def set_event_type_visibility(workspace_id, env_id, event_type_id, published:)
  @http.request(
    method: :put,
    path: "/management/v1/workspaces/#{e(workspace_id)}/environments/#{e(env_id)}/event-types/#{e(event_type_id)}/visibility",
    body: { "published" => published }
  )
end

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

Update an existing environment.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • id (String)

    the environment ID

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

    the updated name

Returns:

  • (Hash)

    the updated environment



64
65
66
67
68
69
70
71
72
# File 'lib/nahook/resources/environments.rb', line 64

def update(workspace_id, id, name: nil)
  body = {}
  body["name"] = name unless name.nil?
  @http.request(
    method: :patch,
    path: "/management/v1/workspaces/#{e(workspace_id)}/environments/#{e(id)}",
    body: body
  )
end