Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: feedjira/feedjira
base: master
...
head fork: john-griffin/feedzirra
compare: update_working
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 02, 2012
@john-griffin john-griffin replace Curl::Multi with UrlBatch helper class which just collects fe…
…eds and calls #perform on them individually (Curl::Easy) as I need mocking support in VCR more than I need parallel feed fetching
0a15790
Showing with 30 additions and 5 deletions.
  1. +20 −4 lib/feedzirra/feed.rb
  2. +10 −1 spec/feedzirra/feed_spec.rb
View
24 lib/feedzirra/feed.rb
@@ -1,5 +1,21 @@
module Feedzirra
class NoParserAvailable < StandardError; end
+
+ class UrlBatch
+ def initialize
+ @urls = []
+ end
+
+ def add(url)
+ @urls << url
+ end
+
+ def perform
+ @urls.each do |url|
+ url.perform
+ end
+ end
+ end
class Feed
USER_AGENT = "feedzirra http://github.com/pauldix/feedzirra/tree/master"
@@ -150,7 +166,7 @@ def self.setup_easy curl, options
# A Hash if multiple URL's are passed. The key will be the URL, and the value the XML.
def self.fetch_raw(urls, options = {})
url_queue = [*urls]
- multi = Curl::Multi.new
+ multi = UrlBatch.new
responses = {}
url_queue.each do |url|
easy = Curl::Easy.new(url) do |curl|
@@ -189,7 +205,7 @@ def self.fetch_raw(urls, options = {})
# A Hash if multiple URL's are passed. The key will be the URL, and the value the Feed object.
def self.fetch_and_parse(urls, options = {})
url_queue = [*urls]
- multi = Curl::Multi.new
+ multi = UrlBatch.new
responses = {}
# I broke these down so I would only try to do 30 simultaneously because
@@ -241,7 +257,7 @@ def self.decode_content(c)
# A Hash if multiple Feeds are passed. The key will be the URL, and the value the updated Feed object.
def self.update(feeds, options = {})
feed_queue = [*feeds]
- multi = Curl::Multi.new
+ multi = UrlBatch.new
responses = {}
feed_queue.slice!(0, 30).each do |feed|
@@ -381,4 +397,4 @@ def self.last_modified_from_header(header)
Time.parse($1) if $1
end
end
-end
+end
View
11 spec/feedzirra/feed_spec.rb
@@ -190,40 +190,48 @@ def self.able_to_parse?(val)
end
it "should set user agent if it's passed as an option" do
+ @curl_easy.should_receive(:perform)
Feedzirra::Feed.fetch_raw(@paul_feed[:url], :user_agent => 'Custom Useragent')
@curl.headers['User-Agent'].should == 'Custom Useragent'
end
it "should set user agent to default if it's not passed as an option" do
+ @curl_easy.should_receive(:perform)
Feedzirra::Feed.fetch_raw(@paul_feed[:url])
@curl.headers['User-Agent'].should == Feedzirra::Feed::USER_AGENT
end
it "should set if modified since as an option if passed" do
+ @curl_easy.should_receive(:perform)
Feedzirra::Feed.fetch_raw(@paul_feed[:url], :if_modified_since => Time.parse("Wed, 28 Jan 2009 04:10:32 GMT"))
@curl.headers["If-Modified-Since"].should == 'Wed, 28 Jan 2009 04:10:32 GMT'
end
it "should set if none match as an option if passed" do
+ @curl_easy.should_receive(:perform)
Feedzirra::Feed.fetch_raw(@paul_feed[:url], :if_none_match => 'ziEyTl4q9GH04BR4jgkImd0GvSE')
@curl.headers["If-None-Match"].should == 'ziEyTl4q9GH04BR4jgkImd0GvSE'
end
it 'should set userpwd for http basic authentication if :http_authentication is passed' do
+ @curl_easy.should_receive(:perform)
@curl.should_receive(:userpwd=).with('username:password')
Feedzirra::Feed.fetch_raw(@paul_feed[:url], :http_authentication => ['username', 'password'])
end
it 'should set accepted encodings' do
+ @curl_easy.should_receive(:perform)
Feedzirra::Feed.fetch_raw(@paul_feed[:url], :compress => true)
@curl.headers["Accept-encoding"].should == 'gzip, deflate'
end
it "should return raw xml" do
+ @curl_easy.should_receive(:perform)
Feedzirra::Feed.fetch_raw(@paul_feed[:url]).should =~ /^#{Regexp.escape('<?xml version="1.0" encoding="UTF-8"?>')}/
end
it "should take multiple feed urls and return a hash of urls and response xml" do
+ @curl_easy.should_receive(:perform).twice
multi = stub('curl_multi', :add => true, :perform => true)
Curl::Multi.stub!(:new).and_return(multi)
@@ -247,6 +255,7 @@ def self.able_to_parse?(val)
end
it "should always return a hash when passed an array" do
+ @curl_easy.should_receive(:perform)
results = Feedzirra::Feed.fetch_raw([@paul_feed[:url]])
results.class.should == Hash
end
@@ -590,4 +599,4 @@ def self.able_to_parse?(val)
it "should return an return an array of feed objects if multiple feeds are passed in"
end
end
-end
+end

No commit comments for this range

Something went wrong with that request. Please try again.