bradgessler-owidget 0.0.2 → 0.1.0
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.yml +2 -2
- data/lib/owidget.rb +1 -0
- data/lib/owidget/consumer.rb +12 -10
- data/lib/owidget/widget.rb +17 -0
- data/spec/owidget/consumer_spec.rb +34 -2
- data/spec/owidget/widget_spec.rb +28 -0
- metadata +4 -2
data/VERSION.yml
CHANGED
data/lib/owidget.rb
CHANGED
data/lib/owidget/consumer.rb
CHANGED
@@ -4,22 +4,24 @@ require 'open-uri'
|
|
4
4
|
|
5
5
|
module OWidget
|
6
6
|
class Consumer
|
7
|
-
|
8
|
-
|
7
|
+
attr_reader :content
|
8
|
+
|
9
|
+
def initialize(content='')
|
10
|
+
@content = content
|
9
11
|
end
|
10
12
|
|
11
|
-
def links
|
12
|
-
|
13
|
-
doc = Nokogiri::HTML(@content)
|
14
|
-
@links = (doc/'html head link[rel="owidget"]').map{ |link| link['href'] }
|
15
|
-
end
|
16
|
-
return @links
|
13
|
+
def links
|
14
|
+
(Nokogiri::HTML(@content)/'html head link[rel="owidget"]').map{ |link| link['href'] }
|
17
15
|
end
|
18
16
|
|
19
17
|
def widgets
|
20
|
-
links.map do |
|
21
|
-
|
18
|
+
links.map do |link|
|
19
|
+
Widget.get(link)
|
22
20
|
end
|
23
21
|
end
|
22
|
+
|
23
|
+
def self.discover(url)
|
24
|
+
new open(url).read
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
@@ -1,8 +1,30 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '../spec_helper')
|
2
2
|
|
3
|
+
describe OWidget::Consumer, 'discovery' do
|
4
|
+
it "should discover" do
|
5
|
+
OWidget::Consumer.should respond_to(:discover)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should instantiate OWidget::Consumer from discover" do
|
9
|
+
url = 'http://www.polleverywhere.com/multiple_choice_polls/MzkwNzM1MzEw'
|
10
|
+
|
11
|
+
OWidget::Consumer.should_receive(:open).with(url).and_return(io('polleverywhere.html'))
|
12
|
+
consumer = OWidget::Consumer.discover(url)
|
13
|
+
consumer.should be_instance_of(OWidget::Consumer)
|
14
|
+
consumer.content.should eql(content('polleverywhere.html'))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
3
18
|
describe OWidget::Consumer do
|
4
19
|
before(:each) do
|
5
20
|
@consumer = OWidget::Consumer.new(content('polleverywhere.html'))
|
21
|
+
@links = {
|
22
|
+
'http://www.polleverywhere.com/multiple_choice_polls/MzkwNzM1MzEw.owidget' => io('polleverywhere.owidget')
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should initialize with content" do
|
27
|
+
@consumer.content.should eql(content('polleverywhere.html'))
|
6
28
|
end
|
7
29
|
|
8
30
|
it "should have links" do
|
@@ -13,12 +35,22 @@ describe OWidget::Consumer do
|
|
13
35
|
@consumer.should have(1).links
|
14
36
|
end
|
15
37
|
|
38
|
+
it "should parse the correct link" do
|
39
|
+
@consumer.links.should include('http://www.polleverywhere.com/multiple_choice_polls/MzkwNzM1MzEw.owidget')
|
40
|
+
end
|
41
|
+
|
16
42
|
it "should have widgets" do
|
17
43
|
@consumer.should respond_to(:widgets)
|
18
44
|
end
|
19
45
|
|
20
|
-
it "should
|
21
|
-
@consumer.
|
46
|
+
it "should have content" do
|
47
|
+
@consumer.should respond_to(:content)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should get widgets" do
|
51
|
+
@consumer.links.each do |link|
|
52
|
+
OWidget::Widget.should_receive(:open).with(link).and_return(@links[link])
|
53
|
+
end
|
22
54
|
@consumer.widgets
|
23
55
|
end
|
24
56
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../spec_helper')
|
2
|
+
|
3
|
+
describe OWidget::Widget, 'get' do
|
4
|
+
it "should get widget" do
|
5
|
+
url = 'http://www.polleverywhere.com/multiple_choice_polls/MzkwNzM1MzEw.owidget'
|
6
|
+
OWidget::Widget.should_receive(:open).with(url).and_return(io('polleverywhere.owidget'))
|
7
|
+
widget = OWidget::Widget.get(url)
|
8
|
+
widget.content.should eql(content('polleverywhere.owidget'))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe OWidget::Widget do
|
13
|
+
before(:each) do
|
14
|
+
@widget = OWidget::Widget.new(content('polleverywhere.owidget'))
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have content" do
|
18
|
+
@widget.should respond_to(:content)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should initialize content" do
|
22
|
+
@widget.content.should eql(content('polleverywhere.owidget'))
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should to_s content" do
|
26
|
+
@widget.to_s.should eql(content('polleverywhere.owidget'))
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bradgessler-owidget
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Gessler
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-23 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -35,12 +35,14 @@ files:
|
|
35
35
|
- lib/owidget
|
36
36
|
- lib/owidget/consumer
|
37
37
|
- lib/owidget/consumer.rb
|
38
|
+
- lib/owidget/widget.rb
|
38
39
|
- lib/owidget.rb
|
39
40
|
- spec/fixtures
|
40
41
|
- spec/fixtures/polleverywhere.html
|
41
42
|
- spec/fixtures/polleverywhere.owidget
|
42
43
|
- spec/owidget
|
43
44
|
- spec/owidget/consumer_spec.rb
|
45
|
+
- spec/owidget/widget_spec.rb
|
44
46
|
- spec/spec_helper.rb
|
45
47
|
has_rdoc: true
|
46
48
|
homepage: http://www.owidget.org
|