livedoor-feeddiscover 1.0.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.
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), '../../../spec_helper.rb')
2
+
3
+ describe Livedoor::API::FeedDiscover::Client do |*arg|
4
+ before do
5
+ @client = Livedoor::API::FeedDiscover::Client.new
6
+ end
7
+
8
+ it "#find should find feed from specified URL" do
9
+ feedlist = @client.find("http://rubyforge.org/")
10
+ feedlist.should be_an_instance_of(Livedoor::API::FeedDiscover::FeedList)
11
+ feedlist.should be_a_kind_of(Enumerable)
12
+ feedlist.should respond_to(:each)
13
+
14
+ feedlist.feeds?.should be_true
15
+ feedlist.size.should eql(1)
16
+
17
+ feedlist.feed.title.should eql("RubyForge Project News")
18
+ feedlist.feed.description.should eql("RubyForge Project News Highlights")
19
+ feedlist.feed.icon.should eql("http://image.reader.livedoor.com/favicon/3/e/3e0012d69b380e9c2437ea4051abbc34b16c2624.png")
20
+ feedlist.feed.link.should eql("http://rubyforge.org")
21
+ feedlist.feed.feedlink.should eql("http://rubyforge.org/export/rss_sfnews.php")
22
+ feedlist.feed.modified_on.should be_an_instance_of(Time)
23
+ feedlist.feed.image.should be_nil
24
+ feedlist.feed.subscribers_count.should be_an_instance_of(Fixnum)
25
+ feedlist.feed.avg_rate.should be_an_instance_of(Float)
26
+ feedlist.feed.official?.should be_true
27
+ feedlist.feed.thirdparty?.should be_false
28
+ end
29
+
30
+ it "#find_from should find all feeds linked from specified URL" do
31
+ feedlist = @client.find_from("http://rubyforge.org/")
32
+ feedlist.size.should eql(2)
33
+ feedlist.feedlinks.should include("http://rubyforge.org/export/rss_sfnews.php")
34
+ feedlist.feedlinks.should include("http://raa.ruby-lang.org/index.rdf")
35
+ end
36
+
37
+ end
@@ -0,0 +1,114 @@
1
+ require File.join(File.dirname(__FILE__), '../../../spec_helper.rb')
2
+
3
+ describe Livedoor::API::FeedDiscover::FeedList do |*arg|
4
+ before do
5
+ @feed_list = Livedoor::API::FeedDiscover::FeedList.new({
6
+ :json => lambda {
7
+ [{
8
+ "title"=>"RubyForge Project News",
9
+ "icon"=> "http://image.reader.livedoor.com/favicon/3/e/3e0012d69b380e9c2437ea4051abbc34b16c2624.png",
10
+ "modified_on"=>1181723997,
11
+ "description"=>"RubyForge Project News Highlights",
12
+ "feedlink"=>"http://rubyforge.org/export/rss_sfnews.php",
13
+ "link"=>"http://rubyforge.org",
14
+ "image"=>nil,
15
+ "subscribers_count"=>57,
16
+ },
17
+ {
18
+ "title"=>"RAA",
19
+ "icon"=> "http://image.reader.livedoor.com/favicon/1/f/1fea2bd9cd6baf85be86e7db365b4584e1cdc414.png",
20
+ "modified_on"=>1181688574,
21
+ "description"=>"Ruby Application Archive",
22
+ "feedlink"=>"http://raa.ruby-lang.org/index.rdf",
23
+ "link"=>"http://raa.ruby-lang.org/",
24
+ "image"=>nil,
25
+ "subscribers_count"=>55
26
+ }]
27
+ }
28
+ })
29
+ end
30
+
31
+ it "#size should return # of json array length" do
32
+ @feed_list.size.should eql(2)
33
+ @feed_list.length.should eql(2)
34
+ end
35
+
36
+ it "#feed should return 1st Feed" do
37
+ @feed_list.feed.should be_an_instance_of(Livedoor::API::FeedDiscover::Feed)
38
+ @feed_list.feed.should eql(@feed_list.feeds.first)
39
+ end
40
+
41
+ it "#feeds should return Array of Feed" do
42
+ @feed_list.feeds.should be_an_instance_of(Array)
43
+ @feed_list.feeds.first.should be_an_instance_of(Livedoor::API::FeedDiscover::Feed)
44
+ @feed_list.feeds.length.should eql(@feed_list.size)
45
+ end
46
+
47
+ it "#feeds should return empty Array if target has no feed." do
48
+ feed_list = Livedoor::API::FeedDiscover::FeedList.new({
49
+ :json => lambda {}
50
+ })
51
+
52
+ feed_list.feeds.should eql([])
53
+ end
54
+
55
+ it "#feeds? should return true/false" do
56
+ @feed_list.feeds?.should be_true
57
+
58
+ feed_list = Livedoor::API::FeedDiscover::FeedList.new({
59
+ :json => lambda {}
60
+ })
61
+ feed_list.feeds?.should be_false
62
+
63
+ feed_list = Livedoor::API::FeedDiscover::FeedList.new({
64
+ :json => lambda { [] }
65
+ })
66
+ feed_list.feeds?.should be_false
67
+ end
68
+
69
+ it "included Enumerable" do
70
+ @feed_list.should respond_to(:each)
71
+ @feed_list.should be_a_kind_of(Enumerable)
72
+ end
73
+
74
+ it "#each are supported" do
75
+ i = 0
76
+ @feed_list.each do |feed|
77
+ feed.should be_an_instance_of(Livedoor::API::FeedDiscover::Feed)
78
+ i += 1
79
+ end
80
+ @feed_list.size.should eql(i)
81
+ end
82
+
83
+ it "#each_feedlink should yield feedlink(String)" do
84
+ r = []
85
+ @feed_list.each_feedlink do |link|
86
+ link.should be_an_instance_of(String)
87
+ r << link
88
+ end
89
+ r[0].should eql("http://rubyforge.org/export/rss_sfnews.php")
90
+ r[1].should eql("http://raa.ruby-lang.org/index.rdf")
91
+ end
92
+
93
+ it "#feed should call fetcher[:json] proc in initialize" do
94
+ called = false
95
+ feed_list = Livedoor::API::FeedDiscover::FeedList.new({
96
+ :json => lambda { called = true; [] }
97
+ })
98
+ called.should be_true
99
+ feed_list.feeds.should eql([])
100
+ called.should be_true
101
+ end
102
+
103
+ it "#opml should call fetcher[:opml] proc lazily" do
104
+ called = false
105
+ feed_list = Livedoor::API::FeedDiscover::FeedList.new({
106
+ :json => lambda {},
107
+ :opml => lambda { called = true; "<opml>...</opml>" }
108
+ })
109
+ called.should be_false
110
+ feed_list.opml.should eql("<opml>...</opml>")
111
+ called.should be_true
112
+ end
113
+
114
+ end
@@ -0,0 +1,114 @@
1
+ require File.join(File.dirname(__FILE__), '../../../spec_helper.rb')
2
+
3
+ describe Livedoor::API::FeedDiscover::Feed do |*arg|
4
+ before do
5
+ @feed = Livedoor::API::FeedDiscover::Feed.new({
6
+ "source" => "http://news.livedoor.com/",
7
+ "icon" => "http://reader.livedoor.com/img/icon/default.gif",
8
+ "link" => "http://news.livedoor.com",
9
+ "description" => "livedoor NEWS",
10
+ "image" => nil,
11
+ "modified_on" => 1178770500,
12
+ "title" => "livedoor NEWS",
13
+ "feedlink" => "http://news.livedoor.com/topics/rss.xml",
14
+ "subscribers_count" => 10,
15
+ "avg_rate" => 2.3,
16
+ "official" => 1
17
+ })
18
+ end
19
+
20
+ it "should return json member" do
21
+ @feed.source.should eql("http://news.livedoor.com/")
22
+ @feed.icon.should eql("http://reader.livedoor.com/img/icon/default.gif")
23
+ @feed.link.should eql("http://news.livedoor.com")
24
+ @feed.description.should eql("livedoor NEWS")
25
+ @feed.image.should be_nil
26
+ @feed.title.should eql("livedoor NEWS")
27
+ @feed.feedlink.should eql("http://news.livedoor.com/topics/rss.xml")
28
+ @feed.subscribers_count.should eql(10)
29
+ @feed.avg_rate.should eql(2.3)
30
+ @feed.official?.should be_true
31
+ end
32
+
33
+ it "should duplicate argument" do
34
+ json = {
35
+ "source" => "http://news.livedoor.com/",
36
+ }
37
+ feed = Livedoor::API::FeedDiscover::Feed.new(json)
38
+
39
+ feed.source.should eql("http://news.livedoor.com/")
40
+ json.clear
41
+ feed.source.should eql("http://news.livedoor.com/")
42
+ end
43
+
44
+ it "should return Time object when sent #modified_on" do
45
+ feed = Livedoor::API::FeedDiscover::Feed.new({
46
+ "modified_on" => 1178770500,
47
+ })
48
+ feed.modified_on.should be_an_instance_of(Time)
49
+ end
50
+
51
+ it "should return nil if modified_on is invalid" do
52
+ feed = Livedoor::API::FeedDiscover::Feed.new({})
53
+ feed.modified_on.should be_nil
54
+
55
+ feed = Livedoor::API::FeedDiscover::Feed.new({"modified_on" => "foo"})
56
+ feed.modified_on.should be_nil
57
+
58
+ feed = Livedoor::API::FeedDiscover::Feed.new({"modified_on" => "1.1"})
59
+ feed.modified_on.should be_nil
60
+ end
61
+
62
+ it "#official? should return true only if official == 1 " do
63
+ feed = Livedoor::API::FeedDiscover::Feed.new({})
64
+ feed.official?.should be_false
65
+
66
+ feed = Livedoor::API::FeedDiscover::Feed.new({"official" => 0})
67
+ feed.official?.should be_false
68
+
69
+ feed = Livedoor::API::FeedDiscover::Feed.new({"official" => 1})
70
+ feed.official?.should be_true
71
+
72
+ feed = Livedoor::API::FeedDiscover::Feed.new({"official" => 2})
73
+ feed.official?.should be_false
74
+
75
+ feed = Livedoor::API::FeedDiscover::Feed.new({"official" => "1"})
76
+ feed.official?.should be_false
77
+
78
+ feed = Livedoor::API::FeedDiscover::Feed.new({"official" => "hoge"})
79
+ feed.official?.should be_false
80
+ end
81
+
82
+ it "#thirdparty? should return false if #official?" do
83
+ feed = Livedoor::API::FeedDiscover::Feed.new({
84
+ "link" => "http://foo.bar.baz/",
85
+ "feedlink" => "http://foobar.feed.com/foobar.rss",
86
+ "official" => 1,
87
+ })
88
+ feed.thirdparty?.should be_false
89
+
90
+ feed = Livedoor::API::FeedDiscover::Feed.new({
91
+ "link" => "http://foo.bar.baz/",
92
+ "feedlink" => "http://foo.bar.baz/index.rss",
93
+ "official" => 1,
94
+ })
95
+ feed.thirdparty?.should be_false
96
+ end
97
+
98
+ it "#thirdparty? should return true if not official? and mismatch domain" do
99
+ feed = Livedoor::API::FeedDiscover::Feed.new({
100
+ "link" => "http://foo.bar.baz/",
101
+ "feedlink" => "http://foo.bar.baz/index.rss",
102
+ "official" => 0,
103
+ })
104
+ feed.thirdparty?.should be_false
105
+
106
+ feed = Livedoor::API::FeedDiscover::Feed.new({
107
+ "link" => "http://foo.bar.baz/",
108
+ "feedlink" => "http://foobar.feed.com/foobar.rss",
109
+ "official" => 0,
110
+ })
111
+ feed.thirdparty?.should be_true
112
+ end
113
+
114
+ end
@@ -0,0 +1,21 @@
1
+ require File.join(File.dirname(__FILE__), '../../../spec_helper.rb')
2
+
3
+ describe Livedoor::API::FeedDiscover::VERSION do |*arg|
4
+ before do
5
+ @v = Livedoor::API::FeedDiscover::VERSION
6
+ end
7
+
8
+ it "should have STRING constant" do
9
+ @v::STRING.should be_an_instance_of(String)
10
+ end
11
+
12
+ it "should have MAJOR, MINOR, TINY constant" do
13
+ @v::MAJOR.should be_an_instance_of(Fixnum)
14
+ @v::MINOR.should be_an_instance_of(Fixnum)
15
+ @v::TINY.should be_an_instance_of(Fixnum)
16
+ end
17
+
18
+ it "should eql STRING and MAJOR.MINOR.TINY" do
19
+ @v::STRING.should == [@v::MAJOR, @v::MINOR, @v::TINY].join(".")
20
+ end
21
+ end
data/spec/spec.opts ADDED
File without changes
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "../lib")
5
+ require "livedoor/api/feed_discover"
6
+
7
+
8
+ require "open-uri"
9
+ require "tempfile"
10
+ require "digest"
11
+
12
+ # local cache for test.
13
+ class URI::HTTP
14
+ def open(*rest, &block)
15
+ cachedir = File.join(File.dirname(__FILE__), ".cache")
16
+ cache = File.join(cachedir, Digest::MD5.hexdigest(self.to_s))
17
+ Dir.mkdir(cachedir) unless File.exist?(cachedir)
18
+ unless File.exist?(cache)
19
+ puts "fetch #{self}"
20
+ File.open(cache, "wb") do |w|
21
+ OpenURI.open_uri(self, *rest) do |r|
22
+ w.write r.read
23
+ end
24
+ end
25
+ end
26
+ File.open(cache, "rb", &block)
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: livedoor-feeddiscover
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2007-06-17 00:00:00 +09:00
8
+ summary: livedoor-feeddiscover performs feed autodiscovery using the livedoor Feed Discover API.
9
+ require_paths:
10
+ - lib
11
+ email: miyamuko@gmail.com
12
+ homepage: http://feeddiscoverapi.rubyforge.org
13
+ rubyforge_project: feeddiscoverapi
14
+ description: livedoor-feeddiscover performs feed autodiscovery using the livedoor Feed Discover API. livedoor Feed Discover API find a Atom/RSS feed(s) from the livedoor Reader crawler database. So, livedoor-feeddiscover do not access the target URL.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - MIYAMUKO Katsuyuki
31
+ files:
32
+ - History.txt
33
+ - License.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ - Rakefile
37
+ - examples/benchmark.rb
38
+ - examples/mkopml.rb
39
+ - helper/helper.rb
40
+ - helper/rake.rb
41
+ - helper/rake_sh_filter.rb
42
+ - helper/util.rb
43
+ - lib/livedoor/api/feed_discover.rb
44
+ - lib/livedoor/api/feed_discover/client.rb
45
+ - lib/livedoor/api/feed_discover/feed.rb
46
+ - lib/livedoor/api/feed_discover/feed_list.rb
47
+ - lib/livedoor/api/feed_discover/version.rb
48
+ - setup.rb
49
+ - spec/livedoor/api/feed_discover/client_spec.rb
50
+ - spec/livedoor/api/feed_discover/feed_list_spec.rb
51
+ - spec/livedoor/api/feed_discover/feed_spec.rb
52
+ - spec/livedoor/api/feed_discover/version_spec.rb
53
+ - spec/spec.opts
54
+ - spec/spec_helper.rb
55
+ test_files:
56
+ - spec/livedoor/api/feed_discover/client_spec.rb
57
+ - spec/livedoor/api/feed_discover/feed_list_spec.rb
58
+ - spec/livedoor/api/feed_discover/feed_spec.rb
59
+ - spec/livedoor/api/feed_discover/version_spec.rb
60
+ rdoc_options:
61
+ - --main
62
+ - README.txt
63
+ extra_rdoc_files:
64
+ - History.txt
65
+ - License.txt
66
+ - Manifest.txt
67
+ - README.txt
68
+ executables: []
69
+
70
+ extensions: []
71
+
72
+ requirements: []
73
+
74
+ dependencies:
75
+ - !ruby/object:Gem::Dependency
76
+ name: json
77
+ version_requirement:
78
+ version_requirements: !ruby/object:Gem::Version::Requirement
79
+ requirements:
80
+ - - ">"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.0
83
+ version: