Class: Schematic::Webhooks::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



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

def initialize(client:)
  @client = client
end

Instance Method Details

#count_webhook_events(request_options: {}, **params) ⇒ Schematic::Webhooks::Types::CountWebhookEventsResponse

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):

  • :ids (String, nil)
  • :q (String, nil)
  • :webhook_id (String, nil)
  • :limit (Integer, nil)
  • :offset (Integer, nil)

Returns:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/schematic/webhooks/client.rb', line 105

def count_webhook_events(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  query_param_names = %i[ids q webhook_id limit offset]
  query_params = {}
  query_params["ids"] = params[:ids] if params.key?(:ids)
  query_params["q"] = params[:q] if params.key?(:q)
  query_params["webhook_id"] = params[:webhook_id] if params.key?(:webhook_id)
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["offset"] = params[:offset] if params.key?(:offset)
  params.except(*query_param_names)

  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "webhook-events/count",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Webhooks::Types::CountWebhookEventsResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#count_webhooks(request_options: {}, **params) ⇒ Schematic::Webhooks::Types::CountWebhooksResponse

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):

  • :q (String, nil)
  • :limit (Integer, nil)
  • :offset (Integer, nil)

Returns:



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/schematic/webhooks/client.rb', line 324

def count_webhooks(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  query_param_names = %i[q limit offset]
  query_params = {}
  query_params["q"] = params[:q] if params.key?(:q)
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["offset"] = params[:offset] if params.key?(:offset)
  params.except(*query_param_names)

  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "webhooks/count",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Webhooks::Types::CountWebhooksResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#create_webhook(request_options: {}, **params) ⇒ Schematic::Webhooks::Types::CreateWebhookResponse

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:



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/schematic/webhooks/client.rb', line 188

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

#delete_webhook(request_options: {}, **params) ⇒ Schematic::Webhooks::Types::DeleteWebhookResponse

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):

  • :webhook_id (String)

Returns:



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/schematic/webhooks/client.rb', line 290

def delete_webhook(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "DELETE",
    path: "webhooks/#{URI.encode_uri_component(params[:webhook_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Webhooks::Types::DeleteWebhookResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_webhook(request_options: {}, **params) ⇒ Schematic::Webhooks::Types::GetWebhookResponse

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):

  • :webhook_id (String)

Returns:



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/schematic/webhooks/client.rb', line 221

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

#get_webhook_event(request_options: {}, **params) ⇒ Schematic::Webhooks::Types::GetWebhookEventResponse

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):

  • :webhook_event_id (String)

Returns:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/schematic/webhooks/client.rb', line 69

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

#list_webhook_events(request_options: {}, **params) ⇒ Schematic::Webhooks::Types::ListWebhookEventsResponse

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):

  • :ids (String, nil)
  • :q (String, nil)
  • :webhook_id (String, nil)
  • :limit (Integer, nil)
  • :offset (Integer, nil)

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/schematic/webhooks/client.rb', line 27

def list_webhook_events(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  query_param_names = %i[ids q webhook_id limit offset]
  query_params = {}
  query_params["ids"] = params[:ids] if params.key?(:ids)
  query_params["q"] = params[:q] if params.key?(:q)
  query_params["webhook_id"] = params[:webhook_id] if params.key?(:webhook_id)
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["offset"] = params[:offset] if params.key?(:offset)
  params.except(*query_param_names)

  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "webhook-events",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Webhooks::Types::ListWebhookEventsResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list_webhooks(request_options: {}, **params) ⇒ Schematic::Webhooks::Types::ListWebhooksResponse

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):

  • :q (String, nil)
  • :limit (Integer, nil)
  • :offset (Integer, nil)

Returns:



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/schematic/webhooks/client.rb', line 149

def list_webhooks(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  query_param_names = %i[q limit offset]
  query_params = {}
  query_params["q"] = params[:q] if params.key?(:q)
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["offset"] = params[:offset] if params.key?(:offset)
  params.except(*query_param_names)

  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "webhooks",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Webhooks::Types::ListWebhooksResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#update_webhook(request_options: {}, **params) ⇒ Schematic::Webhooks::Types::UpdateWebhookResponse

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)

Options Hash (**params):

  • :webhook_id (String)

Returns:



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/schematic/webhooks/client.rb', line 253

def update_webhook(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request_data = Schematic::Webhooks::Types::UpdateWebhookRequestBody.new(params).to_h
  non_body_param_names = ["webhook_id"]
  body = request_data.except(*non_body_param_names)

  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PUT",
    path: "webhooks/#{URI.encode_uri_component(params[:webhook_id].to_s)}",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Webhooks::Types::UpdateWebhookResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end