Class: Square::Events::Client
- Inherits:
-
Object
- Object
- Square::Events::Client
- Defined in:
- lib/square/events/client.rb
Instance Method Summary collapse
-
#disable_events(request_options: {}, **params) ⇒ Square::Types::DisableEventsResponse
Disables events to prevent them from being searchable.
-
#enable_events(request_options: {}, **params) ⇒ Square::Types::EnableEventsResponse
Enables events to make them searchable.
- #initialize(client:) ⇒ void constructor
-
#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.
-
#search_events(request_options: {}, **params) ⇒ Square::Types::SearchEventsResponse
Search for Square API events that occur within a 28-day timeframe.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/square/events/client.rb', line 9 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.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/square/events/client.rb', line 61 def disable_events(request_options: {}, **params) Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "PUT", path: "v2/events/disable", request_options: ) 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::DisableEventsResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end 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.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/square/events/client.rb', line 94 def enable_events(request_options: {}, **params) Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "PUT", path: "v2/events/enable", request_options: ) 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::EnableEventsResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end 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.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/square/events/client.rb', line 128 def list_event_types(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[api_version] query_params = {} query_params["api_version"] = params[:api_version] if params.key?(:api_version) params.except(*query_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/events/types", query: query_params, request_options: ) 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::ListEventTypesResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#search_events(request_options: {}, **params) ⇒ Square::Types::SearchEventsResponse
Search for Square API events that occur within a 28-day timeframe.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/square/events/client.rb', line 24 def search_events(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/events", body: Square::Events::Types::SearchEventsRequest.new(params).to_h, request_options: ) 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::SearchEventsResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |