buzz_feed 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/MIT-LICENSE +20 -0
- data/README.rdoc +58 -0
- data/Rakefile +23 -0
- data/lib/buzz_feed/client.rb +50 -0
- data/lib/buzz_feed/version.rb +9 -0
- data/lib/buzz_feed.rb +14 -0
- data/lib/generators/buzz_feed_generator.rb +33 -0
- data/lib/generators/templates/buzz_feed.yml +15 -0
- data/lib/generators/templates/initializer.rb +19 -0
- data/lib/generators/templates/migration.rb +15 -0
- data/lib/initializers/worker.rb +0 -0
- data/test/buzz_feed_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- metadata +113 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 [Kristijan Sedlak]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
= BuzzFeed - Automated Buzz From The Web Model
|
2
|
+
|
3
|
+
It is popular to have a "Buzz From The Web" widget on the site. This plugin will allow you
|
4
|
+
just that.
|
5
|
+
Use this plugin for automated combining RSS/Atom links from various internet sources. It provides a
|
6
|
+
background worker that periodically updates the Buzz model with fresh RSS/Atom links from
|
7
|
+
sources you define.
|
8
|
+
|
9
|
+
|
10
|
+
== Installation (Rails 3 ready)
|
11
|
+
|
12
|
+
Add this line to your Gemfile (and run bundle install):
|
13
|
+
|
14
|
+
gem 'buzz_feed'
|
15
|
+
|
16
|
+
Run the generator which will generate some configuration files.
|
17
|
+
|
18
|
+
rails g buzz_feed
|
19
|
+
rake db:migrate
|
20
|
+
|
21
|
+
The plugin comes with a Buzz model file. You can override the default model by creating a
|
22
|
+
new app/models/buzz.rb file.
|
23
|
+
|
24
|
+
== Setup
|
25
|
+
|
26
|
+
The generator creates a config/buzz_feed.yml where you configure the plugin. Here is a sample where
|
27
|
+
I defined two sources (smashingmagazine and github RSS sources; the name can be whatever).
|
28
|
+
|
29
|
+
development: &defaults
|
30
|
+
service:
|
31
|
+
smashingmagazine:
|
32
|
+
url: 'http://rss1.smashingmagazine.com/feed/'
|
33
|
+
github:
|
34
|
+
url: 'https://github.com/xpepermint.private.atom?token=1b4b0b956ba3130cc47e420fdb44556f'
|
35
|
+
|
36
|
+
The generator also creates config/initializers/buzz_feed.rb that has defined a Rufus scheduler for
|
37
|
+
periodical reading/updating the Buzz model. You can comment this out to disable periodical updates.
|
38
|
+
|
39
|
+
== Examples
|
40
|
+
|
41
|
+
You can manually read a feed like this:
|
42
|
+
|
43
|
+
data = BuzzFeed::Client.read('github').each do |item|
|
44
|
+
puts item[:id]
|
45
|
+
puts item[:title]
|
46
|
+
puts item[:url]
|
47
|
+
puts item[:created_at]
|
48
|
+
end
|
49
|
+
|
50
|
+
To manually update the Buzz model with fresh links do this:
|
51
|
+
|
52
|
+
BuzzFeed::Client.update('smashingmagazine')
|
53
|
+
|
54
|
+
You can list all defined service names like this:
|
55
|
+
|
56
|
+
data = BuzzFeed::Client.service_names.each do |name|
|
57
|
+
puts name
|
58
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the buzz_feed plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the buzz_feed plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'BuzzFeed'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module BuzzFeed
|
2
|
+
module Client
|
3
|
+
|
4
|
+
# Lists all defined services
|
5
|
+
def self.service_names
|
6
|
+
list = []
|
7
|
+
service = BuzzFeed.config['service'].keys.each do |name|
|
8
|
+
list << name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns data of a service
|
13
|
+
def self.read(name)
|
14
|
+
read_blogspot(BuzzFeed.config['service'][name]['url'])
|
15
|
+
end
|
16
|
+
|
17
|
+
# Updates the Buzz model with fresh links from the service
|
18
|
+
def self.update(name)
|
19
|
+
fresh_data = self.read(name)
|
20
|
+
fresh_ids = fresh_data.map{|b| b[:id]}
|
21
|
+
old_ids = Buzz.select('service_item_id').where('service_name=?', name).where('service_item_id in (?)', fresh_ids).all.map(&:service_item_id)
|
22
|
+
new_ids = fresh_data.map{|b| b[:id]} - old_ids
|
23
|
+
|
24
|
+
fresh_data.each do |buzz|
|
25
|
+
Buzz.create(:title => buzz[:title], :service_name => name, :service_item_id => buzz[:id], :url => buzz[:url],
|
26
|
+
:created_at => buzz[:created_at]) unless new_ids.rindex(buzz[:id]).nil?
|
27
|
+
end
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def self.read_blogspot(url)
|
34
|
+
data = []
|
35
|
+
xml = Nokogiri::XML(open(url)).remove_namespaces!
|
36
|
+
xml.xpath('//feed/entry').each do |item|
|
37
|
+
id = item.xpath('id').text
|
38
|
+
title = item.xpath('title').text.strip
|
39
|
+
created_at = item.xpath('published').text.strip.to_time
|
40
|
+
url = nil
|
41
|
+
item.xpath('link').each do |link|
|
42
|
+
url = link['href'] if link['rel'] == 'alternate'
|
43
|
+
end
|
44
|
+
data << {:id => id, :title => title, :url => url, :created_at => created_at}
|
45
|
+
end
|
46
|
+
data
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/lib/buzz_feed.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module BuzzFeed
|
2
|
+
|
3
|
+
# Return the config yml
|
4
|
+
def self.config
|
5
|
+
@config ||= YAML.load_file(File.join(Rails.root, 'config', 'buzz_feed.yml'))[RAILS_ENV]
|
6
|
+
end
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
%w( buzz_feed/version
|
11
|
+
buzz_feed/client
|
12
|
+
).each do |lib|
|
13
|
+
require File.join(File.dirname(__FILE__), lib)
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class BuzzFeedGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
9
|
+
end
|
10
|
+
|
11
|
+
# Implement the required interface for Rails::Generators::Migration.
|
12
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
13
|
+
def self.next_migration_number(dirname)
|
14
|
+
if ActiveRecord::Base.timestamped_migrations
|
15
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
16
|
+
else
|
17
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_migration_file
|
22
|
+
migration_template 'migration.rb', 'db/migrate/buzz_feed_migration.rb'
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_initializer_file
|
26
|
+
copy_file "initializer.rb", "config/initializers/buzz_feed.rb"
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_config_file
|
30
|
+
copy_file "buzz_feed.yml", "config/buzz_feed.yml"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
development: &defaults
|
2
|
+
service:
|
3
|
+
smashingmagazine:
|
4
|
+
url: 'http://rss1.smashingmagazine.com/feed/'
|
5
|
+
github:
|
6
|
+
url: 'https://github.com/xpepermint.private.atom?token=1b4b0b956ba3130cc47e420fdb44556f'
|
7
|
+
|
8
|
+
staging:
|
9
|
+
<<: *defaults
|
10
|
+
|
11
|
+
production:
|
12
|
+
<<: *defaults
|
13
|
+
|
14
|
+
test:
|
15
|
+
<<: *defaults
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#
|
2
|
+
# BuzzFeed WORKER
|
3
|
+
#
|
4
|
+
# This worker periodically updates the Buzz model with fresh links from the web
|
5
|
+
# defined in the config/buzz_feed.yml.
|
6
|
+
#
|
7
|
+
if !defined?(Rake) && !defined?(IRB) && Rails.env.to_s != 'development'
|
8
|
+
|
9
|
+
Rufus::Scheduler.start_new.every '12h', :first_in => '60s', :blocking => true do |job|
|
10
|
+
Rails.logger.info "[Rufus][#{Time.now}] BuzzFeed worker started."
|
11
|
+
|
12
|
+
data = BuzzFeed::Client.service_names.each do |name|
|
13
|
+
BuzzFeed::Client.update(name)
|
14
|
+
end
|
15
|
+
|
16
|
+
Rails.logger.info "[Rufus][#{Time.now}] BuzzFeed worker finished."
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class BuzzFeedMigration < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :buzzs do |t|
|
4
|
+
t.string :title
|
5
|
+
t.string :service_name, :default => 'website'
|
6
|
+
t.string :service_item_id
|
7
|
+
t.string :url
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :buzzs
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: buzz_feed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kristijan Sedlak
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-07 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rufus-scheduler
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 1
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 0
|
33
|
+
- 7
|
34
|
+
version: 2.0.7
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: nokogiri
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 15
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 4
|
49
|
+
- 4
|
50
|
+
version: 1.4.4
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Use this plugin for automated combining RSS/Atom links from various internet sources.
|
54
|
+
email: xpepermint@gmail.com
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files:
|
60
|
+
- README.rdoc
|
61
|
+
- MIT-LICENSE
|
62
|
+
files:
|
63
|
+
- Rakefile
|
64
|
+
- lib/buzz_feed/client.rb
|
65
|
+
- lib/buzz_feed/version.rb
|
66
|
+
- lib/buzz_feed.rb
|
67
|
+
- lib/generators/buzz_feed_generator.rb
|
68
|
+
- lib/generators/templates/buzz_feed.yml
|
69
|
+
- lib/generators/templates/initializer.rb
|
70
|
+
- lib/generators/templates/migration.rb
|
71
|
+
- lib/initializers/worker.rb
|
72
|
+
- test/buzz_feed_test.rb
|
73
|
+
- test/test_helper.rb
|
74
|
+
- README.rdoc
|
75
|
+
- MIT-LICENSE
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: http://github.com/xpepermint/buzz_feed
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- --main
|
83
|
+
- README.rdoc
|
84
|
+
- --charset=UTF-8
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.3.7
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: BuzzFeed - Automated Buzz From The Web Model.
|
112
|
+
test_files: []
|
113
|
+
|