rack-superfeedr 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,8 +3,8 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem 'rack'
6
- gem 'nokogiri'
7
- gem 'typhoeus'
6
+ gem 'nokogiri', ">=1.6.1"
7
+ gem 'typhoeus', ">=0.6.7"
8
8
 
9
9
 
10
10
  # Add dependencies to develop your gem here.
data/Gemfile.lock CHANGED
@@ -79,7 +79,7 @@ PLATFORMS
79
79
  DEPENDENCIES
80
80
  bundler (>= 1.0.0)
81
81
  jeweler (>= 1.6.4)
82
- nokogiri
82
+ nokogiri (>= 1.6.1)
83
83
  rack
84
84
  shoulda
85
- typhoeus
85
+ typhoeus (>= 0.6.7)
data/README.rdoc CHANGED
@@ -41,5 +41,5 @@ You can then access the Superfeedr object anywhere in your rails application wit
41
41
 
42
42
  == Copyright
43
43
 
44
- Copyright (c) 2012 Superfeedr. See LICENSE.txt for further details.
44
+ Copyright (c) 2014 Superfeedr. See LICENSE.txt for further details.
45
45
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.2.0
@@ -2,7 +2,7 @@ require 'sinatra'
2
2
  require(File.join(File.dirname(__FILE__), '..', 'lib', 'rack-superfeedr.rb'))
3
3
 
4
4
 
5
- use Rack::Superfeedr, { :host => "pstx.showoff.io", :login => "demo", :password => "demo", :format => "json", :async => false } do |superfeedr|
5
+ use Rack::Superfeedr, { :host => "pstx.showoff.io", :login => "julien", :password => "f8054b405e68aa2067df25fb21665bab", :format => "json", :async => false } do |superfeedr|
6
6
  set :superfeedr, superfeedr # so that we can use `settings.superfeedr` to access the superfeedr object in our application.
7
7
 
8
8
  superfeedr.on_notification do |notification|
@@ -16,7 +16,7 @@ get '/hi' do
16
16
  end
17
17
 
18
18
  get '/subscribe' do
19
- subscription = settings.superfeedr.subscribe("http://push-pub.appspot.com/feed")
19
+ subscription = settings.superfeedr.subscribe("http://push-pub.appspot.com/feed", 9999, { verbose: true, retrieve: true })
20
20
  if !subscription
21
21
  settings.superfeedr.error
22
22
  else
@@ -28,6 +28,8 @@ module Rack
28
28
  # It returns true if the subscription was successful (or will be confirmed if you used async => true in the options), false otherwise.
29
29
  # You can also pass an opts third argument that will be merged with the options used in Typhoeus's Request (https://github.com/dbalatero/typhoeus)
30
30
  # A useful option is :verbose => true for example.
31
+ # If you supply a retrieve option, the content of the feed will be retrieved from Superfeedr as well and your on_notification callback will
32
+ # will be called with the content of the feed.
31
33
  def subscribe(url, id = nil, opts = {}, &block)
32
34
  feed_id = "#{id ? id : Base64.urlsafe_encode64(url)}"
33
35
  if block
@@ -37,25 +39,55 @@ module Rack
37
39
  endpoint = opts[:hub] || SUPERFEEDR_ENDPOINT
38
40
  opts.delete(:hub)
39
41
 
42
+ retrieve = opts[:retrieve] || false
43
+ opts.delete(:retrieve)
44
+
45
+
40
46
  if endpoint == SUPERFEEDR_ENDPOINT
41
47
  opts[:userpwd] = "#{@params[:login]}:#{@params[:password]}"
42
48
  end
43
49
 
44
- response = ::Typhoeus::Request.post(endpoint,
45
- opts.merge({
50
+
51
+ opts = opts.merge({
46
52
  :params => {
47
53
  :'hub.mode' => 'subscribe',
48
- :'hub.verify' => @params[:async] ? 'async' : 'sync',
49
54
  :'hub.topic' => url,
50
55
  :'hub.callback' => generate_callback(url, feed_id)
51
56
  },
52
57
  :headers => {
53
58
  :Accept => @params[:format] == "json" ? "application/json" : "application/atom+xml"
54
59
  }
55
- }))
60
+ })
61
+
62
+ if retrieve
63
+ opts[:params][:retrieve] = true
64
+ end
65
+
66
+ opts[:params][:'hub.verify'] = @params[:async] ? 'async' : 'sync',
67
+
68
+ response = ::Typhoeus::Request.post(endpoint, opts)
56
69
 
