Class: Nahook::Resources::EventTypes

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

Overview

Resource for managing event types via the Management API.

Examples:

mgmt = Nahook::Management.new("nhm_token")
mgmt.event_types.list("ws_abc123")
mgmt.event_types.create("ws_abc123", name: "order.paid")

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ EventTypes

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

Parameters:



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

def initialize(http)
  @http = http
end

Instance Method Details

#create(workspace_id, name:, description: nil) ⇒ Hash

Create a new event type.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • name (String)

    the event type name (e.g. “order.paid”)

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

    human-readable description

Returns:

  • (Hash)

    the created event type



38
39
40
41
42
43
44
45
46
47
# File 'lib/nahook/resources/event_types.rb', line 38

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

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

#delete(workspace_id, id) ⇒ nil

Delete an event type.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • id (String)

    the event type public ID

Returns:

  • (nil)


83
84
85
86
87
88
# File 'lib/nahook/resources/event_types.rb', line 83

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

#get(workspace_id, id) ⇒ Hash

Get a single event type by ID.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • id (String)

    the event type public ID

Returns:

  • (Hash)

    the event type



54
55
56
57
58
59
# File 'lib/nahook/resources/event_types.rb', line 54

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

#list(workspace_id) ⇒ Hash

List all event types in a workspace.

Parameters:

  • workspace_id (String)

    the workspace public ID

Returns:

  • (Hash)

    response with “data” key containing an array of event types



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

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

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

Update an existing event type.

Parameters:

  • workspace_id (String)

    the workspace public ID

  • id (String)

    the event type public ID

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

    updated description

Returns:

  • (Hash)

    the updated event type



67
68
69
70
71
72
73
74
75
76
# File 'lib/nahook/resources/event_types.rb', line 67

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

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