twuckoo 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ config/twuckoo.yml
1
2
  lines.txt
2
3
  used_lines*.txt
3
4
  todos.txt
@@ -6,6 +7,5 @@ vendor/gems/ruby/**/gems
6
7
  vendor/gems/ruby/**/specifications
7
8
  vendor/gems/ruby/**/doc
8
9
  vendor/gems/ruby/**/environment.rb
9
- mail_proba.rb
10
- optparse_proba.rb
11
- super_proba.rb
10
+ *_proba.rb
11
+ oauth/
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ begin
13
13
  gemspec.authors = ["Balint Erdi"]
14
14
  gemspec.add_development_dependency("mocha", ">= 0.9.5")
15
15
  gemspec.add_development_dependency("rspec")
16
- gemspec.add_dependency("twibot", ">=0.1.7")
16
+ gemspec.add_dependency("twitter_oauth", "~> 0.4.3")
17
17
  gemspec.add_dependency("hpricot", ">= 0.6.164")
18
18
  gemspec.add_dependency("mail", ">= 1.6.0")
19
19
  gemspec.add_dependency("tlsmail", ">= 0.0.1")
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.5.0
@@ -3,6 +3,6 @@
3
3
  dir = File.join(File.dirname(__FILE__), '..', 'lib')
4
4
  require File.join(dir, 'twuckoo')
5
5
 
6
- @runner = Twuckoo::Runner.create(ARGV)
6
+ @runner = Twuckoo::Runner.new(ARGV.shift, nil, ARGV)
7
7
  # @runner.set_testing
8
8
  @runner.run
@@ -9,9 +9,8 @@ module OneLineFromFile
9
9
  LINES_FILE = 'lines.txt'
10
10
  USED_LINES_FILE = 'used_lines.txt'
11
11
 
12
- def initialize(args=[])
12
+ def setup_for_module
13
13
  @lines = []
14
- # load_lines
15
14
  end
16
15
 
17
16
  def load_tweets
@@ -5,7 +5,7 @@ require "hpricot"
5
5
  module WikipediaTFA
6
6
 
7
7
  WIKIPEDIA_HOST = "http://en.wikipedia.org"
8
- def initialize(args=[])
8
+ def setup_for_module
9
9
  end
10
10
 
11
11
  def load_tweets; end
@@ -10,4 +10,4 @@ require 'modules'
10
10
 
11
11
  require 'twuckoo/config'
12
12
  require 'twuckoo/runner'
13
-
13
+ require 'twuckoo/twitter_oauth_module'
@@ -1,6 +1,5 @@
1
1
  require "optparse"
2
2
  require "ostruct"
3
- require "twibot"
4
3
  require "mail"
5
4
 
6
5
  class TwuckooException < Exception
@@ -18,7 +17,6 @@ class Twuckoo::Runner
18
17
  next_tweet = self.next
19
18
  while (next_tweet and !tweet_limit_reached?) do
20
19
  tweet(next_tweet)
21
- inc_tweet_counter
22
20
  wait if wait_between_tweets?
23
21
  next_tweet = self.next
24
22
  if next_tweet.nil?
@@ -29,22 +27,18 @@ class Twuckoo::Runner
29
27
  end
30
28
  end
31
29
 
32
- def self.create(args=[])
33
- module_name = args.first
30
+ attr_accessor :tweets_sent
31
+
32
+ def initialize(module_name, twitter_module=nil, args=[])
34
33
  unless module_name.nil?
35
- _module = get_module(module_name)
34
+ _module = self.class.get_module(module_name)
36
35
  class_eval { include _module }
37
36
  end
38
- new(args)
39
- end
40
-
41
- attr_accessor :tweets_sent
42
-
43
- def initialize(args=[])
44
37
  @tweets_sent = 0
38
+ @twitter_module = twitter_module.nil? ? Twuckoo::TwitterOauth : twitter_module
45
39
  @options = OpenStruct.new
46
40
  parse_options!(args)
47
- super
41
+ setup_for_module
48
42
  end
49
43
 
50
44
  def parse_options!(args)
@@ -60,11 +54,6 @@ class Twuckoo::Runner
60
54
  end
