rack-superfeedr 0.4.3 → 0.4.4

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmNlOGUxM2U3N2Q4ZTEzZDlhYTkyOGFjYTA3Zjg4ODRlNDI4ZDlkYw==
4
+ MWZjMDczMTYyZWNhN2I4Zjg2NjA3NDg0YTdhNDBjZWMzMTBmNGUzMg==
5
5
  data.tar.gz: !binary |-
6
- YWU4ZjlmZmQ1ZDI2ZGNkZmFkNjkwMDQ3MjA5ZjUxZTVkNjg3OTMwMg==
6
+ MDJhNjBlMDEwNzc3NWNhYzc5MWI4Yjc2NWYzNzY3NDNlYTJiM2U0ZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- M2UxM2E1Njc1NzlhZDRkZjZjNTIwZWIzNmM3NTBjYjk1ZTI0ODBlOTE4ZmJj
10
- ZjI0NTdlY2IzZjc5ZmQ0Y2Y0MmE4N2JjNzNkNjg5MGU0YjYxNzgwNGUxZjEy
11
- M2VmNzc2MmI0MTkwM2U5NGFiMDI4NWUwYzBlMDk2MTk2YjVhMGE=
9
+ NWI4MjQ3ODg1Y2YzZTI2MDAwZDI3ZjkwMzM3M2FhMThiNThlNGQ1YWI1NTA5
10
+ NGJiM2NiNWNhZWJhMzgwYjJkYjRlMTlhNTg3MzBmZDI1ZjRhYmQ3NDhmMjM5
11
+ ODJkOTdlMmZhZWMxYTQ5ZDMyOWU1YWY4ZGZmY2JkYzUyZWQ5OWM=
12
12
  data.tar.gz: !binary |-
