feed-processor 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
- urls.txt
1
+ urls.txt
2
+ pkg
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{feed-processor}
8
- s.version = "0.0.1"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Anthony Eden"]
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "lib/feed_processor/feed.rb",
30
30
  "lib/feed_processor/fetcher.rb",
31
31
  "lib/feed_processor/file_based_request_generator.rb",
32
+ "lib/feed_processor/mongo_feed_handler.rb",
32
33
  "lib/feed_processor/parser.rb",
33
34
  "lib/feed_processor/response.rb",
34
35
  "lib/feed_processor/util.rb"
@@ -0,0 +1,24 @@
1
+ module FeedProcessor
2
+ class MongoFeedHandler
3
+ def process(url, feed)
4
+ f = Feed.create({:url => url, :status => 'to-process'})
5
+ entries = feed.entries
6
+ puts "found #{entries.length} entries in #{url}"
7
+ entries.each do |entry|
8
+ begin
9
+ f.contents.create({
10
+ :title => entry.title,
11
+ :url => entry.url,
12
+ :author => entry.author,
13
+ :summary => entry.summary,
14
+ :content => entry.content,
15
+ :published => entry.published,
16
+ :categories => entry.categories,
17
+ })
18
+ rescue => e
19
+ puts "error creating entry #{entry.url}: #{e.message}"
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -4,8 +4,11 @@ require 'feedzirra'
4
4
 
5
5
  module FeedProcessor
6
6
  class Parser
7
+ attr_reader :options
8
+
7
9
  def initialize(options={})
8
10
  @options = options
11
+ @feed_handler = options[:feed_handler] || FeedProcessor::MongoFeedHandler.new
9
12
  setup_mongo(options[:mongo])
10
13
  end
11
14
  def execute
@@ -25,24 +28,7 @@ module FeedProcessor
25
28
  responses.each do |response|
26
29
  begin
27
30
  feed = Feedzirra::Feed.parse(response.data)
28
- f = Feed.create({:url => url, :status => 'to-process'})
29
- entries = feed.entries
30
- puts "found #{entries.length} entries in #{url}"
31
- entries.each do |entry|
32
- begin
33
- f.contents.create({
34
- :title => entry.title,
35
- :url => entry.url,
36
- :author => entry.author,
37
- :summary => entry.summary,
38
- :content => entry.content,
39
- :published => entry.published,
40
- :categories => entry.categories,
41
- })
42
- rescue => e
43
- puts "error creating entry #{entry.url}: #{e.message}"
44
- end
45
- end
31
+ @feed_handler.process(url, feed)
46
32
  rescue => e
47
33
  puts "error parsing feed #{url}: #{e.message}"
48
34
  end
@@ -1,5 +1,6 @@
1
1
  require 'feed_processor/util'
2
2
  require 'feed_processor/file_based_request_generator'
3
+ require 'feed_processor/mongo_feed_handler'
3
4
  require 'feed_processor/response'
4
5
  require 'feed_processor/feed'
5
6
  require 'feed_processor/content'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feed-processor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Eden
@@ -35,6 +35,7 @@ files:
35
35
  - lib/feed_processor/feed.rb
36
36
  - lib/feed_processor/fetcher.rb
37
37
  - lib/feed_processor/file_based_request_generator.rb
38
+ - lib/feed_processor/mongo_feed_handler.rb
38
39
  - lib/feed_processor/parser.rb
39
40
  - lib/feed_processor/response.rb
40
41
  - lib/feed_processor/util.rb