57
70
  @error = response.body
58
- @params[:async] && response.code == 202 || response.code == 204 # We return true to indicate the status.
71
+ if !retrieve
72
+ @params[:async] && response.code == 202 || response.code == 204 # We return true to indicate the status.
73
+ else
74
+
75
+ if @params[:format] != "json"
76
+ content = Nokogiri.XML(response.body)
77
+ else
78
+ content = JSON.parse(response.body)
79
+
80
+ end
81
+ # Let's now send that data back to the user.
82
+ if defined? Hashie::Mash
83
+ info = Hashie::Mash.new(req: req, body: body)
84
+ end
85
+ if !@callback.call(content, feed_id, info)
86
+ # We need to unsubscribe the user
87
+ end
88
+
89
+ true
90
+ end
59
91
  end
60
92
 
61
93
  ##
@@ -159,7 +191,9 @@ module Rack
159
191
  content = Nokogiri.XML(body)
160
192
  end
161
193
  # Let's now send that data back to the user.
162
- info = Hashie::Mash.new(req: req, body: body)
194
+ if defined? Hashie::Mash
195
+ info = Hashie::Mash.new(req: req, body: body)
196
+ end
163
197
  if !@callback.call(content, feed_id[1], info)
164
198
  # We need to unsubscribe the user
165
199
  end
@@ -2,15 +2,14 @@
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.1.6 ruby lib
6
5
 
7
6
  Gem::Specification.new do |s|
8
7
  s.name = "rack-superfeedr"
9
- s.version = "0.1.6"
8
+ s.version = "0.2.0"
10
9
 
11
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
11
  s.authors = ["julien51"]
13
- s.date = "2014-01-28"
12
+ s.date = "2014-06-10"
14
13
  s.description = "A gem that provides a rack middleware to interract with Superfeedr's API. "
15
14
  s.email = "julien@superfeedr.com"
