radamanthus-superfeedr-ruby 0.4.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.
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/iq_query_stanza_spec'
3
+ describe SubscribeQueryStanza do
4
+
5
+ it_should_behave_like "Iq Query Stanzas"
6
+
7
+ before(:each) do
8
+ @params = { :type => "set", :from => "me@server.com/resource", :nodes => ["http//domain.tld/feed.xml"], :type => "set", :from => "me@server.com/resource"}
9
+ end
10
+
11
+ it "should have the right node value" do
12
+ SubscribeQueryStanza.new(@params).nodes.should == @params[:nodes]
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/iq_query_stanza_spec'
3
+ describe SubscriptionsQueryStanza do
4
+
5
+ it_should_behave_like "Iq Query Stanzas"
6
+
7
+ before(:each) do
8
+ @params = { :type => "set", :from => "me@server.com/resource", :page => 3, :type => "set", :from => "me@server.com/resource"}
9
+ end
10
+
11
+ it "should have the right page value" do
12
+ SubscriptionsQueryStanza.new(@params).page.should == @params[:page].to_s
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/iq_query_stanza_spec'
3
+ describe UnsubscribeQueryStanza do
4
+
5
+ it_should_behave_like "Iq Query Stanzas"
6
+
7
+ before(:each) do
8
+ @params = { :type => "set", :from => "me@server.com/resource", :nodes => ["http//domain.tld/feed.xml", "http//domain.tld/feed2.xml"], :type => "set", :from => "me@server.com/resource"}
9
+ end
10
+
11
+ it "should have the right node value" do
12
+ UnsubscribeQueryStanza.new(@params).nodes.should == @params[:nodes]
13
+ end
14
+
15
+ end
@@ -0,0 +1,237 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Superfeedr do
4
+
5
+ before(:each) do
6
+ @mock_connection = mock(Skates::XmppConnection, {:send_xml => true, :jid => "client@server.tld/resource"})
7
+ end
8
+
9
+ describe "connect" do
10
+ end
11
+
12
+ describe "on_stanza" do
13
+ end
14
+
15
+
16
+ describe "subscribe" do
17
+ it "should call add_feeds with feeds supplied" do
18
+ feeds = ["a"] * 50
19
+ Superfeedr.should_receive(:add_feeds).with(["a"] * 30).and_yield(true)
20
+ Superfeedr.should_receive(:add_feeds).with(["a"] * 20).and_yield(true)
21
+ Superfeedr.subscribe(feeds) do |result|
22
+ result.should be_true
23
+ end
24
+ end
25
+ end
26
+
27
+ describe "unsubscribe" do
28
+ it "should call remove_feeds with feeds supplied" do
29
+ feeds = ["a"] * 40
30
+ Superfeedr.should_receive(:remove_feeds).with(["a"] * 30).and_yield(true)
31
+ Superfeedr.should_receive(:remove_feeds).with(["a"] * 10).and_yield(true)
32
+ Superfeedr.unsubscribe(feeds) do |result|
33
+ result.should be_true
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "subscriptions" do
39
+ it "should call subscriptions_by_page for each page as long as they're not empty" do
40
+ def method_called_upon_page
41
+ end
42
+ self.should_receive(:method_called_upon_page).exactly(4).times
43
+ 3.times do |t|
44
+ Superfeedr.should_receive(:subscriptions_by_page).with(t+1).and_yield( t+1 , ["a", "b", "c"])
45
+ end
46
+ Superfeedr.should_receive(:subscriptions_by_page).with(4).and_yield(4, [])
47
+ Superfeedr.subscriptions do |page, result|
48
+ method_called_upon_page
49
+ end
50
+ end
51
+ end
52
+
53
+
54
+ describe "add_feeds" do
55
+ before(:each) do
56
+ Superfeedr.stub!(:connection).and_return(@mock_connection)
57
+ Superfeedr.stub!(:send).and_return(true)
58
+ @block = Proc.new {
59
+
60
+ }
61
+ @node = "http://domain.com/feed.xml"
62
+ @mock_stanza = mock(SubscribeQueryStanza, {:id => "123"})
63
+ SubscribeQueryStanza.stub!(:new).and_return(@mock_stanza)
64
+ end
65
+
66
+ it "should raise an error if not connected" do
67
+ Superfeedr.should_receive(:connection).and_return(nil)
68
+ lambda {
69
+ Superfeedr.add_feeds(@node, &@block)
70
+ }.should raise_error(Superfeedr::NotConnected)
71
+ end
72
+
73
+ it "should create a new SubscribeQueryStanza with the right url" do
74
+ SubscribeQueryStanza.should_receive(:new).with({:nodes => @node, :from => @mock_connection.jid}).and_return(@mock_stanza)
75
+ Superfeedr.add_feeds(@node, &@block)
76
+ end
77
+
78
+ it "should add a Proc that just calls the block in params to the @@callbacks" do
79
+ Superfeedr.add_feeds(@node, &@block)
80
+ Superfeedr.callbacks[@mock_stanza.id][:method].should == Superfeedr.method(:on_subscribe)
81
+ Superfeedr.callbacks[@mock_stanza.id][:param].should == @block
82
+ end
83
+
84
+ it "should send the stanza" do
85
+ Superfeedr.should_receive(:send).with(@mock_stanza).and_return(true)
86
+ Superfeedr.add_feeds(@node, &@block)
87
+ end
88
+ end
89
+
90
+ describe "remove_feeds" do
91
+ before(:each) do
92
+ Superfeedr.stub!(:connection).and_return(@mock_connection)
93
+ Superfeedr.stub!(:send).and_return(true)
94
+ @block = Proc.new {
95
+
96
+ }
97
+ @nodes = ["http://domain.com/feed.xml"]
98
+ @mock_stanza = mock(UnsubscribeQueryStanza, {:id => "123"})
99
+ UnsubscribeQueryStanza.stub!(:new).and_return(@mock_stanza)
100
+ end
101
+
102
+ it "should raise an error if not connected" do
103
+ Superfeedr.should_receive(:connection).and_return(nil)
104
+ lambda {
105
+ Superfeedr.remove_feeds(@nodes, &@block)
106
+ }.should raise_error(Superfeedr::NotConnected)
107
+ end
108
+
109
+ it "should create a new SubscribeQueryStanza with the right url" do
110
+ UnsubscribeQueryStanza.should_receive(:new).with({:nodes => @nodes, :from => @mock_connection.jid}).and_return(@mock_stanza)
111
+ Superfeedr.remove_feeds(@nodes, &@block)
112
+ end
113
+
114
+ it "should add a Proc that just calls the block in params to the @@callbacks" do
115
+ Superfeedr.remove_feeds(@nodes, &@block)
116
+ Superfeedr.callbacks[@mock_stanza.id][:method].should == Superfeedr.method(:on_unsubscribe)
117
+ Superfeedr.callbacks[@mock_stanza.id][:param].should == @block
118
+ end
119
+
120
+ it "should send the stanza" do
121
+ Superfeedr.should_receive(:send).with(@mock_stanza).and_return(true)
122
+ Superfeedr.remove_feeds(@nodes, &@block)
123
+ end
124
+ end
125
+
126
+ describe "subscriptions_by_page" do
127
+ before(:each) do
128
+ Superfeedr.stub!(:connection).and_return(@mock_connection)
129
+ Superfeedr.stub!(:send).and_return(true)
130
+ @block = Proc.new {
131
+
132
+ }
133
+ @page = 3
134
+ @mock_stanza = mock(SubscriptionsQueryStanza, {:id => "123"})
135
+ SubscriptionsQueryStanza.stub!(:new).and_return(@mock_stanza)
136
+ end
137
+
138
+ it "should raise an error if not connected" do
139
+ Superfeedr.should_receive(:connection).and_return(nil)
140
+ lambda {
141
+ Superfeedr.subscriptions_by_page(@page, &@block)
142
+ }.should raise_error(Superfeedr::NotConnected)
143
+ end
144
+
145
+ it "should create a new SubscribeQueryStanza with the right url" do
146
+ SubscriptionsQueryStanza.should_receive(:new).with({:page => @page, :from => @mock_connection.jid}).and_return(@mock_stanza)
147
+ Superfeedr.subscriptions_by_page(@page, &@block)
148
+ end
149
+
150
+ it "should add a Proc that just calls the block in params to the @@callbacks" do
151
+ Superfeedr.subscriptions_by_page(@page, &@block)
152
+ Superfeedr.callbacks[@mock_stanza.id][:method].should == Superfeedr.method(:on_subscriptions)
153
+ Superfeedr.callbacks[@mock_stanza.id][:param].should == @block
154
+
155
+ end
156
+
157
+ it "should send the stanza" do
158
+ Superfeedr.should_receive(:send).with(@mock_stanza).and_return(true)
159
+ Superfeedr.subscriptions_by_page(@page, &@block)
160
+ end
161
+ end
162
+
163
+ describe "on_subscribe" do
164
+ it "should call the block with true if the stanza type is 'result'" do
165
+ xml = <<-EOXML
166
+ <iq type="result" to="you@superfeedr.com/home" from="firehoser.superfeedr.com" id="sub1">
167
+ <pubsub xmlns="http://jabber.org/protocol/pubsub">
168
+ <subscription jid="you@superfeedr.com" subscription="subscribed" node="http://domain.tld/path/to/feed.xml"/>
169
+ </pubsub>
170
+ </iq>
171
+ EOXML
172
+ stanza = Nokogiri::XML(xml)
173
+ Superfeedr.on_subscribe(stanza.root) do |res|
174
+ res.should be_true
175
+ end
176
+ end
177
+
178
+ it "should call the block with false if the stanza type is not 'result'" do
179
+ xml = <<-EOXML
180
+ <iq type="error" to="you@superfeedr.com/home" from="firehoser.superfeedr.com" id="sub1">
181
+ <pubsub xmlns="http://jabber.org/protocol/pubsub">
182
+ <subscription jid="you@superfeedr.com" subscription="subscribed" node="http://domain.tld/path/to/feed.xml"/>
183
+ </pubsub>
184
+ </iq>
185
+ EOXML
186
+ stanza = Nokogiri::XML(xml)
187
+ Superfeedr.on_subscribe(stanza.root) do |res|
188
+ res.should be_false
189
+ end
190
+ end
191
+
192
+ end
193
+
194
+ describe "on_unsubscribe" do
195
+ it "should call the block with true if the stanza type is 'result'" do
196
+ xml = <<-EOXML
197
+ <iq type='result' from='firehoser.superfeedr.com' to='you@superfeedr.com/home' id='unsub1' />
198
+ EOXML
199
+ stanza = Nokogiri::XML(xml)
200
+ Superfeedr.on_unsubscribe(stanza.root) do |res|
201
+ res.should be_true
202
+ end
203
+ end
204
+
205
+ it "should call the block with false if the stanza type is not 'result'" do
206
+ xml = <<-EOXML
207
+ <iq type='error' from='firehoser.superfeedr.com' to='you@superfeedr.com/home' id='unsub1' />
208
+ EOXML
209
+ stanza = Nokogiri::XML(xml)
210
+ Superfeedr.on_unsubscribe(stanza.root) do |res|
211
+ res.should be_false
212
+ end
213
+ end
214
+ end
215
+
216
+ describe "on_subscriptions" do
217
+ it "should call the block with the page number and the list of feeds as an array" do
218
+ xml = <<-EOXML
219
+ <iq type="result" to="you@superfeedr.com/home" id="subman1" from="firehoser.superfeedr.com">
220
+ <pubsub xmlns:superfeedr='http://superfeedr.com/xmpp-pubsub-ext' xmlns='http://jabber.org/protocol/pubsub'>
221
+ <subscriptions superfeedr:page="3">
222
+ <subscription node="http://domain.tld/path/to/a/feed/atom.xml&amp;toto=tutu" subscription="subscribed" jid="you@superfeedr.com" />
223
+ <subscription node="http://domain2.tld/path/to/feed.rss" subscription="subscribed" jid="you@superfeedr.com" />
224
+ </subscriptions>
225
+ </pubsub>
226
+ </iq>
227
+ EOXML
228
+ stanza = Nokogiri::XML(xml)
229
+ Superfeedr.on_subscriptions(stanza.root) do |page, subscriptions|
230
+ page.should == 3
231
+ subscriptions.should == ["http://domain.tld/path/to/a/feed/atom.xml&toto=tutu", "http://domain2.tld/path/to/feed.rss"]
232
+ end
233
+ end
234
+
235
+ end
236
+
237
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radamanthus-superfeedr-ruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 3
9
+ version: 0.4.3
10
+ platform: ruby
11
+ authors:
12
+ - julien Genestoux
13
+ - Radamanthus Batnag
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-03-30 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: radamanthus-skates
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: nokogiri
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ type: :runtime
46
+ version_requirements: *id002
47
+ description:
48
+ email: rad@batnag.org
49
+ executables: []
50
+
51
+ extensions: []
52
+
53
+ extra_rdoc_files:
54
+ - LICENSE
55
+ - README.rdoc
56
+ files:
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - VERSION.yml
61
+ - lib/config.yaml
62
+ - lib/stanzas/iq_query_stanza.rb
63
+ - lib/stanzas/notification_stanza.rb
64
+ - lib/stanzas/subscribe_query_stanza.rb
65
+ - lib/stanzas/subscriptions_query_stanza.rb
66
+ - lib/stanzas/unsubscribe_query_stanza.rb
67
+ - lib/superfeedr.rb
68
+ - spec/spec.opts
69
+ - spec/spec_helper.rb
70
+ - spec/stanzas/iq_query_stanza_spec.rb
71
+ - spec/stanzas/notifications_stanza_spec.rb
72
+ - spec/stanzas/subscribe_stanza_spec.rb
73
+ - spec/stanzas/subscriptions_stanza_spec.rb
74
+ - spec/stanzas/unsubscribe_stanza_spec.rb
75
+ - spec/superfeedr_ruby_spec.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/julien51/superfeedr-ruby/
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --charset=UTF-8
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ requirements: []
102
+
103
+ rubyforge_project: superfeedr-ruby
104
+ rubygems_version: 1.3.7
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Ruby Client for the Superfeedr
108
+ test_files:
109
+ - spec/spec_helper.rb
110
+ - spec/stanzas/iq_query_stanza_spec.rb
111
+ - spec/stanzas/notifications_stanza_spec.rb
112
+ - spec/stanzas/subscribe_stanza_spec.rb
113
+ - spec/stanzas/subscriptions_stanza_spec.rb
114
+ - spec/stanzas/unsubscribe_stanza_spec.rb
115
+ - spec/superfeedr_ruby_spec.rb