class Amorail::Webhook

AmoCRM webhook entity

Public Class Methods

list() click to toggle source
# File lib/amorail/entities/webhook.rb, line 10
def self.list
  response = client.safe_request(:get, remote_url('list'))

  return [] if response.body.blank?

  response.body['response'].fetch(amo_response_name, []).map do |attributes|
    new.reload_model(attributes)
  end
end
subscribe(webhooks) click to toggle source
# File lib/amorail/entities/webhook.rb, line 20
def self.subscribe(webhooks)
  perform_webhooks_request('subscribe', webhooks) do |data|
    data.map { |attrs| new.reload_model(attrs) }
  end
end
unsubscribe(webhooks) click to toggle source
# File lib/amorail/entities/webhook.rb, line 26
def self.unsubscribe(webhooks)
  perform_webhooks_request('unsubscribe', webhooks)
end

Private Class Methods

perform_webhooks_request(action, webhooks, &block) click to toggle source
# File lib/amorail/entities/webhook.rb, line 30
def self.perform_webhooks_request(action, webhooks, &block)
  response = client.safe_request(
    :post,
    remote_url(action),
    request: { webhooks: { action => webhooks } }
  )

  return response unless block

  block.call(response.body['response'].dig(amo_response_name, 'subscribe'))
end