pubsubhubbub-rails 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/app/controllers/pubsubhubbub/subscriptions_controller.rb +16 -11
- data/lib/pubsubhubbub.rb +3 -0
- data/lib/pubsubhubbub/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6349db14daf275336a05ef0f3eb475254dffe6bc
|
4
|
+
data.tar.gz: c8ce75a29351f825b8d1c799dd33665c555ba063
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
15
|
+
mount Pubsubhubbub::Engine, at: 'pubsubhubbub', as: :pubsubhubbub
|
16
16
|
|
17
17
|
In feed:
|
18
18
|
|
19
|
-
<link rel="hub" href="<%=
|
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
|
-
|
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
|
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
|
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
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
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
data/lib/pubsubhubbub/version.rb
CHANGED