13
- MDAyM2ViZTExZWY4NGRlODVhM2ViYmYzODI4NjNlZTZiYzdkY2JmZjZhMWE1
14
- NThkNGM0OTc0MDdjOTVlNDg4ZDYxYjdmOTc4ZDBiNmEyODVlNWUxMDRmMzNl
15
- NmRhZDE0N2FjYWJkYzY2M2QyZDUzMmI2NTFiMzQ5OWY3ZDlmNmM=
13
+ MmJiYzMwMTQ0NzQxOTNlODhkYjMyMGFhNmE0OWZmOTMzODI3ZDgwMWI2Y2Y2
14
+ MGEyNGM5MGQ3YTc3YzFhYTQwNmViNzI2NzVjOGE5ZTZkMmNhOWVjMjI4OGYy
15
+ YjIxZDY5NjFmZTA1MDQ4MTdhNDVmNzcxNGE3OWY3NzBmZThmOWY=
@@ -3,7 +3,7 @@
3
3
  A gem that provides a rack middleware to interact with {Superfeedr}[http://superfeedr.com/]'s PubSubHubbub API. It let you *subscribe*, *unsubscribe* and *receive* incoming feed notifications.
4
4
  This should work with any Rack-compatible framework, as well as fully managed platforms like {Heroku}[http://www.heroku.com/].
5
5
 
6
- Warning : version 0.3 (July 2014) introduces a lot of breaking changes compared to previous versions. Upgrade carefully!
6
+ If you're looking to integrate into a Rails application, we suggest you check this {Rails Engine}[https://rubygems.org/gems/superfeedr_engine], which is more suited and will handle a lot more things on your behalf!
7
7
 
8
8
  == Installing
9
9
 
@@ -19,16 +19,6 @@ You first need a {subscriber account}[http://superfeedr.com/subscriber] with Sup
19
19
 
20
20
  See the {example}[https://github.com/superfeedr/rack-superfeedr/blob/master/examples/sinatra_app.rb]... and {check the docs}[http://rubydoc.info/github/superfeedr/rack-superfeedr/master/Rack/Superfeedr] for more details.
21
21
 
22
- === Rails
23
-
24
- Tested with Rails 3.2, but should work with any Rails version that supports Rack.
25
-
26
- Install the gem (using bundle), and then in <code>config/application.rb</code>, inside the <code>class Application < Rails::Application</code> block, just add the following line.
27
-
28
- config.middleware.use Rack::Superfeedr do |superfeedr|
29
- ...
30
- end
31
-
32
22
 
33
23
  == Contributing
34
24
 
@@ -41,5 +31,5 @@ Install the gem (using bundle), and then in <code>config/application.rb</code>,
41
31
 
42
32
  == Copyright
43
33
 
44
- Copyright (c) 2014 Superfeedr. See LICENSE.txt for further details.
34
+ Copyright (c) 2015 Superfeedr. See LICENSE.txt for further details.
45
35
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.4.4
@@ -197,7 +197,11 @@ module SuperfeedrAPI
197
197
  request['search'] = opts[:search]
198
198
  end
199
199
 
200
- request['authorization'] = Base64.encode64( "#{@@login}:#{@@password}" ).chomp
200
+ if opts[:login] && opts[:password]
201
+ request['authorization'] = Base64.encode64( "#{opts[:login]}:#{opts[:password]}" ).chomp
202
+ else
203
+ request['authorization'] = Base64.encode64( "#{@@login}:#{@@password}" ).chomp
204
+ end
201
205
 
202
206
  response = http_get(endpoint, request)
203
207
 
@@ -206,7 +210,34 @@ module SuperfeedrAPI
206
210
  blk.call(r)
207
211
  end
208
212
  r
213
+ end
214
+
215
+ def search(query, opts = {}, &blk)
216
+ endpoint = @@superfeedr_endpoint
217
+ request = {
218
+ 'hub.mode' => 'search',
219
+ 'detailed' => true
220
+ }
221
+
222
+ if opts[:format] == "json"
223
+ request['format'] = "json"
224
+ end
209
225
 
226
+ if opts[:login] && opts[:password]
227
+ request['authorization'] = Base64.encode64( "#{opts[:login]}:#{opts[:password]}" ).chomp
228
+ else
229
+ request['authorization'] = Base64.encode64( "#{@@login}:#{@@password}" ).chomp
230
+ end
231
+
232
+ request['query'] = query
233
+
234
+ response = http_post(endpoint, request)
235
+
236
+ r = [response.body, Integer(response.code) == 200, response]
237
+ if blk
238
+ blk.call(r)
239
+ end
240
+ r
210
241
  end
211
242
 
212
243
  protected
@@ -219,7 +250,9 @@ module SuperfeedrAPI
219
250
  'hub.callback' => generate_callback(url, feed_id)
220
251
  }
221
252
 
222
- if endpoint == @@superfeedr_endpoint && @@login && @@password
253
+ if opts[:login] && opts[:password]
254
+ request['authorization'] = Base64.encode64( "#{opts[:login]}:#{opts[:password]}" ).chomp
255
+ elsif @@login && @@password
223
256
  request['authorization'] = Base64.encode64( "#{@@login}:#{@@password}" ).chomp
224
257
  end
225
258
 
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: rack-superfeedr 0.4.3 ruby lib
5
+ # stub: rack-superfeedr 0.4.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "rack-superfeedr"
9
- s.version = "0.4.3"
9
+ s.version = "0.4.4"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["julien51"]
14
- s.date = "2015-04-17"
14
+ s.date = "2015-04-23"
15
15
  s.description = "A gem that provides a rack middleware to interract with Superfeedr's API. "
16
16
  s.email = "julien@superfeedr.com"
17
17
  s.extra_rdoc_files = [
@@ -3,7 +3,7 @@ require 'rack'
3
3
  require_relative 'helper.rb'
4
4
 
5
5
  # To run tests locally, we're using runscope's passageway which proxies requests inside the firewall. (make sure you bind to port 4567)
6
- HOST = '39fbb9eba21.b.passageway.io'
6
+ HOST = '4da832710d5.b.passageway.io'
7
7
  PORT = 80
8
8
  # Also, we need superfeedr credentials.
9
9
  LOGIN = 'demo'
@@ -28,20 +28,20 @@ Thread.new do
28
28
  AccessLog: []
29
29
  }
30
30
  Rack::Handler::WEBrick.run(Rack::Superfeedr.new(MyRackApp.new) do |superfeedr|
31
-
32
- superfeedr.on_verification do |mode, feed_id, url, request|
33
- if mode == 'subscribe' && feed_id == 'accept-subscribe'
34
- true
35
- elsif mode == 'unsubscribe' && feed_id == 'accept-unsubscribe'
36
- true
37
- else
38
- false
39
- end
40
- end
41
31
 
42
- superfeedr.on_notification do |url, feed_id, details|
43
- notified(url, feed_id, details)
44
- end
32
+ superfeedr.on_verification do |mode, feed_id, url, request|
33
+ if mode == 'subscribe' && feed_id == 'accept-subscribe'
34
+ true
35
+ elsif mode == 'unsubscribe' && feed_id == 'accept-unsubscribe'
36
+ true
37
+ else
38
+ false
39
+ end
40
+ end
41
+
42
+ superfeedr.on_notification do |url, feed_id, details|
43
+ notified(url, feed_id, details)
44
+ end
45
45
 
46
46
 
47
47
  end, opts)
@@ -148,6 +148,21 @@ class TestRackSuperfeedr < Test::Unit::TestCase
148
148
  hash['items'].length == 3 || flunk("Not the right number of items")
149
149
  end
150
150
  end
151
+
152
+ context "Searching" do
153
+ should 'yield content from Superfeedr in Atom when asking for no specific format' do
154
+ body, success, response = Rack::Superfeedr.search('superfeedr', {:login => 'tracker', :password => 'a0234221feebbd9c1ee30d33a49c505d'})
155
+ success || flunk("Fail")
156
+ end
157
+
158
+ should 'yield content from Superfeedr in JSON when asking for JSON' do
159
+ body, success, response = Rack::Superfeedr.search('superfeedr', {:login => 'tracker', :password => 'a0234221feebbd9c1ee30d33a49c505d', :format => 'json'})
160
+ success || flunk("Fail")
161
+ hash = JSON.parse body
162
+ hash['status'] || flunk("Not JSON")
163
+ end
164
+
165
+ end
151
166
  end
152
167
 
153
168
  context "With Callbacks" do
@@ -182,70 +197,70 @@ class TestRackSuperfeedr < Test::Unit::TestCase
182
197
  Rack::Superfeedr.subscribe('http://push-pub.appspot.com/feed', '1234', {:retrieve => true}) do |body, success, response|
183
198
  assert_equal "application/atom+xml", response['Content-Type']
184
199
  success || flunk("Fail")
185
- assert body # Some XML
200
+ assert body
201
+ end
186
202
  end
187
- end
188
203
 
189
- should "return the content of Json subscriptions with retrieve" do
190
- response = Rack::Superfeedr.subscribe('http://push-pub.appspot.com/feed', '1234', {:format => "json", :retrieve => true}) do |body, success, response|
191
- assert_equal "application/json; charset=utf-8", response['Content-Type']
192
- success || flunk("Fail")
193
- assert body
204
+ should "return the content of Json subscriptions with retrieve" do
205
+ response = Rack::Superfeedr.subscribe('http://push-pub.appspot.com/feed', '1234', {:format => "json", :retrieve => true}) do |body, success, response|
206
+ assert_equal "application/json; charset=utf-8", response['Content-Type']
207
+ success || flunk("Fail")
208
+ assert body
209
+ end
194
210
  end
195
- end
196
211
 
197
- end
212
+ end
198
213
 
199
- context "Unsubscribing" do
200
- should 'successfully unsubscribe with 204 when not using sync nor asyc' do
201
- Rack::Superfeedr.unsubscribe('http://push-pub.appspot.com/feed', '12345') do |body, success, response|
202
- success || flunk("Fail")
214
+ context "Unsubscribing" do
215
+ should 'successfully unsubscribe with 204 when not using sync nor asyc' do
216
+ Rack::Superfeedr.unsubscribe('http://push-pub.appspot.com/feed', '12345') do |body, success, response|
217
+ success || flunk("Fail")
218
+ end
203
219
  end
204
- end
205
220
 
206
- should 'successfully unsubscribe with 204 when using sync when verification yields true' do
207
- Rack::Superfeedr.unsubscribe('http://push-pub.appspot.com/feed', 'accept-unsubscribe', {:sync => true}) do |body, success, response|
208
- success || flunk("Fail")
221
+ should 'successfully unsubscribe with 204 when using sync when verification yields true' do
222
+ Rack::Superfeedr.unsubscribe('http://push-pub.appspot.com/feed', 'accept-unsubscribe', {:sync => true}) do |body, success, response|
223
+ success || flunk("Fail")
224
+ end
209
225
  end
210
- end
211
226
 
212
- should 'fail to unsubscribe with 204 when using sync when verification yields false' do
213
- Rack::Superfeedr.unsubscribe('http://push-pub.appspot.com/feed', 'refuse-unsubscribe', {:sync => true}) do |body, success, response|
214
- !success || flunk('Fail')
227
+ should 'fail to unsubscribe with 204 when using sync when verification yields false' do
228
+ Rack::Superfeedr.unsubscribe('http://push-pub.appspot.com/feed', 'refuse-unsubscribe', {:sync => true}) do |body, success, response|
229
+ !success || flunk('Fail')
230
+ end
215
231
  end
216
- end
217
232
 
218
- should 'return 202 when using async' do
219
- Rack::Superfeedr.unsubscribe('http://push-pub.appspot.com/feed', 'accept-unsubscribe', {:async => true}) do |body, success, response|
220
- success || flunk("Fail")
233
+ should 'return 202 when using async' do
234
+ Rack::Superfeedr.unsubscribe('http://push-pub.appspot.com/feed', 'accept-unsubscribe', {:async => true}) do |body, success, response|
235
+ success || flunk("Fail")
236
+ end
221
237
  end
222
238
  end
223
- end
224
239
 
225
- context "Retrieving" do
226
- should 'yield content from Superfeedr in Atom when asking for no specific format' do
227
- Rack::Superfeedr.retrieve_by_topic_url('http://push-pub.appspot.com/feed') do |body, success, response|
228
- success || flunk("Fail")
229
- end
230
- end
240
+ context "Retrieving" do
241
+ should 'yield content from Superfeedr in Atom when asking for no specific format' do
242
+ Rack::Superfeedr.retrieve_by_topic_url('http://push-pub.appspot.com/feed') do |body, success, response|
243
+ success || flunk("Fail")
244
+ end
245
+ end
231
246
 
232
- should 'yield content from Superfeedr in JSON when asking for JSON' do
233
- Rack::Superfeedr.retrieve_by_topic_url('http://push-pub.appspot.com/feed', {:format => 'json'}) do |body, success, response|
234
- success || flunk("Fail")
235
- hash = JSON.parse body
236
- hash['status'] || flunk("Not JSON")
237
- end
238
- end
247
+ should 'yield content from Superfeedr in JSON when asking for JSON' do
248
+ Rack::Superfeedr.retrieve_by_topic_url('http://push-pub.appspot.com/feed', {:format => 'json'}) do |body, success, response|
249
+ success || flunk("Fail")
250
+ hash = JSON.parse body
251
+ hash['status'] || flunk("Not JSON")
252
+ end
253
+ end
239
254
 
240
- should 'yield content from Superfeedr in JSON when asking for JSON and only yield the right number of items' do
241
- Rack::Superfeedr.retrieve_by_topic_url('http://push-pub.appspot.com/feed', {:format => 'json', :count => 3}) do |body, success, response|
242
- success || flunk("Fail")
243
- hash = JSON.parse body
244
- hash['items'].length == 3 || flunk("Not the right number of items")
245
- end
255
+ should 'yield content from Superfeedr in JSON when asking for JSON and only yield the right number of items' do
256
+ Rack::Superfeedr.retrieve_by_topic_url('http://push-pub.appspot.com/feed', {:format => 'json', :count => 3}) do |body, success, response|
257
+ success || flunk("Fail")
258
+ hash = JSON.parse body
259
+ hash['items'].length == 3 || flunk("Not the right number of items")
260
+ end
261
+ end
246
262
  end
247
263
  end
248
- end
249
264
 
250
265
  context "Notifications" do
251
266
  should 'handle json notifications'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-superfeedr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - julien51
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-17 00:00:00.000000000 Z
11
+ date: 2015-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack