Class: Square::Webhooks::EventTypes::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Square::Webhooks::EventTypes::Client



8
9
10
# File 'lib/square/webhooks/event_types/client.rb', line 8

def initialize(client:)
  @client = client
end

Instance Method Details

#list(request_options: {}, **params) ⇒ Square::Types::ListWebhookEventTypesResponse

Lists all webhook event types that can be subscribed to.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/square/webhooks/event_types/client.rb', line 15

def list(request_options: {}, **params)
  _query_param_names = [
    ["api_version"],
    %i[api_version]
  ].flatten
  _query = params.slice(*_query_param_names)
  params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/webhooks/event-types",
    query: _query
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::ListWebhookEventTypesResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end