Class: Square::Webhooks::Subscriptions::Client

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

Instance Method Summary collapse

Constructor Details

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



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

def initialize(client:)
  @client = client
end

Instance Method Details

#create(request_options: {}, **params) ⇒ Square::Types::CreateWebhookSubscriptionResponse

Creates a webhook subscription.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/square/webhooks/subscriptions/client.rb', line 37

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

  raise _response.body
end

#delete(request_options: {}, **params) ⇒ Square::Types::DeleteWebhookSubscriptionResponse

Deletes a webhook subscription.



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/square/webhooks/subscriptions/client.rb', line 92

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

  raise _response.body
end

#get(request_options: {}, **params) ⇒ Square::Types::GetWebhookSubscriptionResponse

Retrieves a webhook subscription identified by its ID.



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/square/webhooks/subscriptions/client.rb', line 55

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

  raise _response.body
end

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

Lists all webhook subscriptions owned by your application.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/square/webhooks/subscriptions/client.rb', line 15

def list(request_options: {}, **params)
  _query_param_names = %w[cursor include_disabled sort_order limit]
  _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/webhooks/subscriptions",
    query: _query
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::ListWebhookSubscriptionsResponse.load(_response.body)
  end

  raise _response.body
end

#test(request_options: {}, **params) ⇒ Square::Types::TestWebhookSubscriptionResponse

Tests a webhook subscription by sending a test event to the notification URL.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/square/webhooks/subscriptions/client.rb', line 129

def test(request_options: {}, **params)
  _path_param_names = ["subscription_id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/webhooks/subscriptions/#{params[:subscription_id]}/test",
    body: params.except(*_path_param_names)
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::TestWebhookSubscriptionResponse.load(_response.body)
  end

  raise _response.body
end

#update(request_options: {}, **params) ⇒ Square::Types::UpdateWebhookSubscriptionResponse

Updates a webhook subscription.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/square/webhooks/subscriptions/client.rb', line 72

def update(request_options: {}, **params)
  _path_param_names = ["subscription_id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "PUT",
    path: "v2/webhooks/subscriptions/#{params[:subscription_id]}",
    body: params.except(*_path_param_names)
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::UpdateWebhookSubscriptionResponse.load(_response.body)
  end

  raise _response.body
end

#update_signature_key(request_options: {}, **params) ⇒ Square::Types::UpdateWebhookSubscriptionSignatureKeyResponse

Updates a webhook subscription by replacing the existing signature key with a new one.



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/square/webhooks/subscriptions/client.rb', line 109

def update_signature_key(request_options: {}, **params)
  _path_param_names = ["subscription_id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/webhooks/subscriptions/#{params[:subscription_id]}/signature-key",
    body: params.except(*_path_param_names)
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::UpdateWebhookSubscriptionSignatureKeyResponse.load(_response.body)
  end

  raise _response.body
end