Class: Pinnacle::Webhooks::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pinnacle/webhooks/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



9
10
11
# File 'lib/pinnacle/webhooks/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#attach(request_options: {}, **params) ⇒ Pinnacle::Types::AttachWebhookResult

Attach a webhook to one or more senders (phone numbers or RCS agent IDs) to receive real-time event notifications.

You can attach an existing webhook by providing its ID, or create a new webhook by specifying a name and URL. Supports bulk operations with up to 50 senders per request.

Subscriptions are additive — attaching new senders does not remove existing ones. Re-attaching the same sender updates the event type filter without creating duplicates.

**Custom headers** may be provided in either case via the optional ‘headers` field. When attaching a new webhook, the headers are stored on the webhook and sent on every delivery. When attaching an existing `webhookId`, supplying `headers` overwrites the stored headers on that webhook — omit the field to leave them unchanged, or pass an empty object `{}` to clear them. The reserved `PINNACLE-SIGNING-SECRET` header is always set by Pinnacle and cannot be overridden.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/pinnacle/webhooks/client.rb', line 105

def attach(request_options: {}, **params)
  params = Pinnacle::Internal::Types::Utils.normalize_keys(params)
  request = Pinnacle::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "webhooks/attach",
    body: Pinnacle::Webhooks::Types::AttachWebhookParams.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Pinnacle::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Pinnacle::Types::AttachWebhookResult.load(response.body)
  else
    error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#detach(request_options: {}, **params) ⇒ Pinnacle::Types::DetachWebhookResult

Detach a webhook from one or more senders (phone numbers or RCS agent IDs) to stop receiving event notifications.

The webhook itself is not deleted and remains available for use with other senders. Works regardless of webhook status. Supports bulk operations with up to 50 senders per request.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/pinnacle/webhooks/client.rb', line 143

def detach(request_options: {}, **params)
  params = Pinnacle::Internal::Types::Utils.normalize_keys(params)
  request = Pinnacle::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "webhooks/detach",
    body: Pinnacle::Webhooks::Types::DetachWebhookParams.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Pinnacle::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Pinnacle::Types::DetachWebhookResult.load(response.body)
  else
    error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get(request_options: {}, **params) ⇒ Pinnacle::Types::WebhookResult

Retrieve all webhook that are set up to receive events for specific URLs or phone numbers.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pinnacle/webhooks/client.rb', line 24

def get(request_options: {}, **params)
  params = Pinnacle::Internal::Types::Utils.normalize_keys(params)
  request = Pinnacle::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "webhooks",
    body: Pinnacle::Webhooks::Types::GetWebhookParams.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Pinnacle::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Pinnacle::Types::WebhookResult.load(response.body)
  else
    error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list(request_options: {}, **params) ⇒ Pinnacle::Types::ListWebhooksResponse

List all webhooks with optional filtering and pagination. Results are sorted by creation date, newest first.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pinnacle/webhooks/client.rb', line 58

def list(request_options: {}, **params)
  params = Pinnacle::Internal::Types::Utils.normalize_keys(params)
  request = Pinnacle::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "webhooks/list",
    body: Pinnacle::Webhooks::Types::ListWebhooksParams.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Pinnacle::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Pinnacle::Types::ListWebhooksResponse.load(response.body)
  else
    error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end