jnunemaker-twitter 0.2.8 → 0.3.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,9 @@
1
+ 0.3.1 - July 23, 2008
2
+ * added open to CLI twitter open jnunemaker would open default browser to http://twitter.com/jnunemaker
3
+ * added -f to timeline and replies which ignores the since_id and shows all results
4
+ * added clear_config to remove all cached since id's and such
5
+ * Majorly pimped the output of timelines and replies.
6
+
1
7
  0.3.0 - July 22, 2008
2
8
  * complete rewrite of CLI. Now supports multiple accounts and changing between them.
3
9
  * added source, truncated, in_reply_to_status_id, in_reply_to_user_id, and favorited to Twitter::Status
data/Manifest.txt CHANGED
@@ -3,6 +3,7 @@ License.txt
3
3
  Manifest.txt
4
4
  README.txt
5
5
  Rakefile
6
+ TODO.txt
6
7
  bin/twitter
7
8
  config/hoe.rb
8
9
  config/requirements.rb
@@ -40,6 +41,7 @@ script/generate
40
41
  script/txt2html
41
42
  setup.rb
42
43
  spec/base_spec.rb
44
+ spec/cli/helper_spec.rb
43
45
  spec/direct_message_spec.rb
44
46
  spec/fixtures/followers.xml
45
47
  spec/fixtures/friends.xml
data/TODO.txt ADDED
@@ -0,0 +1,3 @@
1
+ * format the tweets in a more readable fashion (limit words per line so more scannable)
2
+ * add timeout so it doesn't hang forever like it does now if twitter is down
3
+ * add progress indicator for timeline and replies as posting has for more visual indication that work is happening
data/lib/twitter/base.rb CHANGED
@@ -243,7 +243,7 @@ module Twitter
243
243
 
244
244
  # Converts a string response into an Hpricot xml element.
245
245
  def parse(response)
246
- Hpricot.XML(response)
246
+ Hpricot.XML(response || '')
247
247
  end
248
248
  end
249
249
  end
@@ -1,6 +1,31 @@
1
1
  module Twitter
2
2
  module CLI
3
3
  module Helpers
4
+ def output_tweets(collection, options={})
5
+ options.reverse_merge!({
6
+ :cache => false,
7
+ :since_prefix => '',
8
+ :empty_msg => 'Nothing new since your last check.'
9
+ })
10
+ if collection.size > 0
11
+ justify = collection.collect { |s| s.user.screen_name }.max { |a,b| a.length <=> b.length }.length rescue 0
12
+ indention = ' ' * (justify + 3)
13
+ say("\n#{indention}#{collection.size} new tweet(s) found.\n\n")
14
+ collection.each do |s|
15
+ Tweet.create_from_tweet(current_account, s) if options[:cache]
16
+ occurred_at = Time.parse(s.created_at).strftime('On %b %d at %l:%M%P')
17
+ formatted_time = '-' * occurred_at.length + "\n#{indention}#{occurred_at}"
18
+ formatted_name = s.user.screen_name.rjust(justify + 1)
19
+ formatted_msg = ''
20
+ s.text.split(' ').in_groups_of(6, false) { |row| formatted_msg += row.join(' ') + "\n#{indention}" }
21
+ say "#{CGI::unescapeHTML(formatted_name)}: #{CGI::unescapeHTML(formatted_msg)}#{formatted_time}\n\n"
22
+ end
23
+ Configuration["#{options[:since_prefix]}_since_id"] = collection.first.id
24
+ else
25
+ say(options[:empty_msg])
26
+ end
27
+ end
28
+
4
29
  def base(username=current_account.username, password=current_account.password)
5
30
  @base ||= Twitter::Base.new(username, password)
6
31
  end
data/lib/twitter/cli.rb CHANGED
@@ -253,45 +253,57 @@ Main {
253
253
  description 'the timeline you wish to see (friends, public, me)'
254
254
  default 'friends'
255
255
  }
256
+ option('force', 'f') {
257
+ description "Ignore since_id and show first page of results even if there aren't new ones"
258
+ }
256
259
 
257
260
  def run
258
261
  do_work do
259
262
  timeline = params['timeline'].value == 'me' ? 'user' : params['timeline'].value
260
- options, since_id = {}, Configuration["#{timeline}_last_id"]
261
- options[:since_id] = since_id unless since_id.blank?
262
- statuses = base.timeline(timeline.to_sym, options)
263
- username_length = statuses.collect { |s| s.user.screen_name }.max { |a,b| a.length <=> b.length }.length rescue 0
264
- if statuses.size > 0
265
- statuses.each do |s|
266
- Tweet.create_from_tweet(current_account, s) if timeline != :public
267
- say "#{CGI::unescapeHTML(s.user.screen_name.ljust(username_length+1))}: #{CGI::unescapeHTML(s.text)} on #{Time.parse(s.created_at).strftime('%b %d at %l:%M%P')}"
268
- end
269
- Configuration["#{timeline}_last_id"] = statuses.first.id
270
- else
271
- say 'Nothing new since your last check'
272
- end
263
+ options, since_id = {}, Configuration["#{timeline}_since_id"]
264
+ options[:since_id] = since_id if !since_id.blank? && !params['force'].given?
265
+ cache = [:friends, :user].include?(timeline)
266
+ collection = base.timeline(timeline.to_sym, options)
267
+ output_tweets(collection, {:cache => cache, :since_prefix => timeline})
273
268
  end
