Class: SimpleSpark::Endpoints::Webhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_spark/endpoints/webhooks.rb

Overview

Note:

Example webhook

Provides access to the /webhooks endpoint

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Webhooks

Returns a new instance of Webhooks.



9
10
11
# File 'lib/simple_spark/endpoints/webhooks.rb', line 9

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



7
8
9
# File 'lib/simple_spark/endpoints/webhooks.rb', line 7

def client
  @client
end

Instance Method Details

#batch_status(id, limit = nil) ⇒ Array

Parameters:

  • id (String)

    the ID of the webhook

Returns:

  • (Array)

    a list of status hash objects



55
56
57
58
# File 'lib/simple_spark/endpoints/webhooks.rb', line 55

def batch_status(id, limit = nil)
  query_params = limit.nil? ? {} : { limit: limit }
  @client.call(method: :get, path: "webhooks/#{id}/batch-status", query_values: query_params)
end

#create(values) ⇒ Object

Parameters:

  • values (Hash)

    the values to create the webhook with



24
25
26
# File 'lib/simple_spark/endpoints/webhooks.rb', line 24

def create(values)
  @client.call(method: :post, path: 'webhooks', body_values: values)
end

#delete(id) ⇒ Object

Parameters:

  • id (String)

    the ID



72
73
74
# File 'lib/simple_spark/endpoints/webhooks.rb', line 72

def delete(id)
  @client.call(method: :delete, path: "webhooks/#{id}")
end

#list(timezone = nil) ⇒ Array

List currently extant webhooks

Returns:

  • (Array)

    a list of Webhook hash objects



16
17
18
19
# File 'lib/simple_spark/endpoints/webhooks.rb', line 16

def list(timezone = nil)
  query_params = timezone.nil? ? {} : { timezone: timezone }
  @client.call(method: :get, path: 'webhooks', query_values: query_params)
end

#retrieve(id) ⇒ Hash

Retrieve details about a webhook by specifying its id

Parameters:

  • id (String)

    the ID of the webhook

Returns:

  • (Hash)

    an Webhook hash object



32
33
34
# File 'lib/simple_spark/endpoints/webhooks.rb', line 32

def retrieve(id)
  @client.call(method: :get, path: "webhooks/#{id}")
end

#samples(events = nil) ⇒ Array

Parameters:

  • events (String) (defaults to: nil)

    Event types for which to get a sample payload

Returns:

  • (Array)

    a list of sample event hash objects



64
65
66
67
# File 'lib/simple_spark/endpoints/webhooks.rb', line 64

def samples(events = nil)
  query_params = events.nil? ? {} : { events: events }
  @client.call(method: :get, path: 'webhooks/events/samples', query_values: query_params)
end

#update(id, values) ⇒ Object

Parameters:

  • id (String)

    the ID of the webhook

  • values (Hash)

    the values to update the webhook with



40
41
42
# File 'lib/simple_spark/endpoints/webhooks.rb', line 40

def update(id, values)
  @client.call(method: :put, path: "webhooks/#{id}", body_values: values)
end

#validate(id) ⇒ Object

Validates a Webhook by sending an example message event batch from the Webhooks API to the target URL

Parameters:

  • id (String)

    the ID of the webhook



47
48
49
# File 'lib/simple_spark/endpoints/webhooks.rb', line 47

def validate(id)
  @client.call(method: :post, path: "webhooks/#{id}/validate")
end