twtr 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/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.1.1 2008-06-13
2
+ * Added friends method.
3
+ * Added update_location method.
4
+ * Added highline dependancy in gem.
5
+
1
6
  == 0.1.0 2008-05-22
2
- * 1 major enhancement:
3
- * Initial release
7
+ * Initial release
data/config/hoe.rb CHANGED
@@ -58,7 +58,7 @@ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
58
58
 
59
59
  # == Optional
60
60
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
61
- #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
61
+ p.extra_deps = [['highline', '>= 1.4.0']]
62
62
 
63
63
  #p.spec_extras = {} # A hash of extra values to set in the gemspec.
64
64
 
data/lib/twtr/client.rb CHANGED
@@ -45,6 +45,12 @@ module Twtr
45
45
  id = options.delete(:id) || @account_user
46
46
  get_status("/statuses/user_timeline/#{id}", options)
47
47
  end
48
+
49
+ def friends(options={})
50
+ options[:method] = :get
51
+ id = options.delete(:id) || @account_user
52
+ request_status("/statuses/friends/#{id}", options)
53
+ end
48
54
 
49
55
  def replies(options={})
50
56
  get_status("/statuses/replies", options)
@@ -55,9 +61,14 @@ module Twtr
55
61
  friends_timeline()
56
62
  end
57
63
 
64
+ def update_location(options = {})
65
+ options[:method] = :post
66
+ request_status("/account/update_location", options)
67
+ end
68
+
58
69
  def test(options={})
59
70
  request_status("/help/test", options)
60
- end
71
+ end
61
72
 
62
73
  def post_status(path,options = {})
63
74
  options[:method] = :post
data/lib/twtr/console.rb CHANGED
@@ -20,6 +20,9 @@ SYNOPSIS
20
20
  $ twtr ut -i bob # => Show someone's timeline.
21
21
  $ twtr rp # => Show replies.
22
22
  $ twtr up -m "hello world" # => Update message.
23
+ $ twtr friends # => Show friends.
24
+ $ twtr friedns -i bob # => Show bob's friends.
25
+ $ twtr ul -l "Tokyo, Japan" # => Update location.
23
26
 
24
27
  SUBCMMAND
25
28
  setting (reset) # (Re)Set twtr configuration info.
@@ -28,9 +31,14 @@ SUBCMMAND
28
31
  user_timeline (ut) # Show user timeline. -i, --id option required.
29
32
  replies (rp) # Show replies.
30
33
  update (up) # Updates your status. -m, --message option required.
34
+ friedns (fds) # Show friends. available -i, --id option.
35
+ update_location (ul) # Update location. -l, --location option required.
36
+
31
37
  _TEXT_
32
38
 
33
39
  class Console
40
+ include Screen
41
+
34
42
  CONFIG_FILE = Twtr.is_win? ? File.expand_path("#{ENV['HOMEPATH']}/twtr/twtr.yml") \
35
43
  : File.expand_path("~/.twtr/twtr.yml")
36
44
  DEFAULT_DISPLAY_COUNT = 20
@@ -50,6 +58,10 @@ _TEXT_
50
58
  :up => :update,
51
59
  :setting => :setting,
52
60
  :reset => :setting,
61
+ :friends => :friends,
62
+ :fds => :friends,
63
+ :update_location => :update_location,
64
+ :ul => :update_location,
53
65
  }
54
66
 
55
67
  def run(args)
@@ -61,11 +73,13 @@ _TEXT_
61
73
 
62
74
  if @subcommand
63
75
  @configfile ||= CONFIG_FILE
64
- (edit_config(); return) if @subcommand == :setting
76
+ (edit_config(); return) if @subcommand == :setting
65
77
 
66
78
  begin
67
79
  client = Twtr::Client.new(Twtr::Config.load(@configfile))
68
- show_status( client.send(@subcommand, @params) )
80
+ @display_count ||= DEFAULT_DISPLAY_COUNT
81
+ @source = client.send(@subcommand, @params)
82
+ self.send("show_#{@subcommand}")
69
83
  rescue Twtr::ConfigFileNotFoundException => e
70
84
  puts e.message
71
85
  edit_config()
@@ -83,9 +97,9 @@ _TEXT_
83
97
  config = {}
84
98
 
85
99
  account = {}
86
- print "Twitter username: "; user = gets
87
- print "Twitter password: "; password = gets
88
- account["user"] = user.to_s.chomp
100
+ user = HighLine.new.ask("Twitter username: ")
101
+ password = HighLine.new.ask("Twitter password: ") {|q| q.echo = '*' }
102
+ account["user"] = user.to_s.chomp
89
103
  account["password"] = password.to_s.chomp
90
104
  config["account"] = account
91
105
 
@@ -126,6 +140,10 @@ _TEXT_
126
140
  @params.merge!({:source => "twtr", :status => val.toutf8})
127
141
  end
128
142
 