16
15
  s.extra_rdoc_files = [
@@ -34,31 +33,31 @@ Gem::Specification.new do |s|
34
33
  s.homepage = "http://rubygems.org/gems/rack-superfeedr"
35
34
  s.licenses = ["MIT"]
36
35
  s.require_paths = ["lib"]
37
- s.rubygems_version = "2.1.10"
36
+ s.rubygems_version = "1.8.25"
38
37
  s.summary = "A gem that provides a rack middleware to interract with Superfeedr's API."
39
38
 
40
39
  if s.respond_to? :specification_version then
41
- s.specification_version = 4
40
+ s.specification_version = 3
42
41
 
43
42
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
43
  s.add_runtime_dependency(%q<rack>, [">= 0"])
45
- s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
46
- s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
44
+ s.add_runtime_dependency(%q<nokogiri>, [">= 1.6.1"])
45
+ s.add_runtime_dependency(%q<typhoeus>, [">= 0.6.7"])
47
46
  s.add_development_dependency(%q<shoulda>, [">= 0"])
48
47
  s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
49
48
  s.add_development_dependency(%q<jeweler>, [">= 1.6.4"])
50
49
  else
51
50
  s.add_dependency(%q<rack>, [">= 0"])
52
- s.add_dependency(%q<nokogiri>, [">= 0"])
53
- s.add_dependency(%q<typhoeus>, [">= 0"])
51
+ s.add_dependency(%q<nokogiri>, [">= 1.6.1"])
52
+ s.add_dependency(%q<typhoeus>, [">= 0.6.7"])
54
53
  s.add_dependency(%q<shoulda>, [">= 0"])
55
54
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
56
55
  s.add_dependency(%q<jeweler>, [">= 1.6.4"])
57
56
  end
58
57
  else
59
58
  s.add_dependency(%q<rack>, [">= 0"])
60
- s.add_dependency(%q<nokogiri>, [">= 0"])
61
- s.add_dependency(%q<typhoeus>, [">= 0"])
59
+ s.add_dependency(%q<nokogiri>, [">= 1.6.1"])
60
+ s.add_dependency(%q<typhoeus>, [">= 0.6.7"])
62
61
  s.add_dependency(%q<shoulda>, [">= 0"])
63
62
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
64
63
  s.add_dependency(%q<jeweler>, [">= 1.6.4"])
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-superfeedr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - julien51
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-01-28 00:00:00.000000000 Z
12
+ date: 2014-06-10 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rack
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ! '>='
25
28
  - !ruby/object:Gem::Version
@@ -27,34 +30,39 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: nokogiri
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
- version: '0'
37
+ version: 1.6.1
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
- version: '0'
45
+ version: 1.6.1
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: typhoeus
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
- version: '0'
53
+ version: 0.6.7
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
- version: '0'
61
+ version: 0.6.7
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: shoulda
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ! '>='
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ! '>='
67
76
  - !ruby/object:Gem::Version
@@ -69,6 +78,7 @@ dependencies:
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: bundler
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - ! '>='
74
84
  - !ruby/object:Gem::Version
@@ -76,6 +86,7 @@ dependencies:
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
91
  - - ! '>='
81
92
  - !ruby/object:Gem::Version
@@ -83,6 +94,7 @@ dependencies:
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: jeweler
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
99
  - - ! '>='
88
100
  - !ruby/object:Gem::Version
@@ -90,6 +102,7 @@ dependencies:
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
107
  - - ! '>='
95
108
  - !ruby/object:Gem::Version
@@ -118,25 +131,29 @@ files:
118
131
  homepage: http://rubygems.org/gems/rack-superfeedr
119
132
  licenses:
120
133
  - MIT
121
- metadata: {}
122
134
  post_install_message:
123
135
  rdoc_options: []
124
136
  require_paths:
125
137
  - lib
126
138
  required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
127
140
  requirements:
128
141
  - - ! '>='
129
142
  - !ruby/object:Gem::Version
130
143
  version: '0'
144
+ segments:
145
+ - 0
146
+ hash: 1737679521327129604
131
147
  required_rubygems_version: !ruby/object:Gem::Requirement
148
+ none: false
132
149
  requirements:
133
150
  - - ! '>='
134
151
  - !ruby/object:Gem::Version
135
152
  version: '0'
136
153
  requirements: []
137
154
  rubyforge_project:
138
- rubygems_version: 2.1.10
155
+ rubygems_version: 1.8.25
139
156
  signing_key:
140
- specification_version: 4
157
+ specification_version: 3
141
158
  summary: A gem that provides a rack middleware to interract with Superfeedr's API.
142
159
  test_files: []
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZjlhYzhjODNjMjUxZTE5MDhlZTdhOGQ5ZGVjZGQyMTNmYzJlMzQ1Nw==
5
- data.tar.gz: !binary |-
6
- ZGUxMGJkODE2NjIwYTk1Y2Q2MzI3NzRlNDJjNjViYmQwZGJjNGRlOA==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- MzRjNzhiOWIzMWJlNzQ2Y2RiNjIyMTc0Y2MyZjg5NDg0NzZmMzM3Y2UzMTQz
10
- ODJmZTBjZjMwMDM0YjU5ODE2Yzg4NDRkZjE0M2RiYzMyZjY5NTk2ZDAzZjZl
11
- YTU0MDEwOTA3MTI3ZGNiZmFiMTc5MTQ1NTQ5Y2RiZWZmMDFjMDg=
12
- data.tar.gz: !binary |-
13
- Y2YzMmY2MWM3OTRhOWQ1MmI3ZjY0MmY4NjNhZDIwYzc2MmM0OWU3ZmVmMjQ4
14
- YTU4YWNmNmFkZWFlMjc3MTkyYWQ2YmRlYTQ5OWI4MzUzZmY3ZGRlMzIzMTM3
15
- ZjE0OTdiZWQ5NDg5N2Q1YjRlNzhkNmU4MTM0MGU4MzAzZjI3OGM=