twuckoo 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -6,4 +6,6 @@ vendor/gems/ruby/**/gems
6
6
  vendor/gems/ruby/**/specifications
7
7
  vendor/gems/ruby/**/doc
8
8
  vendor/gems/ruby/**/environment.rb
9
- mail_proba.rb
9
+ mail_proba.rb
10
+ optparse_proba.rb
11
+ super_proba.rb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/bin/twuckoo CHANGED
@@ -1,25 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  dir = File.join(File.dirname(__FILE__), '..', 'lib')
4
-
5
4
  require File.join(dir, 'twuckoo')
6
5
 
7
- Dir.glob(File.join(dir, 'modules', '*.rb')).each do |mod|
8
- require mod
9
- end
10
-
11
- module_to_include = case ARGV.first.downcase
12
- when "from_file"
13
- OneLineFromFile
14
- when "file"
15
- OneLineFromFile
16
- when "wikipedia_tfa"
17
- WikipediaTFA
18
- else
19
- raise "No module to include was provided."
20
- end
21
-
22
- Twuckoo::Runner.send(:include, module_to_include)
23
- @runner = Twuckoo::Runner.new
24
- # @cuckoo.set_testing
6
+ @runner = Twuckoo::Runner.new(ARGV)
7
+ # @runner.set_testing
25
8
  @runner.run
@@ -9,7 +9,7 @@ module OneLineFromFile
9
9
  LINES_FILE = 'lines.txt'
10
10
  USED_LINES_FILE = 'used_lines.txt'
11
11
 
12
- def initialize
12
+ def initialize(args=[])
13
13
  @lines = []
14
14
  # load_lines
15
15
  end
@@ -5,6 +5,8 @@ require "hpricot"
5
5
  module WikipediaTFA
6
6
 
7
7
  WIKIPEDIA_HOST = "http://en.wikipedia.org"
8
+ def initialize(args=[])
9
+ end
8
10
 
9
11
  def load_tweets
10
12
  end
@@ -1,8 +1,15 @@
1
+ require "optparse"
2
+ require "ostruct"
3
+
4
+ class TwuckooException < Exception
5
+ end
6
+
1
7
  class Twuckoo::Runner
2
8
  # the idea is to include a module with a well-defined API with three methods:
3
9
  # - load_tweets
4
10
  # - next
5
11
  # - store(tweet)
12
+ attr_reader :used_module
6
13
 
7
14
  def run
8
15
  setup_from_file
@@ -16,10 +23,45 @@ class Twuckoo::Runner
16
23
  end
17
24
  end
18
25
 
19
- def initialize
26
+ def initialize(args=[])
27
+ @options = OpenStruct.new
28
+ parse_options!(args)
29
+
30
+ _module = args.pop
31
+ use_module(get_module(_module))
20
32
  super
21
33
  end
22
34
 
35
+ def parse_options!(args)
36
+ opts = OptionParser.new do |opts|
37
+ opts.banner = "Usage: twuckoo [options] module_to_use"
38
+ opts.on("-n name", "--name name",
39
+ "name will be the name of this twuckoo instance (used for email notifs)") do |name|
40
+ @options.name = name
41
+ end
42
+ opts.on_tail("-h", "--help", "Show this message") do
43
+ puts opts
44
+ exit
45
+ end
46
+ end
47
+
48
+ if args.length.zero?
49
+ puts opts.banner
50
+ exit
51
+ end
52
+
53
+ # opts.on_tail("--version", "Show version") do
54
+ # File.read(...)
55
+ # exit
56
+ # end
57
+
58
+ opts.parse!(args)
59
+ end
60
+
61
+ def name
62
+ @options.name || File.split(File.dirname(__FILE__)).last
63
+ end
64
+
23
65
  def wait_between_tweets?
24
66
  config[:time_to_sleep] != "0"
25
67
  end
@@ -32,10 +74,6 @@ class Twuckoo::Runner
32
74
  def notify
33
75
  send_email(config)
34
76
  end
35
-
36
- def config
37
- @config ||= ::Twuckoo::Config.new
38
- end
39
77
 
40
78
  def tweet(message)
41
79
  unless message.nil? or message.empty?
@@ -45,6 +83,10 @@ class Twuckoo::Runner
45
83
  message
46
84
  end
47
85
 
86
+ def config
87
+ @config ||= ::Twuckoo::Config.new
88
+ end
89
+
48
90
  def get_config_values_from_file(file='config/cuckoo.yml')
49
91
  begin
50
92
  open(file, 'r') do |f|
@@ -68,6 +110,24 @@ class Twuckoo::Runner
68
110
  end
69
111
 
70
112
  private
113
+ def get_module(module_id)
114
+ case module_id
115
+ when "file"
116
+ OneLineFromFile
117
+ when "from_file"
118
+ OneLineFromFile
119
+ when "wikipedia_tfa"
120
+ WikipediaTFA
121
+ else
122
+ raise TwuckooException, "Invalid module: #{module_id.inspect}"
123
+ end
124
+ end
125
+
126
+ def use_module(_module)
127
+ @used_module = _module
128
+ self.class.class_eval { include _module }
129
+ end
130
+
71
131
  def send_tweet(message)
72
132
  twitter.status(:post, message)
73
133
  end
@@ -2,8 +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::Runner.send(:include, OneLineFromFile)
6
- @twuckoo = Twuckoo::Runner.new
5
+ @twuckoo = Twuckoo::Runner.new(["file"])
7
6
  # just so that no files will be written