274
269
  end
275
270
  end
276
271
 
277
272
  mode 'replies' do
278
273
  description 'Allows you to view all @replies at you'
274
+ option('force', 'f') {
275
+ description "Ignore since_id and show first page of replies even if there aren't new ones"
276
+ }
279
277
 
280
278
  def run
281
279
  do_work do
282
280
  options, since_id = {}, Configuration["replies_since_id"]
283
- options[:since_id] = since_id if !since_id.blank?
284
- replies = base.replies(options)
285
- username_length = replies.collect { |s| s.user.screen_name }.max { |a,b| a.length <=> b.length }.length rescue 0
286
- if replies.size > 0
287
- replies.each do |s|
288
- say "#{CGI::unescapeHTML(s.user.screen_name.ljust(username_length+1))}: #{CGI::unescapeHTML(s.text)} on #{Time.parse(s.created_at).strftime('%b %d at %l:%M%P')}"
289
- end
290
- Configuration["replies_since_id"] = replies.first.id
291
- else
292
- say 'No new replies since your last check'
293
- end
281
+ options[:since_id] = since_id if !since_id.blank? && !params['force'].given?
282
+ collection = base.replies(options)
283
+ output_tweets(collection, {:since_prefix => 'replies'})
284
+ end
285
+ end
286
+ end
287
+
288
+ mode 'clear_config' do
289
+ def run
290
+ do_work do
291
+ count = Configuration.count
292
+ Configuration.destroy_all
293
+ say("#{count} configuration entries cleared.")
294
294
  end
295
295
  end
296
296
  end
297
+
298
+ mode 'open' do
299
+ description 'Opens the given twitter user in a browser window'
300
+ argument('username') {
301
+ required
302
+ description "username or id of twitterrer who's page you would like to see"
303
+ }
304
+
305
+ def run
306
+ `open http://twitter.com/#{params['username'].value}`
307
+ end
308
+ end
297
309
  }
@@ -2,7 +2,7 @@ module Twitter #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,35 @@
1
+ require 'ostruct'
2
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
3
+ require File.dirname(__FILE__) + '/../../lib/twitter/cli/helpers'
4
+
5
+ class Configuration; end
6
+
7
+ def say(str)
8
+ puts str
9
+ end
10
+
11
+ describe Twitter::CLI::Helpers do
12
+ include Twitter::CLI::Helpers
13
+
14
+ describe "outputting tweets" do
15
+ before do
16
+ Configuration.stub!(:[]=).and_return(true)
17
+ @collection = [
18
+ OpenStruct.new(
19
+ :text => 'This is my long message that I want to see formatted ooooh so pretty with a few words on each line so it is easy to scan.',
20
+ :created_at => Time.mktime(2008, 5, 1, 10, 15, 00).strftime('%Y-%m-%d %H:%M:%S'),
21
+ :user => OpenStruct.new(:screen_name => 'jnunemaker')
22
+ ),
23
+ OpenStruct.new(
24
+ :text => 'This is my long message that I want to see formatted ooooh so pretty with a.',
25
+ :created_at => Time.mktime(2008, 4, 1, 10, 15, 00).strftime('%Y-%m-%d %H:%M:%S'),
26
+ :user => OpenStruct.new(:screen_name => 'danielmorrison')
27
+ )
28
+ ]
29
+ end
30
+
31
+ specify "should properly format" do
32
+ output_tweets(@collection)
33
+ end
34
+ end
35
+ end
data/twitter.gemspec CHANGED
@@ -1,16 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{twitter}
3
- s.version = "0.2.8"
3
+ s.version = "0.3.1"
4
4
  s.specification_version = 2 if s.respond_to? :specification_version=
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["John Nunemaker"]
7
- s.date = %q{2008-07-6}
7
+ s.date = %q{2008-07-23}
8
8
  s.default_executable = %q{twitter}
9
9
  s.description = %q{a command line interface for twitter, also a library which wraps the twitter api}
10
10
  s.email = %q{nunemaker@gmail.com}
11
11
  s.executables = ["twitter"]
12
12
  s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "README.txt"]
