kimotter 0.1.0 → 0.1.1

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 (2) hide show
  1. data/lib/kimotter_cli.rb +62 -0
  2. metadata +3 -2
@@ -0,0 +1,62 @@
1
+ require 'kimotter'
2
+
3
+ module KimotterCLI
4
+ def self.execute(options={})
5
+ parser = OptionParser.new{ |opts|
6
+ opts.banner = "Usage: #{File.basename($0)} [options] [tweet_message]"
7
+ opts.on("-d", "--debug", "Debug Mode"){ |v|
8
+ options[:debug_mode] = true
9
+ }
10
+ opts.on("-f", "--force", "Force execute, ignore api limit"){ |v|
11
+ options[:force_execute] = true
12
+ }
13
+ opts.on("-a", "--api=URL", "API Endpoint URL"){ |url|
14
+ options[:api_endpoint] = url
15
+ }
16
+ }
17
+ parser.parse!
18
+
19
+ message = ARGV.shift
20
+ unless message
21
+ file = Tempfile.new('foo')
22
+ file.close
23
+
24
+ unless system(ENV['EDITOR'], file.path)
25
+ raise "system command aborted"
26
+ end
27
+ message = File.read(file.path).chomp.gsub(/\n/, " ")
28
+ end
29
+
30
+ if message.empty?
31
+ raise "please input message"
32
+ end
33
+
34
+ logger = options[:debug_mode] ? Logger.new(STDERR) : Logger.new(nil)
35
+ api = options[:api_endpoint] || "http://api.ma.la/twitter/"
36
+ kimotter = Kimotter.new(:api => api, :logger => logger)
37
+
38
+ kimotter.fetch_api_limit
39
+ if !options[:force_execute] and kimotter.api_limit?
40
+ puts "u cant use this api now(api limit)"
41
+ puts "try again later or retry with --force option (ignore API limit)"
42
+ exit(1)
43
+ end
44
+
45
+ print kimotter.confirm_msg + "[y/N] "
46
+ if user_input_line = $stdin.gets
47
+ if user_input_line =~ /^(yes|y)$/i
48
+ puts "hi kimoto. try to tweet your cool message"
49
+ kimotter.tweet(message)
50
+ puts "done!"
51
+ exit(0)
52
+ else
53
+ puts "your tweet went to hell on earth. god damn it"
54
+ exit(3)
55
+ end
56
+ else
57
+ puts "omg?"
58
+ exit(2)
59
+ end
60
+ end
61
+ end
62
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - kimoto
@@ -76,6 +76,7 @@ files:
76
76
  - bin/kimotter
77
77
  - bin/koiketter
78
78
  - lib/kimotter.rb
79
+ - lib/kimotter_cli.rb
79
80
  - test/kimotter_test.rb
80
81
  - test/test_helper.rb
81
82
  has_rdoc: true