pubsubhubbub-rails 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db805f0b5e1c3942f199fa90c96179beda252310
4
- data.tar.gz: c23a61d4bf6e18e322021f7c7c3fb9a034b4aca4
3
+ metadata.gz: 8c675e536b288c0e673e17095e1e71e9e3291b29
4
+ data.tar.gz: f483dbe28eeb7c04504e8860fa2c89f337475085
5
5
  SHA512:
6
- metadata.gz: b6e44824c58667cc3ff7dd580fd66e9f79f84817cf76d5cb6db0d4abcee43ec476e40401c2af71c65746641992b0441c5215d2eedeee2460eb3e93947564e503
7
- data.tar.gz: 4862e4e6728fb2db4b28ad93ac1b9cd0006b36ea0a4a71c9c6cfd17d0514e8dfe8227e12e73ef991be2bb8ad468c27913436158f4e22b28a872e0d28be620b95
6
+ metadata.gz: 1682d9bd26db344a7e292b7682dcfc9c690c625059fbda7a0e9c23ab67409945f22a7deedaf78bf617b221ec9fc2c0a6939c62311a0208e3e3d1b8eeed07f3fe
7
+ data.tar.gz: 5c9f2ad9eec55148d473ec582ec7e34ab4e53a0fce946e23d65390f34e99a80957cdddb75c1557eb2c4bd4b7998030fa47f0396ffee8c1d73cd5ed336843302d
@@ -3,6 +3,8 @@ require_dependency 'pubsubhubbub/application_controller'
3
3
 
4
4
  module Pubsubhubbub
5
5
  class SubscriptionsController < ApplicationController
6
+ include Pubsubhubbub::Utils
7
+
6
8
  rescue_from ValidationError do |msg|
7
9
  render plain: msg, status: :unprocessable_entity
8
10
  end
@@ -33,7 +35,7 @@ module Pubsubhubbub
33
35
  return Pubsubhubbub.verify_topic.call(@topic) if Pubsubhubbub.verify_topic.is_a?(Proc)
34
36
 
35
37
  uri = Addressable::URI.parse(@topic)
36
- response = HTTP.get(uri)
38
+ response = http_client.get(uri)
37
39
 
38
40
  if response['Link']
39
41
  link = LinkHeader.parse(response['Link'].is_a?(Array) ? response['Link'].first : response['Link'])
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Pubsubhubbub
4
4
  class DeliverPayloadJob < ApplicationJob
5
+ include Pubsubhubbub::Utils
6
+
5
7
  queue_as :push
6
8
 
7
9
  def perform(hub_url, subscription_id, current_payload)
@@ -12,9 +14,7 @@ module Pubsubhubbub
12
14
  headers['Link'] = link.to_s
13
15
  headers['X-Hub-Signature'] = sign_payload(subscription.secret, current_payload) if subscription.secret
14
16
 
15
- response = HTTP.timeout(:per_operation, write: 60, connect: 20, read: 60)
16
- .headers(headers)
17
- .post(subscription.callback, body: current_payload)
17
+ response = http_client.headers(headers).post(subscription.callback, body: current_payload)
18
18
 
19
19
  raise FailedDeliveryError unless response.code > 199 && response.code < 300
20
20
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  module Pubsubhubbub
3
3
  class FetchTopicJob < ApplicationJob
4
+ include Pubsubhubbub::Utils
5
+
4
6
  queue_as :push
5
7
 
6
8
  def perform(hub_url, url)
@@ -9,7 +11,7 @@ module Pubsubhubbub
9
11
  current_payload = if Pubsubhubbub.render_topic.is_a?(Proc)
10
12
  Pubsubhubbub.render_topic.call(url)
11
13
  else
12
- HTTP.timeout(:per_operation, write: 60, connect: 20, read: 60).get(url).body.to_s
14
+ http_client.get(url).body.to_s
13
15
  end
14
16
 
15
17
  Subscription.where(topic: url).active.find_each do |subscription|
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  module Pubsubhubbub
3
3
  class VerifyIntentJob < ApplicationJob
4
+ include Pubsubhubbub::Utils
5
+
4
6
  queue_as :push
5
7
 
6
8
  def perform(subscription_id)
@@ -18,7 +20,7 @@ module Pubsubhubbub
18
20
 
19
21
  def verify_intent(subscription)
20
22
  uri = Addressable::URI.parse(subscription.callback)
21
- response = HTTP.timeout(:per_operation, write: 60, connect: 20, read: 60).get(uri, params: { 'hub.mode' => subscription.mode, 'hub.topic' => subscription.topic, 'hub.challenge' => subscription.challenge, 'hub.lease_seconds' => subscription.lease_seconds })
23
+ response = http_client.get(uri, params: { 'hub.mode' => subscription.mode, 'hub.topic' => subscription.topic, 'hub.challenge' => subscription.challenge, 'hub.lease_seconds' => subscription.lease_seconds })
22
24
  response.code > 199 && response.code < 300 && response.body.to_s == subscription.challenge
23
25
  end
24
26
  end
data/lib/pubsubhubbub.rb CHANGED
@@ -4,7 +4,6 @@ require 'addressable/uri'
4
4
  require 'nokogiri'
5
5
  require 'http'
6
6
  require 'link_header'
7
- require 'httplog'
8
7
 
9
8
  module Pubsubhubbub
10
9
  XMLNS = 'http://www.w3.org/2005/Atom'
@@ -21,4 +20,11 @@ module Pubsubhubbub
21
20
  def self.publish(hub_url, topic_url)
22
21
  FetchTopicJob.perform_later(hub_url, topic_url)
23
22
  end
23
+
24
+ module Utils
25
+ def http_client
26
+ HTTP.timeout(:per_operation, write: 30, connect: 20, read: 30)
27
+ .headers(user_agent: "PubSubHubbub/#{Pubsubhubbub::VERSION}")
28
+ end
29
+ end
24
30
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Pubsubhubbub
3
- VERSION = '0.2.6'
3
+ VERSION = '0.3.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubsubhubbub-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugen Rochko