13
- s.files = ["History.txt", "License.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/twitter", "config/hoe.rb", "config/requirements.rb", "examples/blocks.rb", "examples/direct_messages.rb", "examples/favorites.rb", "examples/friends_followers.rb", "examples/friendships.rb", "examples/location.rb", "examples/replies.rb", "examples/sent_messages.rb", "examples/timeline.rb", "examples/twitter.rb", "examples/verify_credentials.rb", "lib/twitter.rb", "lib/twitter/base.rb", "lib/twitter/cli.rb", "lib/twitter/cli/config.rb", "lib/twitter/cli/helpers.rb", "lib/twitter/cli/migrations/20080722194500_create_accounts.rb", "lib/twitter/cli/migrations/20080722194508_create_tweets.rb", "lib/twitter/cli/migrations/20080722214605_add_account_id_to_tweets.rb", "lib/twitter/cli/migrations/20080722214606_create_configurations.rb", "lib/twitter/cli/models/account.rb", "lib/twitter/cli/models/configuration.rb", "lib/twitter/cli/models/tweet.rb", "lib/twitter/direct_message.rb", "lib/twitter/easy_class_maker.rb", "lib/twitter/rate_limit_status.rb", "lib/twitter/status.rb", "lib/twitter/user.rb", "lib/twitter/version.rb", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/base_spec.rb", "spec/direct_message_spec.rb", "spec/fixtures/followers.xml", "spec/fixtures/friends.xml", "spec/fixtures/friends_for.xml", "spec/fixtures/friends_lite.xml", "spec/fixtures/friends_timeline.xml", "spec/fixtures/public_timeline.xml", "spec/fixtures/rate_limit_status.xml", "spec/fixtures/status.xml", "spec/fixtures/user.xml", "spec/fixtures/user_timeline.xml", "spec/spec.opts", "spec/spec_helper.rb", "spec/status_spec.rb", "spec/user_spec.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "twitter.gemspec", "website/css/common.css", "website/index.html"]
13
+ s.files = ["History.txt", "License.txt", "Manifest.txt", "README.txt", "Rakefile", "TODO.txt", "bin/twitter", "config/hoe.rb", "config/requirements.rb", "examples/blocks.rb", "examples/direct_messages.rb", "examples/favorites.rb", "examples/friends_followers.rb", "examples/friendships.rb", "examples/location.rb", "examples/replies.rb", "examples/sent_messages.rb", "examples/timeline.rb", "examples/twitter.rb", "examples/verify_credentials.rb", "lib/twitter.rb", "lib/twitter/base.rb", "lib/twitter/cli.rb", "lib/twitter/cli/config.rb", "lib/twitter/cli/helpers.rb", "lib/twitter/cli/migrations/20080722194500_create_accounts.rb", "lib/twitter/cli/migrations/20080722194508_create_tweets.rb", "lib/twitter/cli/migrations/20080722214605_add_account_id_to_tweets.rb", "lib/twitter/cli/migrations/20080722214606_create_configurations.rb", "lib/twitter/cli/models/account.rb", "lib/twitter/cli/models/configuration.rb", "lib/twitter/cli/models/tweet.rb", "lib/twitter/direct_message.rb", "lib/twitter/easy_class_maker.rb", "lib/twitter/rate_limit_status.rb", "lib/twitter/status.rb", "lib/twitter/user.rb", "lib/twitter/version.rb", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/base_spec.rb", "spec/cli/helper_spec.rb", "spec/direct_message_spec.rb", "spec/fixtures/followers.xml", "spec/fixtures/friends.xml", "spec/fixtures/friends_for.xml", "spec/fixtures/friends_lite.xml", "spec/fixtures/friends_timeline.xml", "spec/fixtures/public_timeline.xml", "spec/fixtures/rate_limit_status.xml", "spec/fixtures/status.xml", "spec/fixtures/user.xml", "spec/fixtures/user_timeline.xml", "spec/spec.opts", "spec/spec_helper.rb", "spec/status_spec.rb", "spec/user_spec.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "twitter.gemspec", "website/css/common.css", "website/index.html"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://twitter.rubyforge.org}
16
16
  s.rdoc_options = ["--main", "README.txt"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jnunemaker-twitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-06 00:00:00 -07:00
12
+ date: 2008-07-23 00:00:00 -07:00
13
13
  default_executable: twitter
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -47,6 +47,7 @@ files:
47
47
  - Manifest.txt
48
48
  - README.txt
49
49
  - Rakefile
50
+ - TODO.txt
50
51
  - bin/twitter
51
52
  - config/hoe.rb
52
53
  - config/requirements.rb
@@ -84,6 +85,7 @@ files:
84
85
  - script/txt2html
85
86
  - setup.rb
86
87
  - spec/base_spec.rb
88
+ - spec/cli/helper_spec.rb
87
89
  - spec/direct_message_spec.rb
88
90
  - spec/fixtures/followers.xml
89
91
  - spec/fixtures/friends.xml