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

#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from Square::BaseApi

Instance Method Details

#create_webhook_subscription(body:) ⇒ ApiResponse

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:

  • (ApiResponse)

    the complete http response with raw body and status code.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/square/api/webhook_subscriptions_api.rb', line 67

def create_webhook_subscription(body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/webhooks/subscriptions',
                                 'default')
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:json_deserialize))
                .is_api_response(true)
                .convertor(ApiResponse.method(:create)))
    .execute
end

#delete_webhook_subscription(subscription_id:) ⇒ ApiResponse

Deletes a webhook subscription. the [Subscription](entity:WebhookSubscription) to delete.

Parameters:

  • subscription_id (String)

    Required parameter: [REQUIRED] The ID of

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/square/api/webhook_subscriptions_api.rb', line 88

def delete_webhook_subscription(subscription_id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/v2/webhooks/subscriptions/{subscription_id}',
                                 'default')
               .template_param(new_parameter(subscription_id, key: 'subscription_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:json_deserialize))
                .is_api_response(true)
                .convertor(ApiResponse.method(:create)))
    .execute
end

#list_webhook_event_types(api_version: nil) ⇒ ApiResponse

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:

  • (ApiResponse)

    the complete http response with raw body and status code.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/square/api/webhook_subscriptions_api.rb', line 9

def list_webhook_event_types(api_version: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/webhooks/event-types',
                                 'default')
               .query_param(new_parameter(api_version, key: 'api_version'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:json_deserialize))
                .is_api_response(true)
                .convertor(ApiResponse.method(:create)))
    .execute
end

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

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/build-basics/common-api-p atterns/pagination). Includes disabled [Subscription](entity:WebhookSubscription)s. By default, all enabled [Subscription](entity:WebhookSubscription)s are returned. by when the [Subscription](entity: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:

  • (ApiResponse)

    the complete http response with raw body and status code.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/square/api/webhook_subscriptions_api.rb', line 41

def list_webhook_subscriptions(cursor: nil,
                               include_disabled: false,
                               sort_order: nil,
                               limit: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/webhooks/subscriptions',
                                 'default')
               .query_param(new_parameter(cursor, key: 'cursor'))
               .query_param(new_parameter(include_disabled, key: 'include_disabled'))
               .query_param(new_parameter(sort_order, key: 'sort_order'))
               .query_param(new_parameter(limit, key: 'limit'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:json_deserialize))
                .is_api_response(true)
                .convertor(ApiResponse.method(:create)))
    .execute
end

#retrieve_webhook_subscription(subscription_id:) ⇒ ApiResponse

Retrieves a webhook subscription identified by its ID. the [Subscription](entity:WebhookSubscription) to retrieve.

Parameters:

  • subscription_id (String)

    Required parameter: [REQUIRED] The ID of

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/square/api/webhook_subscriptions_api.rb', line 108

def retrieve_webhook_subscription(subscription_id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/webhooks/subscriptions/{subscription_id}',
                                 'default')
               .template_param(new_parameter(subscription_id, key: 'subscription_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:json_deserialize))
                .is_api_response(true)
                .convertor(ApiResponse.method(:create)))
    .execute
end

#test_webhook_subscription(subscription_id:, body:) ⇒ ApiResponse

Tests a webhook subscription by sending a test event to the notification URL. the [Subscription](entity: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:

  • (ApiResponse)

    the complete http response with raw body and status code.



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/square/api/webhook_subscriptions_api.rb', line 187

def test_webhook_subscription(subscription_id:,
                              body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/webhooks/subscriptions/{subscription_id}/test',
                                 'default')
               .template_param(new_parameter(subscription_id, key: 'subscription_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:json_deserialize))
                .is_api_response(true)
                .convertor(ApiResponse.method(:create)))
    .execute
end

#update_webhook_subscription(subscription_id:, body:) ⇒ ApiResponse

Updates a webhook subscription. the [Subscription](entity: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:

  • (ApiResponse)

    the complete http response with raw body and status code.



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/square/api/webhook_subscriptions_api.rb', line 131

def update_webhook_subscription(subscription_id:,
                                body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/v2/webhooks/subscriptions/{subscription_id}',
                                 'default')
               .template_param(new_parameter(subscription_id, key: 'subscription_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:json_deserialize))
                .is_api_response(true)
                .convertor(ApiResponse.method(:create)))
    .execute
end

#update_webhook_subscription_signature_key(subscription_id:, body:) ⇒ ApiResponse

Updates a webhook subscription by replacing the existing signature key with a new one. the [Subscription](entity: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:

  • (ApiResponse)

    the complete http response with raw body and status code.



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/square/api/webhook_subscriptions_api.rb', line 159

def update_webhook_subscription_signature_key(subscription_id:,
                                              body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/webhooks/subscriptions/{subscription_id}/signature-key',
                                 'default')
               .template_param(new_parameter(subscription_id, key: 'subscription_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:json_deserialize))
                .is_api_response(true)
                .convertor(ApiResponse.method(:create)))
    .execute
end