Class: QiwiObserver::WebhookRemoval

Inherits:
Object
  • Object
show all
Defined in:
lib/qiwi_observer/webhook/webhook_removal.rb

Instance Method Summary collapse

Constructor Details

#initialize(hook_id) ⇒ WebhookRemoval

Returns a new instance of WebhookRemoval.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
# File 'lib/qiwi_observer/webhook/webhook_removal.rb', line 5

def initialize(hook_id)
  @token = QiwiObserver.config.token
  @hook_id = hook_id

  raise ArgumentError, "QiwiObserver must be configure with token" if @token.nil?
  raise ArgumentError, "Hook ID must be set" unless hook_id
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
# File 'lib/qiwi_observer/webhook/webhook_removal.rb', line 13

def call
  uri = URI("https://edge.qiwi.com/payment-notifier/v1/hooks/#{@hook_id}")
  request = prepare_a_request(uri)
  http = connect_to_api(uri)
  response = http.request(request)
  return WebhookResponse.new(success: true, body: response.body) if response.is_a?(Net::HTTPOK)
  return WebhookResponse.new(success: false, body: [response.code, response.message])
end