61
55
  end
62
56
 
63
- if args.length.zero?
64
- puts opts.banner
65
- exit
66
- end
67
-
68
57
  # opts.on_tail("--version", "Show version") do
69
58
  # File.read(...)
70
59
  # exit
@@ -92,8 +81,14 @@ class Twuckoo::Runner
92
81
 
93
82
  def tweet(message)
94
83
  unless message.nil? or message.empty?
95
- store(message)
96
- send_tweet(message)
84
+ begin
85
+ send_tweet(message, config)
86
+ rescue @twitter_module.exception
87
+ return message
88
+ else
89
+ inc_tweet_counter
90
+ store(message)
91
+ end
97
92
  end
98
93
  message
99
94
  end
@@ -138,8 +133,8 @@ class Twuckoo::Runner
138
133
  end
139
134
  end
140
135
 
141
- def send_tweet(message)
142
- twitter.status(:post, message)
136
+ def send_tweet(message, options)
137
+ @twitter_module._tweet(message, options)
143
138
  end
144
139
 
145
140
  def inc_tweet_counter
@@ -0,0 +1,16 @@
1
+ require 'twitter_oauth/client'
2
+ require 'twitter_oauth'
3
+
4
+ module Twuckoo::TwitterOauth
5
+
6
+ def self._tweet(message, options)
7
+ @client ||= TwitterOAuth::Client.new(
8
+ :consumer_key => options[:consumer_key],
9
+ :consumer_secret => options[:consumer_secret],
10
+ :token => options[:oauth_token],
11
+ :secret => options[:oauth_token_secret]
12
+ )
13
+ @client.update(message)
14
+ end
15
+
16
+ end
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
3
  describe "A cuckoo twitterer with one line from a file" do
4
4
  before do
5
- @twuckoo = Twuckoo::Runner.create(["file"])
5
+ @twuckoo = Twuckoo::Runner.new("file")
6
6
  # just so that no files will be written
7
7
  @twuckoo.stubs(:store).returns(nil)
8
8
  # and the actual text tweets are not tweeted (twittered?)
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
2
 
3
3
  describe Twuckoo::Runner do
4
4
  before do
5
- @twuckoo = Twuckoo::Runner.create(["file"])
5
+ @twuckoo = Twuckoo::Runner.new("file")
6
6
  # actual text tweets should not be tweeted (twittered?)
7
7
  @twuckoo.stubs(:send_tweet).returns(true)
8
8
  end
@@ -43,22 +43,22 @@ describe Twuckoo::Runner do
43
43
  @twuckoo.setup do |config|
44
44
  config[:tweet_limit] = 2
45
45
  end
46
- @twuckoo.expects(:tweet).times(2)
46
+ @twuckoo.expects(:send_tweet).times(2).returns("tweet me this")
47
47
  @twuckoo.run
48
48
  end
49
49
 
50
50
  it "should receive the module to use as the last parameter" do
51
- runner = Twuckoo::Runner.new(%w[file])
51
+ runner = Twuckoo::Runner.new('file')
52
52
  runner.should respond_to(:reset)
53
53
  end
54
54
 
55
55
  it "name can be given through the -n option" do
56
- runner = Twuckoo::Runner.new(%w[-n pragthinklearn file])
56
+ runner = Twuckoo::Runner.new('file', nil, %w[-n pragthinklearn])
57
57
  runner.name.should == "pragthinklearn"
58
58
  end
59
59
 
60
- it "if no is given, the directory name is used" do
61
- runner = Twuckoo::Runner.new(%w[file])
60
+ it "if no name is given, the directory name is used" do
61
+ runner = Twuckoo::Runner.new('file')
62
62
  runner.name.should == "twuckoo"
63
63
  end
64
64
 
@@ -84,4 +84,35 @@ describe Twuckoo::Runner do
84
84
  end
85
85
  end
86
86
 
