Class: Pubsubhubbub::DeliverPayloadJob

Inherits:
ApplicationJob
  • Object
show all
Includes:
Utils
Defined in:
app/jobs/pubsubhubbub/deliver_payload_job.rb

Instance Method Summary collapse

Methods included from Utils

#http_client

Instance Method Details

#perform(hub_url, subscription_id, current_payload) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/jobs/pubsubhubbub/deliver_payload_job.rb', line 9

def perform(hub_url, subscription_id, current_payload)
  subscription = Subscription.find(subscription_id)
  link         = LinkHeader.new([[hub_url, [%w(rel hub)]], [subscription.topic, [%w(rel self)]]])
  headers      = {}

  headers['Link']            = link.to_s
  headers['X-Hub-Signature'] = sign_payload(subscription.secret, current_payload) if subscription.secret

  response = http_client.headers(headers).post(subscription.callback, body: current_payload)

  raise FailedDeliveryError unless response.code > 199 && response.code < 300
end