tuomas-tweetwine 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.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.1.1 released 2009-04-23
2
+
3
+ * Renamed command "msg" to "update".
4
+ * If status update if longer than 140 characters, warn about it.
5
+
1
6
  === 0.1.0 released 2009-04-22
2
7
 
3
8
  * Initial release with minimal functionality.
data/README.rdoc CHANGED
@@ -23,9 +23,9 @@ read the configuration file for authentication.
23
23
 
24
24
  The supported commands are
25
25
 
26
- <tt>friends</tt>:: Fetch friends' statuses (the contents of the user's home).
27
- <tt>user [name]</tt>:: Fetch a specific user's statuses, identified by the argument; if given no argument, fetch your own statuses.
28
- <tt>msg [status]</tt>:: Send a status update, but confirm the action first before actually sending. The status update can either be given as an argument or via STDIN if no argument is given.
26
+ <tt>friends</tt>:: Fetch friends' latest statuses (the contents of the user's home).
27
+ <tt>user [name]</tt>:: Fetch a specific user's latest statuses, identified by the argument; if given no argument, fetch your own statuses.
28
+ <tt>update [status]</tt>:: Send a status update, but confirm the action first before actually sending. The status update can either be given as an argument or via STDIN if no argument is given.
29
29
 
30
30
  If <tt>[command]</tt> is not given, it defaults to <tt>friends</tt>.
31
31
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require "rubygems"
2
2
 
3
3
  full_name = "Tweetwine"
4
4
  package_name = "tweetwine"
5
- version = "0.1.0"
5
+ version = "0.1.1"
6
6
 
7
7
  require "lib/#{package_name}"
8
8
 
data/bin/tweetwine CHANGED
@@ -37,8 +37,8 @@ Usage: tweetwine [options...] [command]
37
37
  -a, --auth <username>:<password> Authentication data.
38
38
  -c, --color Colorize output with ANSI escape codes.
39
39
  -h, --help This help message.
40
- -n, --num <num> The number of statuses to show, defaults
41
- to #{DEFAULT_OPTIONS[:num_statuses]}.
40
+ -n, --num <num> The number of statuses to fetch,
41
+ defaults to #{DEFAULT_OPTIONS[:num_statuses]}.
42
42
 
43
43
  END
44
44
  exit(1)
@@ -5,7 +5,7 @@ module Tweetwine
5
5
  class ClientError < RuntimeError; end
6
6
 
7
7
  class Client
8
- COMMANDS = %w{friends user msg}
8
+ COMMANDS = %w{friends user update}
9
9
 
10
10
  MAX_NUM_STATUSES = 20
11
11
  MAX_STATUS_LENGTH = 140
@@ -15,29 +15,29 @@ module Tweetwine
15
15
  @base_url = "https://#{@username}:#{password}@twitter.com/"
16
16
  @colorize = options[:colorize] || false
17
17
  @num_statuses = options[:num_statuses] || MAX_NUM_STATUSES
18
+ @io = IO.new(options)
18
19
  end
19
20
 
20
21
  def friends
21
- print_statuses JSON.parse(get("statuses/friends_timeline.json?count=#{@num_statuses}"))
22
+ @io.show_statuses JSON.parse(get("statuses/friends_timeline.json?count=#{@num_statuses}"))
22
23
  end
23
24
 
24
25
  def user(user = @username)
25
- print_statuses JSON.parse(get("statuses/user_timeline/#{user}.json?count=#{@num_statuses}"))
26
+ @io.show_statuses JSON.parse(get("statuses/user_timeline/#{user}.json?count=#{@num_statuses}"))
26
27
  end
27
28
 
28
- def msg(status = nil)
29
- unless status
30
- printf "New status: "
31
- status = $stdin.gets
29
+ def update(new_status = nil)
30
+ new_status = @io.prompt("Status update") unless new_status
31
+ if new_status.length > MAX_STATUS_LENGTH
32
+ new_status = new_status[0...MAX_STATUS_LENGTH]
33
+ @io.warn("Update will be truncated: #{new_status}")
32
34
  end
33
- if confirm_user_action("Really send?")
34
- msg = status[0...MAX_STATUS_LENGTH]
35
- body = {:status => msg }
36
- status = JSON.parse(post("statuses/update.json", body))
37
- puts "Sent status update.\n\n"
38
- print_statuses([status])
35
+ if @io.confirm("Really send?")
36
+ status = JSON.parse(post("statuses/update.json", {:status => new_status}))
37
+ @io.info "Sent status update.\n\n"
38
+ @io.show_statuses([status])
39
39
  else
40
- puts "Cancelled."
40
+ @io.info "Cancelled."
41
41
  end
42
42
  end
43
43
 
@@ -56,26 +56,5 @@ module Tweetwine
56
56
  rescue RestClient::Exception => e
57
57
  raise ClientError, e.message
58
58
  end
