kdaigle-roast 0.0.5 → 0.0.6

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.
Files changed (4) hide show
  1. data/VERSION.yml +1 -1
  2. data/bin/roast +1 -1
  3. data/lib/roast/main.rb +46 -29
  4. metadata +2 -2
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 5
4
+ :patch: 6
data/bin/roast CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require "roast"
4
4
 
5
- Roast::Main.run
5
+ Roast::Main.run(:message => (ARGV[0] || STDIN.read) )
data/lib/roast/main.rb CHANGED
@@ -1,16 +1,25 @@
1
1
  module Roast
2
2
 
3
3
  class Main
4
-
5
4
  include Tinder
6
5
 
7
- def self.run(first_msg=nil, room=nil)
8
-
9
- config_file = YAML.load_file(ENV['HOME'] + '/roast.yml')
10
-
11
- options = Hash.new
12
- options[:room] = (room ? room.to_s : nil) || config_file["default"]
13
-
6
+ attr_accessor :message, :room, :config, :domain, :ssl, :username, :password, :verbose
7
+
8
+ def initialize(options)
9
+ @message = options[:message]
10
+ @config = YAML.load_file(ENV['HOME'] + '/roast.yml')
11
+ room_config = @config[(options[:room] ? options[:room].to_s : @config["default"])]
12
+ @room = room_config['room']
13
+ @domain = room_config['domain']
14
+ @ssl = room_config['ssl']
15
+ @username = room_config['username']
16
+ @password = room_config['password']
17
+ @verbose = options[:verbose]
18
+ self
19
+ end
20
+
21
+ def self.run(options={})
22
+
14
23
  opts = OptionParser.new do |opt|
15
24
  opt.banner = "Usage: roast [options] message"
16
25
  opt.separator ""
@@ -20,44 +29,52 @@ module Roast
20
29
  "Room name from config") do |room|
21
30
  options[:room] = room
22
31
  end
32
+ opt.on("-v", "--verbose",
33
+ "Be verbose during the posting of the message") do |verbose|
34
+ options[:verbose] = true
35
+ end
23
36
  end
24
37
 
25
38
  opts.parse!(ARGV)
26
39
 
27
- puts options.inspect
28
-
29
- conf = config_file[options[:room]]
30
-
31
- msg = first_msg || ARGV[0] || STDIN.read
40
+ roast = Roast::Main.new(options)
32
41
 
33
- puts "Using #{conf['room']} configuration ..."
42
+ roast.vocalize "Using #{roast.room} configuration ..."
34
43
 
35
- campfire = Campfire.new(conf['domain'], :ssl => conf['ssl'])
44
+ campfire = Campfire.new(roast.domain, :ssl => roast.ssl)
36
45
 
37
- puts "Logging in..."
38
- campfire.login conf['username'], conf['password']
39
- puts "Logged in!"
46
+ roast.vocalize "Logging in..."
47
+ campfire.login(roast.username, roast.password)
48
+ roast.vocalize "Logged in!"
40
49
 
41
- room = campfire.find_room_by_name conf["room"]
50
+ room = campfire.find_room_by_name(roast.room)
42
51
 
43
- puts "Joining #{room.name}..."
44
- # room.join(true)
45
- puts "Entered room #{room.name}"
52
+ roast.vocalize "Joining #{room.name}..."
53
+ roast.vocalize "Entered room #{room.name}"
46
54
 
47
- puts "Saying message..."
55
+ roast.vocalize "Saying message..."
48
56
 
49
- if msg.split("\n").size > 1
50
- room.paste(msg)
57
+ if message_long?(options[:message])
58
+ room.paste(options[:message])
51
59
  else
52
- room.speak(msg)
60
+ room.speak(options[:message])
53
61
  end
54
62
 
55
- puts "Leaving room..."
63
+ roast.vocalize "Leaving room..."
56
64
 
57
- # room.leave
65
+ roast.vocalize "Done."
66
+ end
67
+
68
+ def vocalize(message)
69
+ STDOUT.puts message if self.verbose
70
+ end
71
+
72
+ private
58
73
 
59
- puts "Done."
74
+ def self.message_long?(message)
75
+ (message.split("\n").size > 1) || (message.size >= 255)
60
76
  end
77
+
61
78
  end
62
79
 
63
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kdaigle-roast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Daigle
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-13 00:00:00 -07:00
12
+ date: 2009-06-15 00:00:00 -07:00
13
13
  default_executable: roast
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency