public
Description: A fast, libxml based, Ruby Atom library supporting the Syndication Format and the Publishing Protocol. <br> Gem is available now!!<br>
Homepage: http://ratom.rubyforge.org/
Clone URL: git://github.com/seangeo/ratom.git
Some fixed to http stuff
seangeo (author)
Wed Jun 25 21:16:00 -0700 2008
commit  9bd5bbe74f18aca1703add20c89bf0addc5219e7
tree    6e61a69cf99db94cb2dd0efca710fc8da74ef1d7
parent  ba86d5dddc9c3756a8ab4a65dddc6b768fbf589a
...
421
422
423
 
 
424
425
426
...
439
440
441
442
 
443
444
445
...
692
693
694
695
696
697
 
698
699
 
700
701
 
702
703
704
...
421
422
423
424
425
426
427
428
...
441
442
443
 
444
445
446
447
...
694
695
696
 
 
 
697
698
 
699
700
 
701
702
703
704
0
@@ -421,6 +421,8 @@ module Atom # :nodoc:
0
     #
0
     # +paginate+:: If true and the feed supports pagination this will fetch each page of the feed.
0
     # +since+:: If a Time object is provided each_entry will iterate over all entries that were updated since that time.
0
+ # +user+:: User name for HTTP Basic Authentication.
0
+ # +pass+:: Password for HTTP Basic Authentication.
0
     #
0
     def each_entry(options = {}, &block)
0
       if options[:paginate]
0
@@ -439,7 +441,7 @@ module Atom # :nodoc:
0
           if since_reached || feed.next_page.nil?
0
             break
0
           else feed.next_page
0
- feed = feed.next_page.fetch
0
+ feed = feed.next_page.fetch(options)
0
           end
0
         end
0
       else
0
@@ -692,13 +694,11 @@ module Atom # :nodoc:
0
     #
0
     # TODO: Handle redirects.
0
     #
0
- def fetch
0
- content = Net::HTTP.get_response(URI.parse(self.href)).body
0
-
0
+ def fetch(options = {})
0
       begin
0
- Atom::Feed.load_feed(content)
0
+ Atom::Feed.load_feed(URI.parse(self.href), options)
0
       rescue ArgumentError, ParseError => ae
0
- content
0
+ Net::HTTP.get_response(URI.parse(self.href)).body
0
       end
0
     end
0
     
...
251
252
253
254
 
255
256
257
...
251
252
253
 
254
255
256
257
0
@@ -251,7 +251,7 @@ module Atom
0
                   raise ArgumentError, "#{class_name}.load only handles http URIs" if o.scheme != 'http'
0
                   response = nil
0
                   Net::HTTP.start(o.host, o.port) do |http|
0
- request = Net::HTTP::Get.new(o.path)
0
+ request = Net::HTTP::Get.new(o.request_uri)
0
                     if opts[:user] && opts[:pass]
0
                       request.basic_auth(opts[:user], opts[:pass])
0
                     end
...
110
111
112
 
 
 
 
 
 
 
 
 
113
114
115
...
929
930
931
932
 
933
934
935
936
937
938
939
940
941
942
943
944
945
 
 
 
 
 
 
 
 
 
 
946
947
948
...
963
964
965
966
967
 
968
969
970
...
1042
1043
1044
1045
1046
1047
1048
 
 
1049
1050
1051
 
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
...
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
...
938
939
940
 
941
942
943
944
945
946
 
 
 
 
 
 
 
 
947
948
949
950
951
952
953
954
955
956
957
958
959
...
974
975
976
 
 
977
978
979
980
...
1052
1053
1054
 
 
 
 
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
 
 
 
 
 
 
 
 
 
 
 
 
 
1066
1067
1068
0
@@ -110,6 +110,15 @@ describe Atom do
0
       Atom::Feed.load_feed(uri).should be_an_instance_of(Atom::Feed)
0
     end
0
     
0
+ it "should accept a URI with query parameters" do
0
+ uri = URI.parse('http://example.com/feed.atom?page=2')
0
+ response = Net::HTTPSuccess.new(nil, nil, nil)
0
+ response.stub!(:body).and_return(File.read('spec/fixtures/simple_single_entry.atom'))
0
+ mock_http_get(uri, response)
0
+
0
+ Atom::Feed.load_feed(uri).should be_an_instance_of(Atom::Feed)
0
+ end
0
+
0
     it "should raise ArgumentError with non-http uri" do
0
       uri = URI.parse('file:/tmp')
0
       lambda { Atom::Feed.load_feed(uri) }.should raise_error(ArgumentError)
0
@@ -929,20 +938,22 @@ describe Atom do
0
       end
0
     end
0
     
0
- describe 'pagination using each_entries' do
0
+ describe 'pagination using each_entry' do
0
       before(:each) do
0
         @feed = Atom::Feed.load_feed(File.open('spec/paging/first_paged_feed.atom'))
0
       end
0
       
0
       it "should paginate through each entry" do
0
- response1 = Net::HTTPSuccess.new(nil, nil, nil)
0
- response1.stub!(:body).and_return(File.read('spec/paging/middle_paged_feed.atom'))
0
- Net::HTTP.should_receive(:get_response).with(URI.parse('http://example.org/index.atom?page=2')).and_return(response1)
0
-
0
- response2 = Net::HTTPSuccess.new(nil, nil, nil)
0
- response2.stub!(:body).and_return(File.read('spec/paging/last_paged_feed.atom'))
0
- Net::HTTP.should_receive(:get_response).with(URI.parse('http://example.org/index.atom?page=4')).and_return(response2)
0
-
0
+ feed1 = Atom::Feed.load_feed(File.read('spec/paging/middle_paged_feed.atom'))
0
+ feed2 = Atom::Feed.load_feed(File.read('spec/paging/last_paged_feed.atom'))
0
+
0
+ Atom::Feed.should_receive(:load_feed).
0
+ with(URI.parse('http://example.org/index.atom?page=2'), an_instance_of(Hash)).
0
+ and_return(feed1)
0
+ Atom::Feed.should_receive(:load_feed).
0
+ with(URI.parse('http://example.org/index.atom?page=4'), an_instance_of(Hash)).
0
+ and_return(feed2)
0
+
0
         entry_count = 0
0
         @feed.each_entry(:paginate => true) do |entry|
0
           entry_count += 1
0
@@ -963,8 +974,7 @@ describe Atom do
0
       it "should only paginate up to since" do
0
         response1 = Net::HTTPSuccess.new(nil, nil, nil)
0
         response1.stub!(:body).and_return(File.read('spec/paging/middle_paged_feed.atom'))
0
- Net::HTTP.should_receive(:get_response).with(URI.parse('http://example.org/index.atom?page=2')).and_return(response1)
0
- Net::HTTP.should_receive(:get_response).with(URI.parse('http://example.org/index.atom?page=4')).never
0
+ mock_http_get(URI.parse('http://example.org/index.atom?page=2'), response1)
0
         
0
         entry_count = 0
0
         @feed.each_entry(:paginate => true, :since => Time.parse('2003-11-19T18:30:02Z')) do |entry|
0
@@ -1042,31 +1052,17 @@ describe Atom do
0
     end
0
     
0
     it "should fetch feed for fetch_next" do
0
- response = Net::HTTPSuccess.new(nil, nil, nil)
0
- response.stub!(:body).and_return(File.read('spec/paging/middle_paged_feed.atom'))
0
- Net::HTTP.should_receive(:get_response).with(URI.parse(@href)).and_return(response)
0
- @link.fetch.should be_an_instance_of(Atom::Feed)
0
+ Atom::Feed.should_receive(:load_feed).with(URI.parse(@href), an_instance_of(Hash))
0
+ @link.fetch
0
     end
0
     
0
     it "should fetch content when response is not xml" do
0
+ Atom::Feed.should_receive(:load_feed).and_raise(Atom::LoadError)
0
       response = Net::HTTPSuccess.new(nil, nil, nil)
0
       response.stub!(:body).and_return('some text.')
0
       Net::HTTP.should_receive(:get_response).with(URI.parse(@href)).and_return(response)
0
       @link.fetch.should == 'some text.'
0
     end
0
-
0
- it "should fetch content when response is not atom" do
0
- content = <<-END
0
- <?xml version="1.0" ?>
0
- <foo>
0
- <bar>text</bar>
0
- </foo>
0
- END
0
- response = Net::HTTPSuccess.new(nil, nil, nil)
0
- response.stub!(:body).and_return(content)
0
- Net::HTTP.should_receive(:get_response).with(URI.parse(@href)).and_return(response)
0
- @link.fetch.should == content
0
- end
0
   end
0
   
0
   describe Atom::Entry do
...
24
25
26
27
 
28
29
30
...
24
25
26
 
27
28
29
30
0
@@ -24,7 +24,7 @@ Spec::Runner.configure do |config|
0
   
0
   def mock_http_get(url, response, user = nil, pass = nil)
0
     req = mock('request')
0
- Net::HTTP::Get.should_receive(:new).with(url.path).and_return(req)
0
+ Net::HTTP::Get.should_receive(:new).with(url.request_uri).and_return(req)
0
     
0
     if user && pass
0
       req.should_receive(:basic_auth).with(user, pass)

Comments

    No one has commented yet.