59
-
60
- def confirm_user_action(msg)
61
- printf "#{msg} [yN] "
62
- confirmation = $stdin.gets.strip
63
- confirmation.downcase[0,1] == "y"
64
- end
65
-
66
- def print_statuses(statuses)
67
- statuses.each do |status|
68
- time_diff_value, time_diff_unit = Util.humanize_time_diff(Time.now, status["created_at"])
69
- from_user = status["user"]["screen_name"]
70
- from_user = Util.colorize(:green, from_user) if @colorize
71
- text = status["text"]
72
- text = Util.colorize(:red, text, /@\w+/) if @colorize
73
- puts <<-END
74
- #{from_user}, #{time_diff_value} #{time_diff_unit} ago:
75
- #{text}
76
-
77
- END
78
- end
79
- end
80
59
  end
81
60
  end
@@ -0,0 +1,65 @@
1
+ module Tweetwine
2
+ class IO
3
+ def initialize(options)
4
+ @input = options[:input] || $stdin
5
+ @output = options[:output] || $stdout
6
+ @colorize = options[:colorize] || false
7
+ end
8
+
9
+ def prompt(prompt)
10
+ @output.print "#{prompt}: "
11
+ @input.gets.strip!
12
+ end
13
+
14
+ def info(msg)
15
+ @output.puts(msg)
16
+ end
17
+
18
+ def warn(msg)
19
+ @output.puts "Warning: #{msg}"
20
+ end
21
+
22
+ def confirm(msg)
23
+ @output.print "#{msg} [yN] "
24
+ confirmation = @input.gets.strip
25
+ confirmation.downcase[0,1] == "y"
26
+ end
27
+
28
+ def show_statuses(statuses)
29
+ statuses.each do |status|
30
+ time_diff_value, time_diff_unit = Util.humanize_time_diff(Time.now, status["created_at"])
31
+ from_user = status["user"]["screen_name"]
32
+ from_user = colorize(:green, from_user) if @colorize
33
+ text = status["text"]
34
+ text = colorize(:red, text, /@\w+/) if @colorize
35
+ @output.puts <<-END
36
+ #{from_user}, #{time_diff_value} #{time_diff_unit} ago:
37
+ #{text}
38
+
39
+ END
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ COLOR_CODES = {
46
+ :green => "\033[32m",
47
+ :red => "\033[31m",
48
+ :neutral => "\033[0m"
49
+ }
50
+
51
+ def colorize(color, str, matcher = nil)
52
+ color_code = COLOR_CODES[color.to_sym]
53
+
54
+ unless matcher
55
+ colorize_str(color_code, str)
56
+ else
57
+ str.gsub(matcher) { |s| colorize_str(color_code, s) }
58
+ end
59
+ end
60
+
61
+ def colorize_str(color_code, str)
62
+ "#{color_code}#{str}#{COLOR_CODES[:neutral]}"
63
+ end
64
+ end
65
+ end
@@ -2,21 +2,6 @@ require "time"
2
2
 
3
3
  module Tweetwine
4
4
  module Util
5
- COLOR_CODES = {
6
- :green => "\033[32m",
7
- :red => "\033[31m"
8
- }
9
-
10
- def self.colorize(color, str, matcher = nil)
11
- color_code = COLOR_CODES[color.to_sym]
12
-
13
- unless matcher
14
- colorize_str(color_code, str)
15
- else
16
- str.gsub(matcher) { |s| colorize_str(color_code, s) }
17
- end
18
- end
19
-
20
5
  def self.humanize_time_diff(from, to)
21
6
  from = Time.parse(from.to_s) unless from.is_a? Time
22
7
  to = Time.parse(to.to_s) unless to.is_a? Time
@@ -35,10 +20,6 @@ module Tweetwine
35
20
 
36
21
  private
37
22
 
38
- def self.colorize_str(color_code, str)
39
- "#{color_code}#{str}\033[0m"
40
- end
41
-
42
23
  def self.pluralize_unit(value, unit)
43
24
  if ["hour", "day"].include?(unit) && value > 1
44
25
  unit = unit + "s"
data/lib/tweetwine.rb CHANGED
@@ -1,3 +1,3 @@
1
- %w{util config client}.each do |f|
1
+ %w{util config io client}.each do |f|
2
2
  require File.dirname(__FILE__) << "/tweetwine/#{f}"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tuomas-tweetwine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tuomas Kareinen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-22 00:00:00 -07:00
12
+ date: 2009-04-23 00:00:00 -07:00
13
13
  default_executable: tweetwine
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -49,6 +49,7 @@ files:
49
49
  - lib/tweetwine
50
50
  - lib/tweetwine/client.rb
51
51
  - lib/tweetwine/config.rb
52
+ - lib/tweetwine/io.rb
52
53
  - lib/tweetwine/util.rb
53
54
  - lib/tweetwine.rb
54
55
  has_rdoc: true
@@ -56,7 +57,7 @@ homepage: http://github.com/tuomas/tweetwine
56
57
  post_install_message:
57
58
  rdoc_options:
58
59
  - --title
59
- - Tweetwine 0.1.0
60
+ - Tweetwine 0.1.1
60
61
  - --main
61
62
  - README.rdoc
62
63
  - --exclude
@@ -81,7 +82,7 @@ requirements: []
81
82
  rubyforge_project:
82
83
  rubygems_version: 1.2.0
83
84
  signing_key:
84
- specification_version: 2
85
+ specification_version: 3
85
86
  summary: A simple Twitter agent for command line use
86
87
  test_files: []
87
88