siyelo-tweetify 0.1.2
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/CHANGELOG +12 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +70 -0
- data/Rakefile +41 -0
- data/TODO +2 -0
- data/VERSION +1 -0
- data/app/models/tweet.rb +65 -0
- data/app/views/tweets/_list.html.haml +5 -0
- data/generators/tweetify_install/USAGE +4 -0
- data/generators/tweetify_install/templates/README +15 -0
- data/generators/tweetify_install/templates/migration.rb +18 -0
- data/generators/tweetify_install/templates/tweetify.rb +11 -0
- data/generators/tweetify_install/tweetify_install_generator.rb +15 -0
- data/generators/tweetify_views/USAGE +3 -0
- data/generators/tweetify_views/tweetify_views_generator.rb +21 -0
- data/init.rb +1 -0
- data/lib/tweetify.rb +14 -0
- data/test/performance/browsing_test.rb +9 -0
- data/test/test_helper.rb +38 -0
- data/test/unit/blog_post_test.rb +8 -0
- metadata +104 -0
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2010 Siyelo. http://www.siyelo.com
|
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,70 @@
|
|
1
|
+
== Tweetify
|
2
|
+
|
3
|
+
A Rails engine for embedding Twitter extracts
|
4
|
+
|
5
|
+
== Dependencies
|
6
|
+
|
7
|
+
Tweetify needs;
|
8
|
+
|
9
|
+
dancroak-twitter-search
|
10
|
+
|
11
|
+
== Installation
|
12
|
+
|
13
|
+
All gems are on gemcutter, so you need to add gemcutter to your sources if you havent yet:
|
14
|
+
|
15
|
+
sudo gem sources -a http://gemcutter.org/
|
16
|
+
|
17
|
+
Install required gem if you dont already have them
|
18
|
+
|
19
|
+
sudo gem install dancroak-twitter-search
|
20
|
+
|
21
|
+
Install the tweetify gem:
|
22
|
+
|
23
|
+
sudo gem install siyelo-tweetify
|
24
|
+
|
25
|
+
Configure gems inside your app:
|
26
|
+
|
27
|
+
config.gem 'rufus-scheduler'
|
28
|
+
config.gem 'dancroak-twitter-search', :lib => "twitter_search"
|
29
|
+
config.gem 'siyelo-tweetify', :lib => "tweetify"
|
30
|
+
|
31
|
+
Run the generator:
|
32
|
+
|
33
|
+
ruby script/generate tweetify
|
34
|
+
|
35
|
+
The generator will install an initializer which describes Tweetify's configuration options. Be sure to update this with your own Twitter search string and 'search agent' name.
|
36
|
+
|
37
|
+
== Basic Usage
|
38
|
+
|
39
|
+
Once the rufus scheduler task is running, it will go off and cache your last N (Tweet.tweet_limit) twitter serach matches.
|
40
|
+
|
41
|
+
Inside your relevant controller, all you need to do is read the cached posts from your database.
|
42
|
+
|
43
|
+
@tweets = Tweet.find(:all, :limit => 3)
|
44
|
+
|
45
|
+
And render them in your view as you wish
|
46
|
+
|
47
|
+
For convenience, some partials are included
|
48
|
+
|
49
|
+
= render :partial => '/tweets/list', :locals => { :tweets => @tweets }
|
50
|
+
|
51
|
+
== TODO
|
52
|
+
|
53
|
+
Please refer to TODO file.
|
54
|
+
|
55
|
+
== Maintainers
|
56
|
+
|
57
|
+
* Glenn Roberts
|
58
|
+
|
59
|
+
== Contributors
|
60
|
+
|
61
|
+
Check them in the CHANGELOG or do `git shortlog -s -n` in the cloned repository.
|
62
|
+
|
63
|
+
== Bugs and Feedback
|
64
|
+
|
65
|
+
If you discover any bugs or want to drop a line, feel free to create an issue on
|
66
|
+
GitHub.
|
67
|
+
|
68
|
+
http://github.com/siyelo/tweetify/issues
|
69
|
+
|
70
|
+
MIT License. Copyright 2010. Siyelo Software CC. http://www.siyelo.com
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "siyelo-tweetify"
|
9
|
+
gem.summary = %Q{A Rails engine for embedding Twitter extracts}
|
10
|
+
gem.description = %Q{A Rails engine for embedding Twitter extracts}
|
11
|
+
gem.email = "glenn.roberts@siyelo.com"
|
12
|
+
gem.homepage = "http://github.com/siyelo/siyelo-tweetify"
|
13
|
+
gem.authors = ["Glenn Roberts"]
|
14
|
+
gem.add_dependency 'edgar-twitter-search', '>=0.5.10'
|
15
|
+
gem.files = FileList["[A-Z]*", "{app,config,generators,lib}/**/*", "init.rb"]
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Run Tweetify unit tests.'
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Generate documentation for Tweetify.'
|
32
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
33
|
+
rdoc.rdoc_dir = 'rdoc'
|
34
|
+
rdoc.title = 'Tweetify'
|
35
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
36
|
+
rdoc.rdoc_files.include('README.rdoc')
|
37
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'Default: run unit tests.'
|
41
|
+
task :default => :test
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
data/app/models/tweet.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
class Tweet < ActiveRecord::Base
|
2
|
+
|
3
|
+
cattr_accessor :search_string
|
4
|
+
@@search_string = "siyelo OR \"siyelo software\""
|
5
|
+
|
6
|
+
cattr_accessor :search_agent
|
7
|
+
@@search_agent = 'tweetify_agent'
|
8
|
+
|
9
|
+
cattr_accessor :read_timeout
|
10
|
+
@@read_timeout = 5.seconds
|
11
|
+
|
12
|
+
cattr_accessor :tweet_limit
|
13
|
+
@@tweet_limit = 3
|
14
|
+
|
15
|
+
attr_accessible :tweet_created_at,
|
16
|
+
:text,
|
17
|
+
:from_user,
|
18
|
+
:tweet_id,
|
19
|
+
:link
|
20
|
+
|
21
|
+
def self.cache_tweets
|
22
|
+
tweets = self.read_tweets
|
23
|
+
self.update_tweets(tweets)
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def self.read_tweets
|
29
|
+
tweets = []
|
30
|
+
begin
|
31
|
+
timeout(read_timeout) do
|
32
|
+
client = TwitterSearch::Client.new(search_agent)
|
33
|
+
tweets = client.query(:q => search_string, :rpp => tweet_limit, :page => '1')
|
34
|
+
end
|
35
|
+
rescue TimeoutError
|
36
|
+
logger.warn("Timeout accessing Twitter: #{$!}, #{$@}")
|
37
|
+
rescue
|
38
|
+
unless $!.message.match /302 Moved Temporarily/ #then no search results returned.
|
39
|
+
logger.warn("Error accessing Twitter: #{$!}")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
tweets.nil? ? [] : tweets
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.update_tweets(tweets)
|
47
|
+
unless tweets.empty?
|
48
|
+
old_tweets = Tweet.find(:all, :order => 'tweet_created_at')
|
49
|
+
|
50
|
+
tweets.each do |t|
|
51
|
+
n = self.create(:tweet_created_at => t.created_at.to_time,
|
52
|
+
:text => t.text,
|
53
|
+
:from_user => t.from_user,
|
54
|
+
:tweet_id => t.id,
|
55
|
+
:link => "http://twitter.com/#{t.from_user}/status/#{t.id}")
|
56
|
+
|
57
|
+
# expire oldest tweet
|
58
|
+
old_tweets.pop.destroy unless old_tweets.empty?
|
59
|
+
end
|
60
|
+
else
|
61
|
+
logger.info("No new tweets found.")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
===============================================================================
|
3
|
+
|
4
|
+
Some setup you must do manually if you haven't yet:
|
5
|
+
|
6
|
+
1. Ensure you have defined your Twitter user name in config/tweetify.rb
|
7
|
+
|
8
|
+
2. Ensure you have defined your Twitter search agent in config/tweetify.rb
|
9
|
+
|
10
|
+
3. Run rake db:migrate to create the Tweets table.
|
11
|
+
|
12
|
+
Note: the initializer creates its own Rufus scheduler task - so if you have
|
13
|
+
other Rufus tasks, you may want to consolidate them.
|
14
|
+
|
15
|
+
===============================================================================
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateTweets < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :tweets do |t|
|
4
|
+
t.string :type
|
5
|
+
t.datetime :tweet_created_at
|
6
|
+
t.string :from_user
|
7
|
+
t.text :text
|
8
|
+
t.string :tweet_id
|
9
|
+
t.string :link
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :tweets
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Tweet.search_string = "siyelo OR \"siyelo software\""
|
2
|
+
Tweet.search_agent = "SOME_UNIQUE_IDENTIFIER"
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rufus/scheduler'
|
6
|
+
|
7
|
+
scheduler = Rufus::Scheduler.start_new(:frequency => 900.0)
|
8
|
+
|
9
|
+
scheduler.every '1h' do
|
10
|
+
Tweet.cache_tweets
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
class TweetifyInstallGenerator < Rails::Generator::Base
|
3
|
+
|
4
|
+
def manifest
|
5
|
+
record do |m|
|
6
|
+
|
7
|
+
m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "tweetify_create_blog_posts"
|
8
|
+
|
9
|
+
m.directory "config/initializers"
|
10
|
+
m.template "tweetify.rb", "config/initializers/tweetify.rb"
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class TweetifyViewsGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
def initialize(*args)
|
4
|
+
super
|
5
|
+
@source_root = options[:source] || File.join(spec.path, '..', '..')
|
6
|
+
end
|
7
|
+
|
8
|
+
def manifest
|
9
|
+
record do |m|
|
10
|
+
m.directory "app/views"
|
11
|
+
|
12
|
+
Dir[File.join(@source_root, "app", "views", "**/*.haml")].each do |file|
|
13
|
+
file = file.gsub(@source_root, "")[1..-1]
|
14
|
+
|
15
|
+
m.directory File.dirname(file)
|
16
|
+
m.file file, file
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'tweetify'
|
data/lib/tweetify.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
+
require 'test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Transactional fixtures accelerate your tests by wrapping each test method
|
7
|
+
# in a transaction that's rolled back on completion. This ensures that the
|
8
|
+
# test database remains unchanged so your fixtures don't have to be reloaded
|
9
|
+
# between every test method. Fewer database queries means faster tests.
|
10
|
+
#
|
11
|
+
# Read Mike Clark's excellent walkthrough at
|
12
|
+
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
13
|
+
#
|
14
|
+
# Every Active Record database supports transactions except MyISAM tables
|
15
|
+
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
16
|
+
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
17
|
+
# is recommended.
|
18
|
+
#
|
19
|
+
# The only drawback to using transactional fixtures is when you actually
|
20
|
+
# need to test transactions. Since your test is bracketed by a transaction,
|
21
|
+
# any transactions started in your code will be automatically rolled back.
|
22
|
+
self.use_transactional_fixtures = true
|
23
|
+
|
24
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
25
|
+
# would need people(:david). If you don't want to migrate your existing
|
26
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
27
|
+
# instantiated fixtures translates to a database query per test method),
|
28
|
+
# then set this back to true.
|
29
|
+
self.use_instantiated_fixtures = false
|
30
|
+
|
31
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
32
|
+
#
|
33
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
34
|
+
# -- they do not yet inherit this setting
|
35
|
+
fixtures :all
|
36
|
+
|
37
|
+
# Add more helper methods to be used by all tests here...
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: siyelo-tweetify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Glenn Roberts
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-04 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: edgar-twitter-search
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 31
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 5
|
33
|
+
- 10
|
34
|
+
version: 0.5.10
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: A Rails engine for embedding Twitter extracts
|
38
|
+
email: glenn.roberts@siyelo.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- README.rdoc
|
45
|
+
- TODO
|
46
|
+
files:
|
47
|
+
- CHANGELOG
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- TODO
|
52
|
+
- VERSION
|
53
|
+
- app/models/tweet.rb
|
54
|
+
- app/views/tweets/_list.html.haml
|
55
|
+
- generators/tweetify_install/USAGE
|
56
|
+
- generators/tweetify_install/templates/README
|
57
|
+
- generators/tweetify_install/templates/migration.rb
|
58
|
+
- generators/tweetify_install/templates/tweetify.rb
|
59
|
+
- generators/tweetify_install/tweetify_install_generator.rb
|
60
|
+
- generators/tweetify_views/USAGE
|
61
|
+
- generators/tweetify_views/tweetify_views_generator.rb
|
62
|
+
- init.rb
|
63
|
+
- lib/tweetify.rb
|
64
|
+
- test/performance/browsing_test.rb
|
65
|
+
- test/test_helper.rb
|
66
|
+
- test/unit/blog_post_test.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/siyelo/siyelo-tweetify
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- --charset=UTF-8
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.3.7
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: A Rails engine for embedding Twitter extracts
|
101
|
+
test_files:
|
102
|
+
- test/performance/browsing_test.rb
|
103
|
+
- test/test_helper.rb
|
104
|
+
- test/unit/blog_post_test.rb
|