Class: WebhookSystem::Job

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/webhook_system/job.rb

Overview

This is the ActiveJob in charge of actually sending each event

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.client_for(endpoint) ⇒ Object



18
19
20
21
22
23
# File 'lib/webhook_system/job.rb', line 18

def self.client_for(endpoint)
  Faraday.new(url: endpoint) do |faraday|
    faraday.response :logger if ENV['WEBHOOK_DEBUG']
    faraday.adapter Faraday.default_adapter
  end
end

.post(endpoint, payload) ⇒ Object



11
12
13
14
15
16
# File 'lib/webhook_system/job.rb', line 11

def self.post(endpoint, payload)
  client_for(endpoint).post do |req|
    req.headers['Content-Type'] = 'application/json; base64+aes256'
    req.body = payload.to_s
  end
end

Instance Method Details

#perform(subscription, event) ⇒ Object



6
7
8
9
# File 'lib/webhook_system/job.rb', line 6

def perform(subscription, event)
  payload = Encoder.encode(subscription.secret, event)
  self.class.post(subscription.url, payload)
end