rack-superfeedr 0.4.1 → 0.4.2
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 +64 -56
- data/rack-superfeedr.gemspec +1 -1
- data/test/test_rack-superfeedr.rb +100 -14
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
data/lib/rack-superfeedr.rb
CHANGED
@@ -4,69 +4,69 @@ require 'uri'
|
|
4
4
|
|
5
5
|
module SuperfeedrAPI
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
@@superfeedr_endpoint = "https://push.superfeedr.com/"
|
8
|
+
@@port = 80
|
9
|
+
@@host = 'my-app.com'
|
10
|
+
@@base_path = '/superfeedr/feed/'
|
11
|
+
@@scheme = 'http'
|
12
|
+
@@login = nil
|
13
|
+
@@password = nil
|
14
|
+
|
15
|
+
def superfeedr_endpoint= _superfeedr_endpoint
|
16
|
+
@@superfeedr_endpoint = _superfeedr_endpoint
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
def superfeedr_endpoint
|
20
|
+
@@superfeedr_endpoint
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def port= _port
|
24
|
+
@@port = _port
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def port
|
28
|
+
@@port
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
def host= _host
|
32
|
+
@@host = _host
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
def base_path= _base_path
|
40
|
-
@@base_path = _base_path
|
41
|
-
end
|
35
|
+
def host
|
36
|
+
@@host
|
37
|
+
end
|
42
38
|
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
def base_path= _base_path
|
40
|
+
@@base_path = _base_path
|
41
|
+
end
|
46
42
|
|
47
|
-
|
48
|
-
|
49
|
-
|
43
|
+
def base_path
|
44
|
+
@@base_path
|
45
|
+
end
|
50
46
|
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
def scheme= _scheme
|
48
|
+
@@scheme = _scheme
|
49
|
+
end
|
54
50
|
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
def scheme
|
52
|
+
@@scheme
|
53
|
+
end
|
58
54
|
|
59
|
-
|
60
|
-
|
61
|
-
|
55
|
+
def login= _login
|
56
|
+
@@login = _login
|
57
|
+
end
|
62
58
|
|
63
|
-
|
64
|
-
|
65
|
-
|
59
|
+
def login
|
60
|
+
@@login
|
61
|
+
end
|
66
62
|
|
67
|
-
|
68
|
-
|
69
|
-
|
63
|
+
def password= _password
|
64
|
+
@@password = _password
|
65
|
+
end
|
66
|
+
|
67
|
+
def password
|
68
|
+
@@password
|
69
|
+
end
|
70
70
|
|
71
71
|
##
|
72
72
|
# Subscribe you to a url. id is optional but strongly recommanded has a unique identifier for this url. It will be used to help you identify which feed
|
@@ -104,7 +104,11 @@ module SuperfeedrAPI
|
|
104
104
|
|
105
105
|
response = http_post(endpoint, request)
|
106
106
|
|
107
|
-
|
107
|
+
r = [response.body, opts[:async] && Integer(response.code) == 202 || Integer(response.code) == 204 || opts[:retrieve] && Integer(response.code) == 200, response]
|
108
|
+
if blk
|
109
|
+
blk.call(r)
|
110
|
+
end
|
111
|
+
r
|
108
112
|
end
|
109
113
|
|
110
114
|
##
|
@@ -136,11 +140,11 @@ module SuperfeedrAPI
|
|
136
140
|
|
137
141
|
response = http_get(endpoint, request)
|
138
142
|
|
143
|
+
r = [response.body, Integer(response.code) == 200, response]
|
139
144
|
if blk
|
140
|
-
blk.call(
|
141
|
-
else
|
142
|
-
[response.body, Integer(response.code) == 200, response]
|
145
|
+
blk.call(r)
|
143
146
|
end
|
147
|
+
r
|
144
148
|
end
|
145
149
|
|
146
150
|
##
|
@@ -167,7 +171,11 @@ module SuperfeedrAPI
|
|
167
171
|
|
168
172
|
response = http_post(endpoint, request)
|
169
173
|
|
170
|
-
|
174
|
+
r = response.body, opts[:async] && Integer(response.code) == 202 || Integer(response.code) == 204, response
|
175
|
+
if blk
|
176
|
+
blk.call(r)
|
177
|
+
end
|
178
|
+
r
|
171
179
|
end
|
172
180
|
|
173
181
|
protected
|
data/rack-superfeedr.gemspec
CHANGED
@@ -56,36 +56,121 @@ Rack::Superfeedr.password = PASSWORD
|
|
56
56
|
|
57
57
|
class TestRackSuperfeedr < Test::Unit::TestCase
|
58
58
|
|
59
|
-
context "
|
59
|
+
context "Without Callbacks" do
|
60
60
|
|
61
|
-
|
62
|
-
|
61
|
+
context "Subscribing" do
|
62
|
+
|
63
|
+
should "yield true with a simple subscribe" do
|
64
|
+
body, success, response = Rack::Superfeedr.subscribe('http://push-pub.appspot.com/feed', '12345')
|
63
65
|
success || flunk("Fail")
|
64
66
|
end
|
65
|
-
end
|
66
67
|
|
67
|
-
|
68
|
-
|
68
|
+
should "support sync mode and call the verification callback before yielding true" do
|
69
|
+
body, success, response = Rack::Superfeedr.subscribe('http://push-pub.appspot.com/feed', 'accept-subscribe', {:sync => true})
|
69
70
|
success || flunk("Fail")
|
70
71
|
end
|
71
|
-
end
|
72
72
|
|
73
|
-
|
74
|
-
|
73
|
+
should "support sync mode and call the verification callback before yielding false if verification fails" do
|
74
|
+
body, success, response = Rack::Superfeedr.subscribe('http://push-pub.appspot.com/feed', 'refuse-subscribe', {:sync => true})
|
75
75
|
!success || flunk('Fail')
|
76
76
|
end
|
77
|
+
|
78
|
+
should "support async mode and yield true" do
|
79
|
+
body, success, response = Rack::Superfeedr.subscribe('http://push-pub.appspot.com/feed', 'refuse-subscribe', {:async => true})
|
80
|
+
success || flunk("Fail")
|
81
|
+
end
|
82
|
+
|
83
|
+
should "return the content of Atom subscriptions with retrieve" do
|
84
|
+
body, success, response = Rack::Superfeedr.subscribe('http://push-pub.appspot.com/feed', '1234', {:retrieve => true})
|
85
|
+
assert_equal "application/atom+xml", response['Content-Type']
|
86
|
+
success || flunk("Fail")
|
87
|
+
assert body
|
88
|
+
end
|
89
|
+
|
90
|
+
should "return the content of Json subscriptions with retrieve" do
|
91
|
+
body, success, response = Rack::Superfeedr.subscribe('http://push-pub.appspot.com/feed', '1234', {:format => "json", :retrieve => true})
|
92
|
+
assert_equal "application/json; charset=utf-8", response['Content-Type']
|
93
|
+
success || flunk("Fail")
|
94
|
+
assert body
|
95
|
+
end
|
77
96
|
end
|
78
97
|
|
79
|
-
|
80
|
-
|
98
|
+
context "Unsubscribing" do
|
99
|
+
should 'successfully unsubscribe with 204 when not using sync nor asyc' do
|
100
|
+
body, success, response = Rack::Superfeedr.unsubscribe('http://push-pub.appspot.com/feed', '12345')
|
101
|
+
success || flunk("Fail")
|
102
|
+
end
|
103
|
+
|
104
|
+
should 'successfully unsubscribe with 204 when using sync when verification yields true' do
|
105
|
+
body, success, response = Rack::Superfeedr.unsubscribe('http://push-pub.appspot.com/feed', 'accept-unsubscribe', {:sync => true})
|
106
|
+
success || flunk("Fail")
|
107
|
+
end
|
108
|
+
|
109
|
+
should 'fail to unsubscribe with 204 when using sync when verification yields false' do
|
110
|
+
body, success, response = Rack::Superfeedr.unsubscribe('http://push-pub.appspot.com/feed', 'refuse-unsubscribe', {:sync => true})
|
111
|
+
!success || flunk('Fail')
|
112
|
+
end
|
113
|
+
|
114
|
+
should 'return 202 when using async' do
|
115
|
+
body, success, response = Rack::Superfeedr.unsubscribe('http://push-pub.appspot.com/feed', 'accept-unsubscribe', {:async => true})
|
81
116
|
success || flunk("Fail")
|
82
117
|
end
|
83
118
|
end
|
84
119
|
|
85
|
-
|
86
|
-
|
87
|
-
|
120
|
+
context "Retrieving" do
|
121
|
+
should 'yield content from Superfeedr in Atom when asking for no specific format' do
|
122
|
+
body, success, response = Rack::Superfeedr.retrieve_by_topic_url('http://push-pub.appspot.com/feed')
|
88
123
|
success || flunk("Fail")
|
124
|
+
end
|
125
|
+
|
126
|
+
should 'yield content from Superfeedr in JSON when asking for JSON' do
|
127
|
+
body, success, response = Rack::Superfeedr.retrieve_by_topic_url('http://push-pub.appspot.com/feed', {:format => 'json'})
|
128
|
+
success || flunk("Fail")
|
129
|
+
hash = JSON.parse body
|
130
|
+
hash['status'] || flunk("Not JSON")
|
131
|
+
end
|
132
|
+
|
133
|
+
should 'yield content from Superfeedr in JSON when asking for JSON and only yield the right number of items' do
|
134
|
+
body, success, response = Rack::Superfeedr.retrieve_by_topic_url('http://push-pub.appspot.com/feed', {:format => 'json', :count => 3})
|
135
|
+
success || flunk("Fail")
|
136
|
+
hash = JSON.parse body
|
137
|
+
hash['items'].length == 3 || flunk("Not the right number of items")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context "With Callbacks" do
|
143
|
+
|
144
|
+
context "Subscribing" do
|
145
|
+
|
146
|
+
should "yield true with a simple subscribe" do
|
147
|
+
Rack::Superfeedr.subscribe('http://push-pub.appspot.com/feed', '12345') do |body, success, response|
|
148
|
+
success || flunk("Fail")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
should "support sync mode and call the verification callback before yielding true" do
|
153
|
+
Rack::Superfeedr.subscribe('http://push-pub.appspot.com/feed', 'accept-subscribe', {:sync => true}) do |body, success, response|
|
154
|
+
success || flunk("Fail")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
should "support sync mode and call the verification callback before yielding false if verification fails" do
|
159
|
+
Rack::Superfeedr.subscribe('http://push-pub.appspot.com/feed', 'refuse-subscribe', {:sync => true}) do |body, success, response|
|
160
|
+
!success || flunk('Fail')
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
should "support async mode and yield true" do
|
165
|
+
Rack::Superfeedr.subscribe('http://push-pub.appspot.com/feed', 'refuse-subscribe', {:async => true}) do |body, success, response|
|
166
|
+
success || flunk("Fail")
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
should "return the content of Atom subscriptions with retrieve" do
|
171
|
+
Rack::Superfeedr.subscribe('http://push-pub.appspot.com/feed', '1234', {:retrieve => true}) do |body, success, response|
|
172
|
+
assert_equal "application/atom+xml", response['Content-Type']
|
173
|
+
success || flunk("Fail")
|
89
174
|
assert body # Some XML
|
90
175
|
end
|
91
176
|
end
|
@@ -149,6 +234,7 @@ class TestRackSuperfeedr < Test::Unit::TestCase
|
|
149
234
|
end
|
150
235
|
end
|
151
236
|
end
|
237
|
+
end
|
152
238
|
|
153
239
|
context "Notifications" do
|
154
240
|
should 'handle json notifications'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-superfeedr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -159,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
159
|
version: '0'
|
160
160
|
segments:
|
161
161
|
- 0
|
162
|
-
hash:
|
162
|
+
hash: 4382464025338648913
|
163
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
164
|
none: false
|
165
165
|
requirements:
|