87
+ it "tries tweeting again if Twitter is not available" do
88
+ module ShakyTwitter
89
+ i = 0
90
+ define_method :_tweet do |message, options|
91
+ if i == 0
92
+ i = i + 1
93
+ raise ShakyTwitterException, "Twitter is down. Try again later"
94
+ else
95
+ i = i + 1
96
+ message
97
+ end
98
+ end
99
+
100
+ extend self
101
+
102
+ class ShakyTwitterException < Exception
103
+ end
104
+ def self.exception
105
+ ShakyTwitterException
106
+ end
107
+ end
108
+ twuckoo = Twuckoo::Runner.new("file", ShakyTwitter)
109
+ twuckoo.stubs(:send_email).returns(true)
110
+ twuckoo.setup do |config|
111
+ config[:tweet_limit] = 2
112
+ config[:time_to_sleep] = "0"
113
+ end
114
+ twuckoo.stubs(:next).returns('Twuckoo 2.0 is coming soonish')
115
+ twuckoo.run
116
+ twuckoo.tweets_sent.should == 2
117
+ end
87
118
  end
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
3
  describe "A cuckoo twitterer for wikipedia featured article" do
4
4
  before do
5
- @twuckoo = Twuckoo::Runner.create(["wikipedia_tfa"])
5
+ @twuckoo = Twuckoo::Runner.new("wikipedia_tfa")
6
6
  @twuckoo.setup do |config|
7
7
  config[:time_to_sleep] = "0"
8
8
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{twuckoo}
8
- s.version = "0.4.2"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Balint Erdi"]
12
- s.date = %q{2010-04-28}
12
+ s.date = %q{2010-09-12}
13
13
  s.default_executable = %q{twuckoo}
14
14
  s.description = %q{ A simple yet elegant solution to tweet a message regularly from a file (or from a webpage, a database, etc.)
15
15
  }
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "lib/twuckoo.rb",
36
36
  "lib/twuckoo/config.rb",
37
37
  "lib/twuckoo/runner.rb",
38
+ "lib/twuckoo/twitter_oauth_module.rb",
38
39
  "spec/duration_string_spec.rb",
39
40
  "spec/one_line_from_file_spec.rb",
40
41
  "spec/spec.opts",
