tw 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ gem 'hoe'
4
4
  gem 'newgem'
5
5
  gem 'oauth'
6
6
  gem 'twitter'
7
+ gem 'twitter-text'
7
8
  gem 'userstream'
8
9
  gem 'json'
9
10
  gem 'rainbow'
data/Gemfile.lock CHANGED
@@ -32,6 +32,8 @@ GEM
32
32
  faraday (~> 0.8)
33
33
  multi_json (~> 1.3)
34
34
  simple_oauth (~> 0.1.6)
35
+ twitter-text (1.5.0)
36
+ activesupport
35
37
  userstream (1.2.2)
36
38
  hashie (~> 1.2.0)
37
39
  oauth (~> 0.4.6)
@@ -49,4 +51,5 @@ DEPENDENCIES
49
51
  parallel
50
52
  rainbow
51
53
  twitter
54
+ twitter-text
52
55
  userstream
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.3.3 2012-10-18
2
+
3
+ * count 140 chars with t.co
4
+
1
5
  === 0.3.2 2012-10-11
2
6
 
3
7
  * set config file permission 600
data/Manifest.txt CHANGED
@@ -13,6 +13,7 @@ lib/tw/app/opt_parser.rb
13
13
  lib/tw/app/render.rb
14
14
  lib/tw/client/auth.rb
15
15
  lib/tw/client/error.rb
16
+ lib/tw/client/helper.rb
16
17
  lib/tw/client/request.rb
17
18
  lib/tw/client/stream.rb
18
19
  lib/tw/client/tweet.rb
@@ -24,4 +25,5 @@ script/console
24
25
  script/destroy
25
26
  script/generate
26
27
  test/test_helper.rb
28
+ test/test_t_co.rb
27
29
  test/test_tw.rb
data/Rakefile CHANGED
@@ -16,6 +16,7 @@ $hoe = Hoe.spec 'tw' do
16
16
  self.rubyforge_name = self.name # TODO this is default value
17
17
  self.extra_deps = [['oauth','>= 0.4.7', '< 1.0.0'],
18
18
  ['twitter', '>= 4.0.0', '< 5.0.0'],
19
+ ['twitter', '>= 1.5.0', '< 2.0.0'],
19
20
  ['userstream', '>= 1.2.0', '< 1.3.0'],
20
21
  ['json', '>= 1.7.5', '< 1.8.0'],
21
22
  ['args_parser', '>= 0.1.2'],
data/lib/tw.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
+ $KCODE = 'u' if RUBY_VERSION < '1.9'
4
5
  require 'oauth'
5
6
  require 'twitter'
7
+ require 'twitter-text'
6
8
  require 'time'
7
9
  require 'user_stream'
8
10
  require 'yaml'
@@ -18,9 +20,10 @@ require 'tw/client/request'
18
20
  require 'tw/client/tweet'
19
21
  require 'tw/client/stream'
20
22
  require 'tw/client/error'
23
+ require 'tw/client/helper'
21
24
 
22
25
  module Tw
23
- VERSION = '0.3.2'
26
+ VERSION = '0.3.3'
24
27
  class Conf
25
28
  REQUIRE_VERSION = '0.1.0'
26
29
  end
data/lib/tw/app/cmds.rb CHANGED
@@ -53,7 +53,7 @@ module Tw::App
53
53
  cmd 'dm:to' do |to, opts|
54
54
  unless opts[:pipe]
55
55
  message = @parser.argv.join(' ')
56
- len = message.split(//u).size
56
+ len = message.char_length_with_t_co
57
57
  if len > 140
58
58
  STDERR.puts "message too long (#{len} chars)"
59
59
  on_error
data/lib/tw/app/main.rb CHANGED
@@ -113,7 +113,7 @@ module Tw::App
113
113
  }, @parser[:format]
114
114
  else
115
115
  message = @parser.argv.join(' ')
116
- if (len = message.split(//u).size) > 140
116
+ if (len = message.char_length_with_t_co) > 140
117
117
  STDERR.puts "tweet too long (#{len} chars)"
118
118
  on_error
119
119
  else
@@ -0,0 +1,11 @@
1
+
2
+ class String
3
+ def char_length_with_t_co
4
+ Tw::Conf.update_twitter_config
5
+ len = self.char_length
6
+ Twitter::Extractor.extract_urls(self).each do |url|
7
+ len += (url =~ /^https/ ? Tw::Conf['twitter_config']['short_url_length_https'] : Tw::Conf['twitter_config']['short_url_length']) - url.char_length
8
+ end
9
+ len
10
+ end
11
+ end
data/lib/tw/conf.rb CHANGED
@@ -60,6 +60,19 @@ module Tw
60
60
  end
61
61
  end
62
62
 
63
+ def self.update_twitter_config(force_update=false)
64
+ if self['twitter_config'].kind_of? Hash and
65
+ self['twitter_config']['last_updated_at']+60*60*24 > Time.now.to_i and
66
+ !force_update
67
+ return
68
+ end
69
+ self['twitter_config'] = {}
70
+ self['twitter_config']['short_url_length'] = Twitter::configuration.short_url_length
71
+ self['twitter_config']['short_url_length_https'] = Twitter::configuration.short_url_length_https
72
+ self['twitter_config']['last_updated_at'] = Time.now.to_i
73
+ self.save
74
+ end
75
+
63
76
  private
64
77
  def self.open_conf_file(opt=nil, &block)
65
78
  if block_given?
data/test/test_t_co.rb ADDED
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/test_helper.rb'
3
+
4
+ class TestTCo < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @client = Tw::Client.new
8
+ @client.auth
9
+ end
10
+
11
+ def test_t_co_char_length
12
+ msg = "blog書いた → http://shokai.org/blog/archives/6513"
13
+ assert msg.char_length > msg.char_length_with_t_co
14
+ end
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-11 00:00:00.000000000 Z
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth
@@ -233,6 +233,7 @@ files:
233
233
  - lib/tw/app/render.rb
234
234
  - lib/tw/client/auth.rb
235
235
  - lib/tw/client/error.rb
236
+ - lib/tw/client/helper.rb
236
237
  - lib/tw/client/request.rb
237
238
  - lib/tw/client/stream.rb
238
239
  - lib/tw/client/tweet.rb
@@ -244,6 +245,7 @@ files:
244
245
  - script/destroy
245
246
  - script/generate
246
247
  - test/test_helper.rb
248
+ - test/test_t_co.rb
247
249
  - test/test_tw.rb
248
250
  - .gemtest
249
251
  homepage: http://shokai.github.com/tw
@@ -262,7 +264,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
262
264
  version: '0'
263
265
  segments:
264
266
  - 0
265
- hash: -2371504449230392816
267
+ hash: 1015519835812409521
266
268
  required_rubygems_version: !ruby/object:Gem::Requirement
267
269
  none: false
268
270
  requirements:
@@ -277,4 +279,5 @@ specification_version: 3
277
279
  summary: ! '* twitter client.'
278
280
  test_files:
279
281
  - test/test_helper.rb
282
+ - test/test_t_co.rb
280
283
  - test/test_tw.rb