twog 0.3.1 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- coverage/
2
- pkg/
3
- *.swp
data/README.textile DELETED
@@ -1,74 +0,0 @@
1
- h1. Twog
2
-
3
- By Jason Meridth
4
-
5
- Twog is a simple application that parses an RSS feed and will tweet any posts it hasn't already tweeted. Once you obtain OAuth access to a twitter account and provide it in the configuration and run Twog, it will tweet a prefix, your blog title, and a URL of the post. There are also options of using Bit.ly for URL shortening and you can install Twog as a cron job for automated polling.
6
-
7
- h2. Install
8
-
9
- sudo gem install twog
10
-
11
- h2. Writing to Twitter With OAuth
12
-
13
- Please read "this":http://www.lostechies.com/blogs/jason_meridth/archive/2010/04/05/oauth.aspx if you want to know how to get your Twitter OAuth consumer key/secret and access token/secret.
14
-
15
- One you have those, run the command:
16
-
17
- bq. twog --conf
18
-
19
- and a hidden configuration file will be created in the your home folder (~/.twog/conf.yaml). Once there, please fill it out with the information necessary to use this tool.
20
-
21
- h2. Seeing What Will Be Tweeted
22
-
23
- To see what will be Tweeted before it is, type:
24
-
25
- bq. twog -o
26
-
27
- or
28
-
29
- bq. twog --output
30
-
31
- h2. Shortening Blog Post URLs With Bitly API
32
-
33
- In order to use Bitly for URL shortening, you'll need to go to http://bit.ly and click the "Sign Up":http://bit.ly/account/register?rd=/ link on the top right and get an account. Once you are logged-in you click the "Account":http://bit.ly/account link in the same top right area. You will see your API Key in the middle of the page.
34
-
35
- Put your bit.ly username and api key into the ~/.twog/conf.yaml file to be used in the code.
36
-
37
- h2. Automating Polling With Cron
38
-
39
- To install twog as a crontab job, run the command:
40
-
41
- bq. twog --cronadd N
42
-
43
- where N is the number of minutes you want twog to fire off every time.
44
-
45
- To remove twog as a crontab job, run the command:
46
-
47
- bq. twog --cronrm
48
-
49
- "Crontab Info":http://www.unixgeeks.org/security/newbie/unix/cron-1.html for all my non-*nix bretheren.
50
-
51
- h2. Runtime Dependencies
52
-
53
- * TwitterOauth: Writes tweets to Twitter (Ruby)
54
- * Whenever: Sets up cron jobs (Ruby)
55
- * Bitly: Shortens URLs (Ruby)
56
-
57
- h2. Developer Dependencies
58
-
59
- * RSpec: Test and Mocking framework (Ruby)
60
-
61
- h2. TODO
62
-
63
- Please check the "issues":http://github.com/armmer/twog/issues on Github for future features or bugs that need to be fixed
64
-
65
- h2. Contributors
66
-
67
- Matt Dietz ("cerberus98":http://github.com/cerberus98) special thanks
68
- Chris MacGown ("ChristopherMacGown":http://github.com/ChristopherMacGown)
69
- Paul Voccio ("pvo":http://github.com/pvo)
70
- Joe Ocampo ("agilejoe":http://github.com/agilejoe)
71
-
72
- h2. Copyright
73
-
74
- Copyright (c) 2010 Jason Meridth. See LICENSE for details.
@@ -1,39 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe Twog::BlogPostsHandler do
4
- include TwogSpecHelper
5
- include Twog::BlogPostsHandler
6
-
7
- before(:each) do
8
- post = Twog::Post.new(stub('', :pubDate => Time.now, :link => 'http://tinyurl.com'))
9
- @posts = [post]
10
- @last_blog_post_tweeted = test_conf['last_blog_post_tweeted']
11
- end
12
-
13
- it "should determine that there is one new blog post to tweet" do
14
- posts = get_new_blog_posts(@posts, @last_blog_post_tweeted)
15
- posts.length.should == 1
16
- end
17
-
18
- it "should return zero if posts are nil" do
19
- posts = get_new_blog_posts(nil, @last_blog_post_tweeted)
20
- posts.length.should == 0
21
- end
22
-
23
- it "should return zero if no posts are passed" do
24
- posts = get_new_blog_posts([], @last_blog_post_tweeted)
25
- posts.length.should == 0
26
- end
27
-
28
- it "should return the posts if there is no last_blog_post_tweeted in the conf file" do
29
- posts = get_new_blog_posts(@posts, nil)
30
- posts.length.should == 1
31
- end
32
-
33
- it "should return zero posts if the date is older than the last blog post date tweeted" do
34
- post = Twog::Post.new(stub('', :pubDate => (Date.parse(@last_blog_post_tweeted.to_s) - 10).to_s, :link => 'http://tinyurl.com'))
35
- @posts = [post]
36
- posts = get_new_blog_posts(@posts, @last_blog_post_tweeted)
37
- posts.length.should == 0
38
- end
39
- end
data/spec/post_spec.rb DELETED
@@ -1,74 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe Twog::Post do
4
- context "when rss entry has updated and link.href" do
5
- before(:each) do
6
- updated = stub('update', :content => '2010-04-02T01:00:00-06:00')
7
- link = stub('link', :href => 'http://tinyurl.com')
8
- @post = stub('post', :updated => updated, :link => link)
9
-
10
- end
11
-
12
- it "should return a link" do
13
-
14
- twog_post = Twog::Post.new(@post)
15
-
16
- twog_post.link.should == "http://tinyurl.com"
17
- twog_post.date.should == "2010-04-02T01:00:00-06:00"
18
- end
19
-
20
- ##
21
- ## RE-WRITE TO BE MORE RUBYISH
22
- ##
23
- it "should sort multiple posts" do
24
- unsorted = (1..10).sort_by { rand }.collect do |i|
25
- updated = stub('update', :content => (Time.now + (60*60*24*i)).to_s)
26
- link = stub('link', :href => 'http://tinyurl.com')
27
- post = stub('post', :updated => updated, :link => link)
28
- Twog::Post.new(post)
29
- end
30
- sorted = unsorted.sort!
31
- sorted.length.should == 10
32
-
33
- time = Time.now
34
- sorted.each do |p|
35
- p_time = Time.parse(p.date.to_s)
36
- p_time.should be > time
37
- time = p_time
38
- end
39
- end
40
- end
41
-
42
- context "when rss entry has pubDate and link" do
43
- before(:each) do
44
- @post = stub('post', :pubDate => '2010-04-02T01:00:00-06:00', :link => 'http://tinyurl.com')
45
- end
46
-
47
- it "should return a link" do
48
- twog_post = Twog::Post.new(@post)
49
-
50
- twog_post.link.should == "http://tinyurl.com"
51
- twog_post.date.should == "2010-04-02T01:00:00-06:00"
52
- end
53
-
54
- ##
55
- ## RE-WRITE TO BE MORE RUBYISH
56
- ##
57
- it "should sort multiple posts again" do
58
- unsorted = (1..10).sort_by { rand }.collect do |i|
59
- post = stub('post', :pubDate => (Time.now + (60*60*24*i)).to_s, :link => 'http://tinyurl.com')
60
- Twog::Post.new(post)
61
- end
62
- sorted = unsorted.sort!
63
- sorted.length.should == 10
64
-
65
- time = Time.now
66
- sorted.each do |p|
67
- p_time = Time.parse(p.date.to_s)
68
- p_time.should be > time
69
- time = p_time
70
- end
71
-
72
- end
73
- end
74
- end
@@ -1,32 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe Twog::RssEntryToTwogPostMapper do
4
- include Twog::RssEntryToTwogPostMapper
5
-
6
- it "should convert rss entries that have updated.content and link.href" do
7
- updated = stub('update', :content => '2010-04-02T01:00:00-06:00')
8
- link = stub('link', :href => 'http://tinyurl.com')
9
- post = stub('post', :updated => updated, :link => link)
10
-
11
- posts = (0..20).collect { |x| post }
12
-
13
- twog_posts = map(posts)
14
- twog_posts.length.should == 21
15
- twog_posts.each do |p|
16
- p.date.should == "2010-04-02T01:00:00-06:00"
17
- p.link.should == "http://tinyurl.com"
18
- end
19
- end
20
-
21
- it "should convert rss entries that have pubDate and link" do
22
- post = stub('post', :pubDate => '2010-04-02T01:00:00-06:00', :link => 'http://tinyurl.com')
23
- posts = (0..20).collect { |x| post }
24
-
25
- twog_posts = map(posts)
26
- twog_posts.length.should == 21
27
- twog_posts.each do |p|
28
- p.date.should == "2010-04-02T01:00:00-06:00"
29
- p.link.should == "http://tinyurl.com"
30
- end
31
- end
32
- end
@@ -1,18 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe Twog::RssParser do
4
- include TwogSpecHelper
5
- include Twog::RssParser
6
-
7
- it "should throw exception if rss_feed isn't provided" do
8
- lambda { parse_feed(nil) }.should raise_error('RSS feed missing')
9
- end
10
-
11
- it "should read the rss_feed_url and parse the items" do
12
- self.stub!(:open).and_return(rss_feed_url_content)
13
- items = parse_feed(test_conf)
14
- items.length.should == 1
15
- items[0].title.content.should == "Pair Programming"
16
- items[0].link.href.should == "http://blog.jasonmeridth.com/2009/01/29/pair-programming.html"
17
- end
18
- end
@@ -1,60 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
- require 'rubygems'
3
- require 'rss'
4
-
5
- describe Twog::TwitterHandler do
6
- include TwogSpecHelper
7
- include Twog::TwitterHandler
8
-
9
- before(:each) do
10
- @posts = [stub('post', :date => Time.now, :link => 'http://bit.ly/Afr8s9')]
11
- @conf = test_conf
12
- end
13
-
14
- it "should do nothing if no posts are provided" do
15
- tweet(nil, nil, nil)
16
- tweet([], nil, nil)
17
- end
18
-
19
- it "should throw exception if oauth consumer key isn't provided" do
20
- @conf['consumer_key'] = nil
21
- lambda { tweet(@posts, @conf, nil) }.should raise_error('OAuth Consumer Key missing')
22
- end
23
-
24
- it "should throw exception if oauth consumer secret isn't provided" do
25
- @conf['consumer_secret'] = nil
26
- lambda { tweet(@posts, @conf, nil) }.should raise_error('OAuth Consumer Secret missing')
27
- end
28
-
29
- it "should throw exception if oauth access token isn't provided" do
30
- @conf['access_token'] = nil
31
- lambda { tweet(@posts, @conf, nil) }.should raise_error('OAuth Access Token missing')
32
- end
33
-
34
- it "should throw exception if oauth access secret isn't provided" do
35
- @conf['access_secret'] = nil
36
- lambda { tweet(@posts, @conf, nil) }.should raise_error('OAuth Access Secret missing')
37
- end
38
-
39
- it "should shorten the blog post url with bitly when bitly handler is provided" do
40
- bitly = mock 'bitly'
41
- bitly_url = mock 'bitly_url'
42
- bitly.should_receive(:shorten).and_return(bitly_url)
43
- bitly_url.should_receive(:short_url)
44
- self.stub!(:use_twitter_oauth)
45
- self.stub!(:update_config_file_with_latest_tweet_date)
46
- tweet(@posts, @conf, bitly)
47
- end
48
-
49
- it "should make sure the text that is tweeted is at or less than 140 chars when the title is at or greater than 140 chars" do
50
- text = ensure_text_is_of_length(140, "1234567890"*14, "http://bit.ly/Afr8s9")
51
- text.should == "blogged: 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 http://bit.ly/Afr8s9"
52
- text.length.should == 140
53
- end
54
-
55
- it "should make sure the text that is tweeted is at or less than 140 chars when the title is less than 140 chars" do
56
- text = ensure_text_is_of_length(140, "1234567890", "http://bit.ly/Afr8s9")
57
- text.should == "blogged: 1234567890 http://bit.ly/Afr8s9"
58
- text.length.should == 40
59
- end
60
- end
data/spec/twog_spec.rb DELETED
@@ -1,39 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe Twog do
4
- include TwogSpecHelper
5
- include Twog::Twog
6
-
7
- it "should not tweet if there are no new blog posts" do
8
- stub!(:get_posts_to_tweet).with(test_conf).and_return([])
9
- stub!(:tweet).and_return(1)
10
- result = run(test_conf)
11
- result.should be nil
12
- end
13
-
14
- it "should parse the rss feed and tweet new blog posts" do
15
- entry = rss_entry
16
- stub!(:get_posts_to_tweet).with(test_conf).and_return([entry])
17
- stub!(:get_bitly_from)
18
- stub!(:tweet).and_return(1)
19
- result = run(test_conf)
20
- result.should == 1
21
- end
22
-
23
- it "should return nil if bitly username is nil" do
24
- conf = test_conf
25
- conf['bitly_username'] = nil
26
- get_bitly_from(conf).should be nil
27
- end
28
-
29
- it "should return nil if bitly api key is nil" do
30
- conf = test_conf
31
- conf['bitly_username'] = nil
32
- get_bitly_from(conf).should be nil
33
- end
34
-
35
- it "should return nil if bitly api key is nil" do
36
- Bitly.stub!(:new).and_return("hello")
37
- get_bitly_from(test_conf).should == "hello"
38
- end
39
- end