rack-superfeedr 0.1.0 → 0.1.3
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.
- data/VERSION +1 -1
- data/lib/rack-superfeedr.rb +26 -6
- data/rack-superfeedr.gemspec +1 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/rack-superfeedr.rb
CHANGED
@@ -34,7 +34,9 @@ module Rack
|
|
34
34
|
@verifications[feed_id] ||= {}
|
35
35
|
@verifications[feed_id]['subscribe'] = block
|
36
36
|
end
|
37
|
-
|
37
|
+
endpoint = opts[:hub] || SUPERFEEDR_ENDPOINT
|
38
|
+
opts.delete(:hub)
|
39
|
+
response = ::Typhoeus::Request.post(endpoint,
|
38
40
|
opts.merge({
|
39
41
|
:params => {
|
40
42
|
:'hub.mode' => 'subscribe',
|
@@ -44,9 +46,13 @@ module Rack
|
|
44
46
|
},
|
45
47
|
:headers => {
|
46
48
|
:Accept => @params[:format] == "json" ? "application/json" : "application/atom+xml"
|
47
|
-
}
|
48
|
-
:userpwd => "#{@params[:login]}:#{@params[:password]}"
|
49
|
+
}
|
49
50
|
}))
|
51
|
+
|
52
|
+
if endpoint == SUPERFEEDR_ENDPOINT
|
53
|
+
opts[:userpwd] = "#{@params[:login]}:#{@params[:password]}"
|
54
|
+
end
|
55
|
+
|
50
56
|
@error = response.body
|
51
57
|
@params[:async] && response.code == 202 || response.code == 204 # We return true to indicate the status.
|
52
58
|
end
|
@@ -106,6 +112,17 @@ module Rack
|
|
106
112
|
self
|
107
113
|
end
|
108
114
|
|
115
|
+
def reset(params = {})
|
116
|
+
raise ArgumentError, 'Missing :host in params' unless params[:host]
|
117
|
+
raise ArgumentError, 'Missing :login in params' unless params[:login]
|
118
|
+
raise ArgumentError, 'Missing :password in params' unless params[:password]
|
119
|
+
@params = params
|
120
|
+
end
|
121
|
+
|
122
|
+
def params
|
123
|
+
@params
|
124
|
+
end
|
125
|
+
|
109
126
|
def call(env)
|
110
127
|
req = Rack::Request.new(env)
|
111
128
|
if env['REQUEST_METHOD'] == 'GET' && feed_id = env['PATH_INFO'].match(/\/superfeedr\/feed\/(.*)/)
|
@@ -124,6 +141,8 @@ module Rack
|
|
124
141
|
elsif env['REQUEST_METHOD'] == 'POST' && feed_id = env['PATH_INFO'].match(/\/superfeedr\/feed\/(.*)/)
|
125
142
|
# Notification
|
126
143
|
content = nil
|
144
|
+
# Body is a stream, not a string, so capture it once and save it
|
145
|
+
body = req.body.read
|
127
146
|
if env["CONTENT_TYPE"]
|
128
147
|
content_type = env["CONTENT_TYPE"].split(";").first
|
129
148
|
else
|
@@ -131,13 +150,14 @@ module Rack
|
|
131
150
|
end
|
132
151
|
if content_type == "application/json"
|
133
152
|
# Let's parse the body as JSON
|
134
|
-
content = JSON.parse(
|
153
|
+
content = JSON.parse(body)
|
135
154
|
elsif content_type == "application/atom+xml"
|
136
155
|
# Let's parse the body as ATOM using nokogiri
|
137
|
-
content = Nokogiri.XML(
|
156
|
+
content = Nokogiri.XML(body)
|
138
157
|
end
|
139
158
|
# Let's now send that data back to the user.
|
140
|
-
|
159
|
+
info = Hashie::Mash.new(req: req, body: body)
|
160
|
+
if !@callback.call(content, feed_id[1], info)
|
141
161
|
# We need to unsubscribe the user
|
142
162
|
end
|
143
163
|
Rack::Response.new("Thanks!", 200).finish
|
data/rack-superfeedr.gemspec
CHANGED
@@ -50,6 +50,7 @@ Gem::Specification.new do |s|
|
|
50
50
|
s.add_runtime_dependency(%q<rack>, [">= 0"])
|
51
51
|
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
52
52
|
s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
|
53
|
+
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
53
54
|
else
|
54
55
|
s.add_dependency(%q<rack>, [">= 0"])
|
55
56
|
s.add_dependency(%q<nokogiri>, [">= 0"])
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rack-superfeedr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- julien51
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2013-03
|
13
|
+
date: 2013-07-03 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rack
|
@@ -157,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
157
|
requirements:
|
158
158
|
- - ">="
|
159
159
|
- !ruby/object:Gem::Version
|
160
|
-
hash:
|
160
|
+
hash: 1522793861721834200
|
161
161
|
segments:
|
162
162
|
- 0
|
163
163
|
version: "0"
|