@@ -48,7 +49,7 @@ Gem::Specification.new do |s|
48
49
  s.homepage = %q{http://github.com/balinterdi/twuckoo}
49
50
  s.rdoc_options = ["--charset=UTF-8"]
50
51
  s.require_paths = ["lib"]
51
- s.rubygems_version = %q{1.3.6}
52
+ s.rubygems_version = %q{1.3.7}
52
53
  s.summary = %q{Need to tweet periodically in an automated fashion? Then Twuckoo is for you!}
53
54
  s.test_files = [
54
55
  "spec/duration_string_spec.rb",
@@ -63,17 +64,17 @@ Gem::Specification.new do |s|
63
64
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
64
65
  s.specification_version = 3
65
66
 
66
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
67
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
67
68
  s.add_development_dependency(%q<mocha>, [">= 0.9.5"])
68
69
  s.add_development_dependency(%q<rspec>, [">= 0"])
69
- s.add_runtime_dependency(%q<twibot>, [">= 0.1.7"])
70
+ s.add_runtime_dependency(%q<twitter_oauth>, ["~> 0.4.3"])
70
71
  s.add_runtime_dependency(%q<hpricot>, [">= 0.6.164"])
71
72
  s.add_runtime_dependency(%q<mail>, [">= 1.6.0"])
72
73
  s.add_runtime_dependency(%q<tlsmail>, [">= 0.0.1"])
73
74
  else
74
75
  s.add_dependency(%q<mocha>, [">= 0.9.5"])
75
76
  s.add_dependency(%q<rspec>, [">= 0"])
76
- s.add_dependency(%q<twibot>, [">= 0.1.7"])
77
+ s.add_dependency(%q<twitter_oauth>, ["~> 0.4.3"])
77
78
  s.add_dependency(%q<hpricot>, [">= 0.6.164"])
78
79
  s.add_dependency(%q<mail>, [">= 1.6.0"])
79
80
  s.add_dependency(%q<tlsmail>, [">= 0.0.1"])
@@ -81,7 +82,7 @@ Gem::Specification.new do |s|
81
82
  else
82
83
  s.add_dependency(%q<mocha>, [">= 0.9.5"])
83
84
  s.add_dependency(%q<rspec>, [">= 0"])
84
- s.add_dependency(%q<twibot>, [">= 0.1.7"])
85
+ s.add_dependency(%q<twitter_oauth>, ["~> 0.4.3"])
85
86
  s.add_dependency(%q<hpricot>, [">= 0.6.164"])
86
87
  s.add_dependency(%q<mail>, [">= 1.6.0"])
87
88
  s.add_dependency(%q<tlsmail>, [">= 0.0.1"])
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twuckoo
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 11
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 4
8
- - 2
9
- version: 0.4.2
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Balint Erdi
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-04-28 00:00:00 +02:00
18
+ date: 2010-09-12 00:00:00 +02:00
18
19
  default_executable: twuckoo
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: mocha
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 49
27
30
  segments:
28
31
  - 0
29
32
  - 9
@@ -35,35 +38,41 @@ dependencies:
35
38
  name: rspec
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 3
41
46
  segments:
42
47
  - 0
43
48
  version: "0"
44
49
  type: :development
45
50
  version_requirements: *id002
46
51
  - !ruby/object:Gem::Dependency
47
- name: twibot
52
+ name: twitter_oauth
48
53
  prerelease: false
49
54
  requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
50
56
  requirements:
51
- - - ">="
57
+ - - ~>
52
58
  - !ruby/object:Gem::Version
59
+ hash: 9
53
60
  segments:
54
61
  - 0
55
- - 1
56
- - 7
57
- version: 0.1.7
62
+ - 4
63
+ - 3
64
+ version: 0.4.3
58
65
  type: :runtime
59
66
  version_requirements: *id003
60
67
  - !ruby/object:Gem::Dependency
61
68
  name: hpricot
62
69
  prerelease: false
63
70
  requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
64
72
  requirements:
65
73
  - - ">="
66
74
  - !ruby/object:Gem::Version
75
+ hash: 335
67
76
  segments:
68
77
  - 0
69
78
  - 6
@@ -75,9 +84,11 @@ dependencies:
75
84
  name: mail
76
85
  prerelease: false
77
86
  requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
78
88
  requirements:
79
89
  - - ">="
80
90
  - !ruby/object:Gem::Version
91
+ hash: 15
81
92
  segments:
82
93
  - 1
83
94
  - 6
@@ -89,9 +100,11 @@ dependencies:
89
100
  name: tlsmail
90
101
  prerelease: false
91
102
  requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
92
104
  requirements:
93
105
  - - ">="
94
106
  - !ruby/object:Gem::Version
107
+ hash: 29
95
108
  segments:
96
109
  - 0
97
110
  - 0
@@ -124,6 +137,7 @@ files:
124
137
  - lib/twuckoo.rb
125
138
  - lib/twuckoo/config.rb
126
139
  - lib/twuckoo/runner.rb
140
+ - lib/twuckoo/twitter_oauth_module.rb
127
141
  - spec/duration_string_spec.rb
128
142
  - spec/one_line_from_file_spec.rb
129
143
  - spec/spec.opts
@@ -143,23 +157,27 @@ rdoc_options:
143
157
  require_paths:
144
158
  - lib
145
159
  required_ruby_version: !ruby/object:Gem::Requirement
160
+ none: false
146
161
  requirements:
147
162
  - - ">="
148
163
  - !ruby/object:Gem::Version
164
+ hash: 3
149
165
  segments:
150
166
  - 0
151
167
  version: "0"
152
168
  required_rubygems_version: !ruby/object:Gem::Requirement
169
+ none: false
153
170
  requirements:
154
171
  - - ">="
155
172
  - !ruby/object:Gem::Version
173
+ hash: 3
156
174
  segments:
157
175
  - 0
158
176
  version: "0"
159
177
  requirements: []
160
178
 
161
179
  rubyforge_project:
162
- rubygems_version: 1.3.6
180
+ rubygems_version: 1.3.7
163
181
  signing_key:
164
182
  specification_version: 3
165
183
  summary: Need to tweet periodically in an automated fashion? Then Twuckoo is for you!