Class: Rerout::CreateWebhookInput

Inherits:
Object
  • Object
show all
Defined in:
lib/rerout/create_webhook_input.rb

Overview

Request body for ‘POST /v1/projects/me/webhooks`. `name`, `url`, and `events` are required; `is_active` and `payload_format` are optional and omitted from the payload when not set (server defaults apply).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, url:, events:, is_active: nil, payload_format: nil) ⇒ CreateWebhookInput

Returns a new instance of CreateWebhookInput.

Parameters:

  • name (String)

    required, human-readable label for the endpoint.

  • url (String)

    required, public https:// URL that receives deliveries.

  • events (Array<String>)

    required, non-empty list of event types to subscribe to (e.g. ‘link.created`).

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

    whether the endpoint starts active. Server default: ‘true`.

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

    payload encoding — ‘“json”` or `“slack”`. Server default: `“json”`.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rerout/create_webhook_input.rb', line 18

def initialize(name:, url:, events:, is_active: nil, payload_format: nil)
  raise ArgumentError, 'name is required' if name.nil? || name.to_s.empty?
  raise ArgumentError, 'url is required' if url.nil? || url.to_s.empty?
  if events.nil? || !events.is_a?(Array) || events.empty?
    raise ArgumentError, 'events is required and must be a non-empty Array'
  end

  @name = name
  @url = url
  @events = events
  @is_active = is_active
  @payload_format = payload_format
  freeze
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



8
9
10
# File 'lib/rerout/create_webhook_input.rb', line 8

def events
  @events
end

#is_activeObject (readonly)

Returns the value of attribute is_active.



8
9
10
# File 'lib/rerout/create_webhook_input.rb', line 8

def is_active
  @is_active
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/rerout/create_webhook_input.rb', line 8

def name
  @name
end

#payload_formatObject (readonly)

Returns the value of attribute payload_format.



8
9
10
# File 'lib/rerout/create_webhook_input.rb', line 8

def payload_format
  @payload_format
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/rerout/create_webhook_input.rb', line 8

def url
  @url
end

Instance Method Details

#to_hObject

Serialize for the wire. Optional fields are only included when set.



34
35
36
37
38
39
# File 'lib/rerout/create_webhook_input.rb', line 34

def to_h
  hash = { 'name' => name, 'url' => url, 'events' => events }
  hash['is_active'] = is_active unless is_active.nil?
  hash['payload_format'] = payload_format unless payload_format.nil?
  hash
end