Class: VitableConnect::WebhookEvents::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/VitableConnect/webhook_events/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



9
10
11
# File 'lib/VitableConnect/webhook_events/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#get(request_options: {}, **params) ⇒ VitableConnect::Types::WebhookEventResponse

Retrieves a single webhook event by its prefixed ID. Returns 404 if the event does not exist or belongs to a different organization.

Examples:

client.webhook_events.get(event_id: "event_id")

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

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)

Options Hash (**params):

Returns:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/VitableConnect/webhook_events/client.rb', line 95

def get(request_options: {}, **params)
  params = VitableConnect::Internal::Types::Utils.normalize_keys(params)
  request = VitableConnect::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v1/webhook-events/#{URI.encode_uri_component(params[:event_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise VitableConnect::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    VitableConnect::Types::WebhookEventResponse.load(response.body)
  else
    error_class = VitableConnect::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list(request_options: {}, **params) ⇒ VitableConnect::Types::WebhookEventListResponse

Retrieves a paginated list of webhook events for the authenticated organization. Supports filtering by event name, resource type, resource ID, and date range.

Examples:

client.webhook_events.list(
  limit: 20,
  page: 1
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

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)

Options Hash (**params):

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/VitableConnect/webhook_events/client.rb', line 38

def list(request_options: {}, **params)
  params = VitableConnect::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["created_after"] = params[:created_after] if params.key?(:created_after)
  query_params["created_before"] = params[:created_before] if params.key?(:created_before)
  query_params["event_name"] = params[:event_name] if params.key?(:event_name)
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["page"] = params[:page] if params.key?(:page)
  query_params["resource_id"] = params[:resource_id] if params.key?(:resource_id)
  query_params["resource_type"] = params[:resource_type] if params.key?(:resource_type)

  VitableConnect::Internal::OffsetItemIterator.new(
    initial_page: query_params["page"],
    item_field: :data,
    has_next_field: nil,
    step: false
  ) do |next_page|
    query_params["page"] = next_page
    request = VitableConnect::Internal::JSON::Request.new(
      base_url: request_options[:base_url],
      method: "GET",
      path: "v1/webhook-events",
      query: query_params,
      request_options: request_options
    )
    begin
      response = @client.send(request)
    rescue Net::HTTPRequestTimeout
      raise VitableConnect::Errors::TimeoutError
    end
    code = response.code.to_i
    if code.between?(200, 299)
      parsed_response = VitableConnect::Types::WebhookEventListResponse.load(response.body)
      [parsed_response, response]
    else
      error_class = VitableConnect::Errors::ResponseError.subclass_for_code(code)
      raise error_class.new(response.body, code: code)
    end
  end
end

#list_deliveries(request_options: {}, **params) ⇒ VitableConnect::Types::ListWebhookEventDeliveriesResponse

Retrieves all delivery attempts for a webhook event. Returns up to 100 deliveries. Each delivery includes a computed status field (Pending, In Progress, Delivered, or Failed).

Examples:

client.webhook_events.list_deliveries(event_id: "event_id")

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

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)

Options Hash (**params):

Returns:



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/VitableConnect/webhook_events/client.rb', line 133

def list_deliveries(request_options: {}, **params)
  params = VitableConnect::Internal::Types::Utils.normalize_keys(params)
  request = VitableConnect::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v1/webhook-events/#{URI.encode_uri_component(params[:event_id].to_s)}/deliveries",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise VitableConnect::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    VitableConnect::Types::ListWebhookEventDeliveriesResponse.load(response.body)
  else
    error_class = VitableConnect::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end