Class: Webhooker::TriggerJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/webhooker/trigger_job.rb

Instance Method Summary collapse

Instance Method Details

#create_signature(body) ⇒ Object



22
23
24
# File 'app/jobs/webhooker/trigger_job.rb', line 22

def create_signature body
  OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), @subscriber.secret, body)
end

#perform(subscriber, payload) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/jobs/webhooker/trigger_job.rb', line 5

def perform subscriber, payload
  @subscriber = subscriber
  uri = URI.parse subscriber.url
  req = Net::HTTP::Post.new(uri.path)
  req.set_form_data payload
  Net::HTTP.new(uri.host, uri.port).start do |http|
    app = Rails.application.class.parent.to_s
    body = payload.to_json
    header = {
      'Content-Type' => 'application/json; charset=utf-8',
      'User-Agent' => app,
      "X-#{app}-Signature" => create_signature(body)
    }
    http.post uri.path, body, header
  end
end