8
7
  @twuckoo.stubs(:store).returns(nil)
9
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.new
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
@@ -36,6 +36,21 @@ describe Twuckoo::Runner do
36
36
  @twuckoo.config[:time_to_sleep].should == "3m"
37
37
  end
38
38
 
39
+ it "should receive the module to use as the last parameter" do
40
+ runner = Twuckoo::Runner.new(%w[file])
41
+ runner.used_module.should == OneLineFromFile
42
+ end
43
+
44
+ it "name can be given through the -n option" do
45
+ runner = Twuckoo::Runner.new(%w[-n pragthinklearn file])
46
+ runner.name.should == "pragthinklearn"
47
+ end
48
+
49
+ it "if no is given, the directory name is used" do
50
+ runner = Twuckoo::Runner.new(%w[file])
51
+ runner.name.should == "twuckoo"
52
+ end
53
+
39
54
  describe "loading values from the config file" do
40
55
  it "sets the time interval to wait b/w tweets correctly" do
41
56
  @twuckoo.expects(:get_config_values_from_file).returns({ :time_to_sleep => "3m" })
@@ -2,8 +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::Runner.send(:include, WikipediaTFA)
6
- @twuckoo = Twuckoo::Runner.new
5
+ @twuckoo = Twuckoo::Runner.new(["wikipedia_tfa"])
7
6
  @twuckoo.setup do |config|
8
7
  config[:time_to_sleep] = "0"
9
8
  end
data/twuckoo.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{twuckoo}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
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-01-12}
12
+ s.date = %q{2010-01-13}
13
13
  s.description = %q{ A simple yet elegant solution to tweet a message regularly from a file (from a webpage, a database, etc.)
14
14
  }
15
15
  s.email = %q{balint.erdi@gmail.com}
@@ -26,7 +26,9 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "bin/edit_json.rb",
29
+ "bin/jeweler",
29
30
  "bin/prettify_json.rb",
31
+ "bin/rubyforge",
30
32
  "bin/t4rsh",
31
33
  "bin/twuckoo",
32
34
  "lib/duration_string.rb",
@@ -48,11 +50,17 @@ Gem::Specification.new do |s|
48
50
  "twuckoo.gemspec",
49
51
  "vendor/gems/environment.rb",
50
52
  "vendor/gems/ruby/1.8/cache/activesupport-2.3.5.gem",
53
+ "vendor/gems/ruby/1.8/cache/gemcutter-0.3.0.gem",
54
+ "vendor/gems/ruby/1.8/cache/git-1.2.5.gem",
51
55
  "vendor/gems/ruby/1.8/cache/hpricot-0.8.2.gem",
56
+ "vendor/gems/ruby/1.8/cache/jeweler-1.4.0.gem",
52
57
  "vendor/gems/ruby/1.8/cache/json-1.2.0.gem",
58
+ "vendor/gems/ruby/1.8/cache/json_pure-1.2.0.gem",
53
59
  "vendor/gems/ruby/1.8/cache/mail-1.5.2.gem",
60
+ "vendor/gems/ruby/1.8/cache/mail-1.5.3.gem",
54
61
  "vendor/gems/ruby/1.8/cache/mbbx6spp-twitter4r-0.4.0.gem",
55
62
  "vendor/gems/ruby/1.8/cache/mime-types-1.16.gem",
63
+ "vendor/gems/ruby/1.8/cache/rubyforge-2.0.3.gem",
56
64
  "vendor/gems/ruby/1.8/cache/twibot-0.1.7.gem"
57
65
  ]
58
66
  s.homepage = %q{http://github.com/balinterdi/twuckoo}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twuckoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Balint Erdi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-12 00:00:00 +01:00
12
+ date: 2010-01-13 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -35,7 +35,9 @@ files:
35
35
  - Rakefile
36
36
  - VERSION
37
37
  - bin/edit_json.rb
38
+ - bin/jeweler
38
39
  - bin/prettify_json.rb
40
+ - bin/rubyforge
39
41
  - bin/t4rsh
40
42
  - bin/twuckoo
41
43
  - lib/duration_string.rb
@@ -57,11 +59,17 @@ files:
57
59
  - twuckoo.gemspec
58
60
  - vendor/gems/environment.rb
59
61
  - vendor/gems/ruby/1.8/cache/activesupport-2.3.5.gem
62
+ - vendor/gems/ruby/1.8/cache/gemcutter-0.3.0.gem
63
+ - vendor/gems/ruby/1.8/cache/git-1.2.5.gem
60
64
  - vendor/gems/ruby/1.8/cache/hpricot-0.8.2.gem
65
+ - vendor/gems/ruby/1.8/cache/jeweler-1.4.0.gem
61
66
  - vendor/gems/ruby/1.8/cache/json-1.2.0.gem
67
+ - vendor/gems/ruby/1.8/cache/json_pure-1.2.0.gem
62
68
  - vendor/gems/ruby/1.8/cache/mail-1.5.2.gem
69
+ - vendor/gems/ruby/1.8/cache/mail-1.5.3.gem
63
70
  - vendor/gems/ruby/1.8/cache/mbbx6spp-twitter4r-0.4.0.gem
64
71
  - vendor/gems/ruby/1.8/cache/mime-types-1.16.gem
72
+ - vendor/gems/ruby/1.8/cache/rubyforge-2.0.3.gem
65
73
  - vendor/gems/ruby/1.8/cache/twibot-0.1.7.gem
66
74
  has_rdoc: true
67
75
  homepage: http://github.com/balinterdi/twuckoo