Class: Square::Events::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Square::Events::Client



7
8
9
# File 'lib/square/events/client.rb', line 7

def initialize(client:)
  @client = client
end

Instance Method Details

#disable_events(request_options: {}, **_params) ⇒ Square::Types::DisableEventsResponse

Disables events to prevent them from being searchable. All events are disabled by default. You must enable events to make them searchable. Disabling events for a specific time period prevents them from being searchable, even if you re-enable them later.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/square/events/client.rb', line 34

def disable_events(request_options: {}, **_params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "PUT",
    path: "v2/events/disable"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::DisableEventsResponse.load(_response.body)
  end

  raise _response.body
end

#enable_events(request_options: {}, **_params) ⇒ Square::Types::EnableEventsResponse

Enables events to make them searchable. Only events that occur while in the enabled state are searchable.



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/square/events/client.rb', line 51

def enable_events(request_options: {}, **_params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "PUT",
    path: "v2/events/enable"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::EnableEventsResponse.load(_response.body)
  end

  raise _response.body
end

#list_event_types(request_options: {}, **params) ⇒ Square::Types::ListEventTypesResponse

Lists all event types that you can subscribe to as webhooks or query using the Events API.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/square/events/client.rb', line 68

def list_event_types(request_options: {}, **params)
  _query_param_names = ["api_version"]
  _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::SANDBOX,
    method: "GET",
    path: "v2/events/types",
    query: _query
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::ListEventTypesResponse.load(_response.body)
  end

  raise _response.body
end

#search_events(request_options: {}, **params) ⇒ Square::Types::SearchEventsResponse

Search for Square API events that occur within a 28-day timeframe.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/square/events/client.rb', line 14

def search_events(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/events",
    body: params
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::SearchEventsResponse.load(_response.body)
  end

  raise _response.body
end