pubsubhubbub-rails 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e1e57ed25a60b5353d6a2a0be5383ec687f5348
4
- data.tar.gz: fe069db3bb82d6b97c480d6081074190cb2ba4f5
3
+ metadata.gz: 6349db14daf275336a05ef0f3eb475254dffe6bc
4
+ data.tar.gz: c8ce75a29351f825b8d1c799dd33665c555ba063
5
5
  SHA512:
6
- metadata.gz: 5495c78dc0562ff98871987caa3a4c0bfc4729e0fa981bf7ab58cb7b6440675dbfeb3527849205d614726dafbd10d3da2fe06fd9cbbbb3f0c34531ed2fef572c
7
- data.tar.gz: 7d67a52dc39f8c60c093f45b90b9636bededbbcb6271e12e84a1594be2363bd496dd127cea21314bb8ae2edc05a64018504a61dfbe652411ebfaae70bccaceba
6
+ metadata.gz: 545bfa9f131ed04832b7ecea89f0ac91883de681f4aafec1b4ff8cb8f3f3557b5d5175bb095acd0abbabc4f82bd8688a0684466e9568174d3af0138249933a8f
7
+ data.tar.gz: 737998e5e77034a4875dffb4451306b7aa37abbda116423fc6894bf1e677657e5e25269f44f3de6aeb4fa7aea96596306031932f5d6211976ae6e3e2b0658f88
data/README.md CHANGED
@@ -12,17 +12,17 @@ This is a mountable PubSubHubbub server conforming to the v0.4 of the spec.
12
12
 
13
13
  In `routes.rb`:
14
14
 
15
- mount Pubsubhubbub::Engine => '/pubsubhubbub', as: :pubsubhubbub
15
+ mount Pubsubhubbub::Engine, at: 'pubsubhubbub', as: :pubsubhubbub
16
16
 
17
17
  In feed:
18
18
 
19
- <link rel="hub" href="<%= pubsubhubbub_hub_url %>" />
19
+ <link rel="hub" href="<%= pubsubhubbub_url %>" />
20
20
 
21
21
  ## Installation
22
22
  Add this line to your application's Gemfile:
23
23
 
24
24
  ```ruby
25
- gem 'pubsubhubbub-rails'
25
+ gem 'pubsubhubbub-rails', require: 'pubsubhubbub'
26
26
  ```
27
27
 
28
28
  And then execute:
@@ -3,6 +3,10 @@ require_dependency 'pubsubhubbub/application_controller'
3
3
 
4
4
  module Pubsubhubbub
5
5
  class SubscriptionsController < ApplicationController
6
+ rescue_from ValidationError do |msg|
7
+ render plain: msg, status: :unprocessable_entity
8
+ end
9
+
6
10
  def index
7
11
  @callback = params['hub.callback']
8
12
  @mode = params['hub.mode']
@@ -19,13 +23,13 @@ module Pubsubhubbub
19
23
  when 'publish'
20
24
  publish
21
25
  else
22
- render plain: 'Unknown mode', status: :unprocessable_entity
26
+ raise ValidationError, "Unknown mode: #{@mode}"
23
27
  end
24
28
  end
25
29
 
26
30
  private
27
31
 
28
- def check_topic_hub
32
+ def check_topic_hub!
29
33
  uri = Addressable::URI.parse(@topic)
30
34
  response = HTTP.get(uri)
31
35
 
@@ -34,7 +38,7 @@ module Pubsubhubbub
34
38
  hub = link.find_link(%w(rel hub))
35
39
  topic = link.find_link(%w(rel self))
36
40
 
37
- return true if hub&.href == hub_url && topic&.href == @topic
41
+ return if hub&.href&.chomp('\\') == hub_url.chomp('\\') && topic&.href&.chomp('\\') == @topic.chomp('\\')
38
42
  end
39
43
 
40
44
  xml = Nokogiri::XML(response.body)
@@ -43,13 +47,14 @@ module Pubsubhubbub
43
47
  link = xml.at_xpath('//xmlns:link[@rel="hub"]', xmlns: XMLNS)
44
48
  topic = xml.at_xpath('//xmlns:link[@rel="self"]', xmlns: XMLNS)
45
49
 
46
- link&.attribute('href')&.value == hub_url && topic&.attribute('href')&.value == @topic
50
+ raise ValidationError, "Topic advertises different hub: #{link&.attribute('href')&.value}" if link&.attribute('href')&.value&.chomp('\\') != hub_url.chomp('\\')
51
+ raise ValidationError, "Topic advertises different self: #{topic&.attribute('href')&.value}" if topic&.attribute('href')&.value&.chomp('\\') != @topic.chomp('\\')
47
52
  end
48
53
 
49
54
  def subscribe
50
- render(plain: 'Missing callback URL', status: :unprocessable_entity) && return if @callback.blank?
51
- render(plain: 'Missing topic URL', status: :unprocessable_entity) && return if @topic.blank?
52
- render(plain: 'Topic advertises a different hub or topic URL', status: :unprocessable_entity) && return unless check_topic_hub
55
+ raise ValidationError, 'Missing callback URL' if @callback.blank?
56
+ raise ValidationError, 'Missing topic URL' if @topic.blank?
57
+ check_topic_hub!
53
58
 
54
59
  @subscription = Subscription.where(topic: @topic, callback: @callback).first_or_initialize(topic: @topic, callback: @callback, mode: @mode, secret: @secret)
55
60
  @subscription.lease_seconds = @lease_seconds
@@ -61,9 +66,9 @@ module Pubsubhubbub
61
66
  end
62
67
 
63
68
  def unsubscribe
64
- render(plain: 'Missing callback URL', status: :unprocessable_entity) && return if @callback.blank?
65
- render(plain: 'Missing topic URL', status: :unprocessable_entity) && return if @topic.blank?
66
- render(plain: 'Topic advertises a different hub or topic URL', status: :unprocessable_entity) && return unless check_topic_hub
69
+ raise ValidationError, 'Missing callback URL' if @callback.blank?
70
+ raise ValidationError, 'Missing topic URL' if @topic.blank?
71
+ check_topic_hub!
67
72
 
68
73
  @subscription = Subscription.where(topic: @topic, callback: @callback).first
69
74
 
@@ -77,7 +82,7 @@ module Pubsubhubbub
77
82
  end
78
83
 
79
84
  def publish
80
- render(plain: 'Missing URL', status: :unprocessable_entity) && return if @url.blank?
85
+ raise ValidationError, 'Missing URL' if @url.blank?
81
86
  FetchTopicJob.perform_later(hub_url, @url)
82
87
  head 202
83
88
  end
data/lib/pubsubhubbub.rb CHANGED
@@ -11,4 +11,7 @@ module Pubsubhubbub
11
11
 
12
12
  class FailedDeliveryError < StandardError
13
13
  end
14
+
15
+ class ValidationError < StandardError
16
+ end
14
17
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Pubsubhubbub
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
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.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugen Rochko