143
+ opt.on('-l','--location=location','Post location.') do |val|
144
+ @params.merge!({:source => "twtr", :location => val.toutf8})
145
+ end
146
+
129
147
  opt.on('-p', '--page=number',"Gets the 20 next statuses.") do |val|
130
148
  @params.merge!({:page => val.to_i})
131
149
  end
@@ -150,23 +168,5 @@ _TEXT_
150
168
  end
151
169
  end
152
170
 
153
- def show_help(opt)
154
- puts "\n#{Twtr::DESCRIPTION}\n#{opt}"
155
- end
156
-
157
- def show_status(source)
158
- @display_count ||= DEFAULT_DISPLAY_COUNT
159
- doc = REXML::Document.new(source)
160
- return if(!doc || !doc.elements['statuses'])
161
- count = 0
162
- doc.elements['statuses'].each_element do |e|
163
- msg = e.elements['user/screen_name'].text + ': ' + e.elements['text'].text
164
- msg = msg.tosjis if Twtr.is_win?
165
- print "#{msg}\n"
166
- break if((count+=1) >= @display_count)
167
- end
168
- puts ""
169
- end
170
-
171
171
  end
172
172
  end
@@ -0,0 +1,66 @@
1
+ module Twtr
2
+ module Screen
3
+
4
+ module InstanceMethods
5
+
6
+ def show_public_timeline() show_status(); end
7
+ def show_friends_timeline() show_status(); end
8
+ def show_user_timeline() show_status(); end
9
+ def show_replies() show_status(); end
10
+ def show_update() show_status(); end
11
+
12
+ def show_status()
13
+ doc = REXML::Document.new(@source)
14
+ return if(!doc || !doc.elements['statuses'])
15
+ count = 0
16
+ doc.elements['statuses'].each_element do |e|
17
+ text = e.elements['user/screen_name'].text + ': ' + e.elements['text'].text
18
+ puts_with_enc text
19
+ break if((count+=1) >= @display_count)
20
+ end
21
+ puts ""
22
+ end
23
+
24
+ def show_friends()
25
+ doc = REXML::Document.new(@source)
26
+ return if(!doc || !doc.elements['users'])
27
+ count = 0
28
+ doc.elements['users'].each_element do |e|
29
+ puts_user_and_location(e)
30
+ break if((count+=1) >= @display_count)
31
+ end
32
+ puts ""
33
+ end
34
+
35
+ def show_update_location()
36
+ doc = REXML::Document.new(@source)
37
+ return if(!doc || !doc.elements['user'])
38
+ count = 0
39
+ e = doc.elements['user']
40
+ puts_user_and_location(e)
41
+ puts ""
42
+ end
43
+
44
+ def puts_user_and_location(e)
45
+ text = "#{e.elements['screen_name'].text}"
46
+ location = "#{e.elements['location'].text}"
47
+ text += " (#{location})" unless location.empty?
48
+ puts_with_enc text
49
+ end
50
+
51
+ def show_help(opt)
52
+ puts "\n#{Twtr::DESCRIPTION}\n#{opt}"
53
+ end
54
+
55
+ end
56
+
57
+ def puts_with_enc(text)
58
+ text = text.tosjis if Twtr.is_win?
59
+ print "#{text}\n"
60
+ end
61
+
62
+ def self.included(receiver)
63
+ receiver.send :include, InstanceMethods
64
+ end
65
+ end
66
+ end
data/lib/twtr/version.rb CHANGED
@@ -2,7 +2,7 @@ module Twtr #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/twtr.rb CHANGED
@@ -9,8 +9,11 @@ module Twtr
9
9
  require "kconv"
10
10
  require "cgi"
11
11
  require "rexml/document"
12
+ require "rubygems"
13
+ require "highline"
12
14
  require "twtr/version"
13
15
  require "twtr/config"
16
+ require "twtr/screen"
14
17
  require "twtr/console"
15
18
  require "twtr/client"
16
19
  require "twtr/errors"
@@ -56,7 +56,7 @@ class TestTwtrConsole < Test::Unit::TestCase
56
56
 
57
57
  def test_version()
58
58
  ret = `#{TWTR_PATH} -v`
59
- assert_equal("twtr 0.1.0\n", ret)
59
+ assert_equal("twtr 0.1.1\n", ret)
60
60
  end
61
61
 
62
62
  def test_unkown_subcommand
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twtr
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
  - Ryota Maruko
@@ -9,10 +9,18 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-10 00:00:00 +09:00
12
+ date: 2008-06-13 00:00:00 +09:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: highline
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.4.0
23
+ version:
16
24
  description: twtr is a twitter client for Linux, OSX and Windows Console.
17
25
  email:
18
26
  - ""
@@ -36,6 +44,7 @@ files:
36
44
  - lib/twtr/config.rb
37
45
  - lib/twtr/console.rb
38
46
  - lib/twtr/errors.rb
47
+ - lib/twtr/screen.rb
39
48
  - lib/twtr/version.rb
40
49
  - setup.rb
41
50
  - test/test_helper.rb