Class: Square::WebhookSubscriptionsApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/square/api/webhook_subscriptions_api.rb

Overview

WebhookSubscriptionsApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#execute_request, #get_user_agent, #validate_parameters, #validate_parameters_types

Constructor Details

#initialize(config, http_call_back: nil) ⇒ WebhookSubscriptionsApi

Returns a new instance of WebhookSubscriptionsApi.



4
5
6
# File 'lib/square/api/webhook_subscriptions_api.rb', line 4

def initialize(config, http_call_back: nil)
  super(config, http_call_back: http_call_back)
end

Instance Method Details

#create_webhook_subscription(body:) ⇒ CreateWebhookSubscriptionResponse Hash

Creates a webhook subscription. object containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (CreateWebhookSubscriptionRequest)

    Required parameter: An

Returns:

  • (CreateWebhookSubscriptionResponse Hash)

    response from the API call



103
104
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
# File 'lib/square/api/webhook_subscriptions_api.rb', line 103

def create_webhook_subscription(body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/webhooks/subscriptions'
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#delete_webhook_subscription(subscription_id:) ⇒ DeleteWebhookSubscriptionResponse Hash

Deletes a webhook subscription. the [Subscription]($m/WebhookSubscription) to delete.

Parameters:

  • subscription_id (String)

    Required parameter: [REQUIRED] The ID of

Returns:

  • (DeleteWebhookSubscriptionResponse Hash)

    response from the API call



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/square/api/webhook_subscriptions_api.rb', line 136

def delete_webhook_subscription(subscription_id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/webhooks/subscriptions/{subscription_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'subscription_id' => { 'value' => subscription_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.delete(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#list_webhook_event_types(api_version: nil) ⇒ ListWebhookEventTypesResponse Hash

Lists all webhook event types that can be subscribed to. to list event types. Setting this field overrides the default version used by the application.

Parameters:

  • api_version (String) (defaults to: nil)

    Optional parameter: The API version for which

Returns:

  • (ListWebhookEventTypesResponse Hash)

    response from the API call



13
14
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
42
# File 'lib/square/api/webhook_subscriptions_api.rb', line 13

def list_webhook_event_types(api_version: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/webhooks/event-types'
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    'api_version' => api_version
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#list_webhook_subscriptions(cursor: nil, include_disabled: false, sort_order: nil, limit: nil) ⇒ ListWebhookSubscriptionsResponse Hash

Lists all webhook subscriptions owned by your application. a previous call to this endpoint. Provide this to retrieve the next set of results for your original query. For more information, see [Pagination](developer.squareup.com/docs/basics/api101/pagination) . Includes disabled [Subscription]($m/WebhookSubscription)s. By default, all enabled [Subscription]($m/WebhookSubscription)s are returned. by when the [Subscription]($m/WebhookSubscription) was created with the specified order. This field defaults to ASC. to be returned in a single page. It is possible to receive fewer results than the specified limit on a given page. The default value of 100 is also the maximum allowed value. Default: 100

Parameters:

  • cursor (String) (defaults to: nil)

    Optional parameter: A pagination cursor returned by

  • include_disabled (TrueClass|FalseClass) (defaults to: false)

    Optional parameter:

  • sort_order (SortOrder) (defaults to: nil)

    Optional parameter: Sorts the returned list

  • limit (Integer) (defaults to: nil)

    Optional parameter: The maximum number of results

Returns:

  • (ListWebhookSubscriptionsResponse Hash)

    response from the API call



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/square/api/webhook_subscriptions_api.rb', line 61

def list_webhook_subscriptions(cursor: nil,
                               include_disabled: false,
                               sort_order: nil,
                               limit: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/webhooks/subscriptions'
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    'cursor' => cursor,
    'include_disabled' => include_disabled,
    'sort_order' => sort_order,
    'limit' => limit
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#retrieve_webhook_subscription(subscription_id:) ⇒ RetrieveWebhookSubscriptionResponse Hash

Retrieves a webhook subscription identified by its ID. the [Subscription]($m/WebhookSubscription) to retrieve.

Parameters:

  • subscription_id (String)

    Required parameter: [REQUIRED] The ID of

Returns:

  • (RetrieveWebhookSubscriptionResponse Hash)

    response from the API call



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/square/api/webhook_subscriptions_api.rb', line 171

def retrieve_webhook_subscription(subscription_id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/webhooks/subscriptions/{subscription_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'subscription_id' => { 'value' => subscription_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#test_webhook_subscription(subscription_id:, body:) ⇒ TestWebhookSubscriptionResponse Hash

Tests a webhook subscription by sending a test event to the notification URL. the [Subscription]($m/WebhookSubscription) to test. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • subscription_id (String)

    Required parameter: [REQUIRED] The ID of

  • body (TestWebhookSubscriptionRequest)

    Required parameter: An object

Returns:

  • (TestWebhookSubscriptionResponse Hash)

    response from the API call



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/square/api/webhook_subscriptions_api.rb', line 293

def test_webhook_subscription(subscription_id:,
                              body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/webhooks/subscriptions/{subscription_id}/test'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'subscription_id' => { 'value' => subscription_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#update_webhook_subscription(subscription_id:, body:) ⇒ UpdateWebhookSubscriptionResponse Hash

Updates a webhook subscription. the [Subscription]($m/WebhookSubscription) to update. object containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • subscription_id (String)

    Required parameter: [REQUIRED] The ID of

  • body (UpdateWebhookSubscriptionRequest)

    Required parameter: An

Returns:

  • (UpdateWebhookSubscriptionResponse Hash)

    response from the API call



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/square/api/webhook_subscriptions_api.rb', line 209

def update_webhook_subscription(subscription_id:,
                                body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/webhooks/subscriptions/{subscription_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'subscription_id' => { 'value' => subscription_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.put(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#update_webhook_subscription_signature_key(subscription_id:, body:) ⇒ UpdateWebhookSubscriptionSignatureKeyResponse Hash

Updates a webhook subscription by replacing the existing signature key with a new one. the [Subscription]($m/WebhookSubscription) to update. parameter: An object containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • subscription_id (String)

    Required parameter: [REQUIRED] The ID of

  • body (UpdateWebhookSubscriptionSignatureKeyRequest)

    Required

Returns:

  • (UpdateWebhookSubscriptionSignatureKeyResponse Hash)

    response from the API call



251
252
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
279
280
281
282
283
# File 'lib/square/api/webhook_subscriptions_api.rb', line 251

def update_webhook_subscription_signature_key(subscription_id:,
                                              body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/webhooks/subscriptions/{subscription_id}/signature-key'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'subscription_id' => { 'value' => subscription_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end