twpipe 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/twpipe CHANGED
@@ -29,6 +29,7 @@ Options:
29
29
  EOF
30
30
 
31
31
  opt.on('-c CONFIG_FILE', '--config CONFIG_FILE', 'path to configuration file') {|v| options['config_path'] = File.expand_path(v) }
32
+ opt.on('-e [PREFIX]', '--echo-back [PREFIX]', 'echo back your tweet with prefix.') {|v| options['echo_back_with_prefix'] = v }
32
33
 
33
34
  opt.permute!
34
35
  end
@@ -45,7 +46,10 @@ end
45
46
  begin
46
47
  Twpipe.config_path = options['config_path'] if options['config_path']
47
48
  pipe = Twpipe.new
48
- pipe.tweet(message)
49
+ tweet = pipe.tweet(message)
50
+ if options['echo_back_with_prefix']
51
+ puts "%s%s" % [options['echo_back_with_prefix'], tweet]
52
+ end
49
53
  rescue Twpipe::ConfigError => e
50
54
  puts e.message
51
55
  end
@@ -5,6 +5,8 @@ require 'twpipe/version'
5
5
  # == Twpipe
6
6
  #
7
7
  class Twpipe
8
+ MAX_TWEET_LENGTH = 140
9
+
8
10
  class ConfigError < Exception; end
9
11
 
10
12
  class << self
@@ -28,8 +30,12 @@ class Twpipe
28
30
  #
29
31
  # message: string variable that you would tweet
30
32
  #
33
+ # return:
34
+ # * message that truncated first MAX_TWEET_LENGTH characters
35
+ #
31
36
  def tweet(message)
32
37
  @client.update(message)
38
+ message.split(//).first(MAX_TWEET_LENGTH).join
33
39
  end
34
40
 
35
41
  private
@@ -1,3 +1,3 @@
1
1
  class Twpipe
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -67,10 +67,11 @@ EOF
67
67
  let(:twitter) { mock('Twitter:Base') }
68
68
 
69
69
  it 'should receive Twitter::Base#update' do
70
+ message = 'a' * 141
70
71
  Twpipe.config_path = File.join(File.dirname(__FILE__), '../data/config/valid.yml')
71
72
  twpipe = Twpipe.new
72
- twpipe.instance_variable_get(:@client).should_receive(:update).with('message')
73
- twpipe.tweet('message')
73
+ twpipe.instance_variable_get(:@client).should_receive(:update).with(message)
74
+ twpipe.tweet(message).should == 'a' * 140
74
75
  end
75
76
  end
76
77
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{twpipe}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["koshigoe"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twpipe
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - koshigoe