Skip to content
This repository
Browse code

Removed all the old stuff. Rewrites are fun!!!!!

  • Loading branch information...
commit dd2445e3e2c97f38b28a3f32ea902536b3897adf 1 parent 4397254
John Nunemaker authored April 02, 2009

Showing 66 changed files with 0 additions and 5,378 deletions. Show diff stats Hide diff stats

  1. 68  Manifest
  2. 84  README
  3. 42  Rakefile
  4. 14  bin/twitter
  5. 15  examples/blocks.rb
  6. 29  examples/direct_messages.rb
  7. 20  examples/favorites.rb
  8. 25  examples/friends_followers.rb
  9. 13  examples/friendships.rb
  10. 7  examples/identica_timeline.rb
  11. 8  examples/location.rb
  12. 60  examples/oauth.rb
  13. 9  examples/posting.rb
  14. 27  examples/replies.rb
  15. 18  examples/search.rb
  16. 27  examples/sent_messages.rb
  17. 34  examples/timeline.rb
  18. 27  examples/twitter.rb
  19. 13  examples/verify_credentials.rb
  20. 38  lib/twitter.rb
  21. 284  lib/twitter/base.rb
  22. 334  lib/twitter/cli.rb
  23. 9  lib/twitter/cli/config.rb
  24. 109  lib/twitter/cli/helpers.rb
  25. 13  lib/twitter/cli/migrations/20080722194500_create_accounts.rb
  26. 16  lib/twitter/cli/migrations/20080722194508_create_tweets.rb
  27. 9  lib/twitter/cli/migrations/20080722214605_add_account_id_to_tweets.rb
  28. 13  lib/twitter/cli/migrations/20080722214606_create_configurations.rb
  29. 33  lib/twitter/cli/models/account.rb
  30. 13  lib/twitter/cli/models/configuration.rb
  31. 20  lib/twitter/cli/models/tweet.rb
  32. 22  lib/twitter/direct_message.rb
  33. 43  lib/twitter/easy_class_maker.rb
  34. 32  lib/twitter/oauth.rb
  35. 19  lib/twitter/rate_limit_status.rb
  36. 101  lib/twitter/search.rb
  37. 83  lib/twitter/search_result.rb
  38. 82  lib/twitter/search_result_info.rb
  39. 22  lib/twitter/status.rb
  40. 38  lib/twitter/user.rb
  41. 3  lib/twitter/version.rb
  42. 139  spec/base_spec.rb
  43. 49  spec/cli/helper_spec.rb
  44. 35  spec/direct_message_spec.rb
  45. 11  spec/fixtures/follower_ids.xml
  46. 706  spec/fixtures/followers.xml
  47. 12  spec/fixtures/friend_ids.xml
  48. 609  spec/fixtures/friends.xml
  49. 584  spec/fixtures/friends_for.xml
  50. 192  spec/fixtures/friends_lite.xml
  51. 66  spec/fixtures/friends_timeline.xml
  52. 5  spec/fixtures/friendship_already_exists.xml
  53. 12  spec/fixtures/friendship_created.xml
  54. 148  spec/fixtures/public_timeline.xml
  55. 7  spec/fixtures/rate_limit_status.xml
  56. 147  spec/fixtures/search_result_info.yml
  57. 1  spec/fixtures/search_results.json
  58. 25  spec/fixtures/status.xml
  59. 38  spec/fixtures/user.xml
  60. 465  spec/fixtures/user_timeline.xml
  61. 100  spec/search_spec.rb
  62. 1  spec/spec.opts
  63. 23  spec/spec_helper.rb
  64. 40  spec/status_spec.rb
  65. 42  spec/user_spec.rb
  66. 45  twitter.gemspec
68  Manifest
... ...
@@ -1,68 +0,0 @@
1  
-bin/twitter
2  
-examples/blocks.rb
3  
-examples/direct_messages.rb
4  
-examples/favorites.rb
5  
-examples/friends_followers.rb
6  
-examples/friendships.rb
7  
-examples/identica_timeline.rb
8  
-examples/location.rb
9  
-examples/posting.rb
10  
-examples/replies.rb
11  
-examples/search.rb
12  
-examples/sent_messages.rb
13  
-examples/timeline.rb
14  
-examples/twitter.rb
15  
-examples/verify_credentials.rb
16  
-History
17  
-lib/twitter/base.rb
18  
-lib/twitter/cli/config.rb
19  
-lib/twitter/cli/helpers.rb
20  
-lib/twitter/cli/migrations/20080722194500_create_accounts.rb
21  
-lib/twitter/cli/migrations/20080722194508_create_tweets.rb
22  
-lib/twitter/cli/migrations/20080722214605_add_account_id_to_tweets.rb
23  
-lib/twitter/cli/migrations/20080722214606_create_configurations.rb
24  
-lib/twitter/cli/models/account.rb
25  
-lib/twitter/cli/models/configuration.rb
26  
-lib/twitter/cli/models/tweet.rb
27  
-lib/twitter/cli.rb
28  
-lib/twitter/direct_message.rb
29  
-lib/twitter/easy_class_maker.rb
30  
-lib/twitter/rate_limit_status.rb
31  
-lib/twitter/search.rb
32  
-lib/twitter/search_result.rb
33  
-lib/twitter/search_result_info.rb
34  
-lib/twitter/status.rb
35  
-lib/twitter/user.rb
36  
-lib/twitter/version.rb
37  
-lib/twitter.rb
38  
-License
39  
-Manifest
40  
-Rakefile
41  
-README
42  
-spec/base_spec.rb
43  
-spec/cli/helper_spec.rb
44  
-spec/direct_message_spec.rb
45  
-spec/fixtures/follower_ids.xml
46  
-spec/fixtures/followers.xml
47  
-spec/fixtures/friend_ids.xml
48  
-spec/fixtures/friends.xml
49  
-spec/fixtures/friends_for.xml
50  
-spec/fixtures/friends_lite.xml
51  
-spec/fixtures/friends_timeline.xml
52  
-spec/fixtures/friendship_already_exists.xml
53  
-spec/fixtures/friendship_created.xml
54  
-spec/fixtures/public_timeline.xml
55  
-spec/fixtures/rate_limit_status.xml
56  
-spec/fixtures/search_result_info.yml
57  
-spec/fixtures/search_results.json
58  
-spec/fixtures/status.xml
59  
-spec/fixtures/user.xml
60  
-spec/fixtures/user_timeline.xml
61  
-spec/search_spec.rb
62  
-spec/spec.opts
63  
-spec/spec_helper.rb
64  
-spec/status_spec.rb
65  
-spec/user_spec.rb
66  
-website/css/common.css
67  
-website/images/terminal_output.png
68  
-website/index.html
84  README
... ...
@@ -1,84 +0,0 @@
1  
-= addicted to twitter
2  
-
3  
-... a sweet little diddy that helps you twitter your life away
4  
-
5  
-== Install
6  
-
7  
-sudo gem install twitter will work just fine. For command line use, you'll need a few other gems: sudo gem install main highline activerecord sqlite3-ruby
8  
-
9  
-== Examples
10  
-
11  
-	Twitter::Base.new('your email', 'your password').update('watching veronica mars')
12  
-	
13  
-	# or you can use post
14  
-	Twitter::Base.new('your email', 'your password').post('post works too')
15  
-
16  
-	puts "Public Timeline", "=" * 50
17  
-	Twitter::Base.new('your email', 'your password').timeline(:public).each do |s|
18  
-	  puts s.text, s.user.name
19  
-	  puts
20  
-	end
21  
-
22  
-	puts '', "Friends Timeline", "=" * 50
23  
-	Twitter::Base.new('your email', 'your password').timeline.each do |s|
24  
-	  puts s.text, s.user.name
25  
-	  puts
26  
-	end
27  
-
28  
-	puts '', "Friends", "=" * 50
29  
-	Twitter::Base.new('your email', 'your password').friends.each do |u|
30  
-	  puts u.name, u.status.text
31  
-	  puts
32  
-	end
33  
-
34  
-	puts '', "Followers", "=" * 50
35  
-	Twitter::Base.new('your email', 'your password').followers.each do |u|
36  
-	  puts u.name, u.status.text
37  
-	  puts
38  
-	end
39  
-	
40  
-== Search Examples
41  
-
42  
-	Twitter::Search.new('httparty').each { |r| puts r.inspect }
43  
-	Twitter::Search.new('httparty').from('jnunemaker').each { |r| puts r.inspect }
44  
-	Twitter::Search.new.from('jnunemaker').to('oaknd1').each { |r| puts r.inspect }
45  
-	
46  
-
47  
-== Command Line Use
48  
-
49  
-Note: If you want to use twitter from the command line be sure that sqlite3 and the sqlite3-ruby gem are installed. I removed the sqlite3-ruby gem as a dependency because you shouldn't need that to just use the API wrapper. Eventually I'll move the CLI interface into another gem.
50  
-	
51  
-	$ twitter
52  
-
53  
-Will give you a list of all the commands. You can get the help for each command by running twitter [command] -h. 
54  
-
55  
-The first thing you'll want to do is install the database so your account(s) can be stored. 
56  
-
57  
-	$ twitter install
58  
-	
59  
-You can always uninstall twitter like this:
60  
-
61  
-	$ twitter uninstall
62  
-	
63  
-Once the twitter database is installed and migrated, you can add accounts like this:
64  
-
65  
-	$ twitter add
66  
-	Add New Account:
67  
-	Username: jnunemaker
68  
-	Password (won't be displayed): 
69  
-	Account added.
70  
-
71  
-You can also list all the accounts you've added.
72  
-
73  
-	$ twitter list
74  
-	Account List
75  
-	* jnunemaker
76  
-	  snitch_test
77  
-
78  
-The * means denotes the account that will be used when posting, befriending, defriending, following, leaving or viewing a timeline.
79  
-
80  
-To post using the account marked with the *, simply type the following:
81  
-
82  
-	$ twitter post "releasing my new twitter gem"
83  
-
84  
-That is about it. You can do pretty much anything that you can do with twitter from the command line interface.
42  Rakefile
... ...
@@ -1,42 +0,0 @@
1  
-ProjectName = 'twitter'
2  
-WebsitePath = "jnunemaker@rubyforge.org:/var/www/gforge-projects/#{ProjectName}"
3  
-
4  
-require 'rubygems'
5  
-require 'rake'
6  
-require 'echoe'
7  
-require 'spec/rake/spectask'
8  
-require "lib/#{ProjectName}/version"
9  
-
10  
-Echoe.new(ProjectName, Twitter::Version) do |p|
11  
-  p.description     = "a command line interface for twitter, also a library which wraps the twitter api"
12  
-  p.url             = "http://#{ProjectName}.rubyforge.org"
13  
-  p.author          = "John Nunemaker"
14  
-  p.email           = "nunemaker@gmail.com"
15  
-  p.extra_deps      = [['oauth', '>= 0.3.2'], ['hpricot', '>= 0.6'], ['activesupport', '>= 2.1'], ['httparty', '>= 0.2.4']]
16  
-  p.need_tar_gz     = false
17  
-  p.docs_host       = WebsitePath
18  
-end
19  
-
20  
-desc 'Upload website files to rubyforge'
21  
-task :website do
22  
-  sh %{rsync -av website/ #{WebsitePath}}
23  
-  Rake::Task['website_docs'].invoke
24  
-end
25  
-
26  
-task :website_docs do
27  
-  Rake::Task['redocs'].invoke
28  
-  sh %{rsync -av doc/ #{WebsitePath}/docs}
29  
-end
30  
-
31  
-desc 'Preps the gem for a new release'
32  
-task :prepare do
33  
-  %w[manifest build_gemspec].each do |task|
34  
-    Rake::Task[task].invoke
35  
-  end
36  
-end
37  
-
38  
-Rake::Task[:default].prerequisites.clear
39  
-task :default => :spec
40  
-Spec::Rake::SpecTask.new do |t|
41  
-  t.spec_files = FileList["spec/**/*_spec.rb"]
42  
-end
14  bin/twitter
... ...
@@ -1,14 +0,0 @@
1  
-#!/usr/bin/env ruby
2  
-
3  
-# if we have stdin, let's prepend it to the message for post
4  
-if ARGV[0] && ARGV[0] == 'post' && !STDIN.tty?
5  
-  ARGV[1] = "#{STDIN.read}#{ARGV[1]}"
6  
-end
7  
-
8  
-# if we have stdin, let's prepend it to the message for d
9  
-if ARGV[0] && ARGV[0] == 'd' && !STDIN.tty?
10  
-  ARGV[2] = "#{STDIN.read}#{ARGV[2]}"
11  
-end
12  
-
13  
-require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'twitter'))
14  
-require 'twitter/cli'
15  examples/blocks.rb
... ...
@@ -1,15 +0,0 @@
1  
-require 'rubygems'
2  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
3  
-config = YAML::load(open(ENV['HOME'] + '/.twitter'))
4  
-
5  
-twitter = Twitter::Base.new(config['email'], config['password'])
6  
-
7  
-puts 'BLOCK CREATE'
8  
-puts twitter.block('project_rockne').name
9  
-puts
10  
-puts
11  
-
12  
-puts 'BLOCK DESTROY'
13  
-puts twitter.block('project_rockne').name
14  
-puts
15  
-puts
29  examples/direct_messages.rb
... ...
@@ -1,29 +0,0 @@
1  
-require 'rubygems'
2  
-require 'activesupport'
3  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
4  
-config = YAML::load(open(ENV['HOME'] + '/.twitter'))
5  
-
6  
-twitter = Twitter::Base.new(config['email'], config['password'])
7  
-
8  
-puts 'SINCE'
9  
-twitter.direct_messages(:since => Time.now - 5.day).each do |s|
10  
-  puts "- #{s.id} #{s.text}"
11  
-end
12  
-puts
13  
-puts
14  
-
15  
-# puts 'SINCE_ID'
16  
-# twitter.direct_messages(:since_id => 33505386).each do |s|
17  
-#   puts "- #{s.text}"
18  
-# end
19  
-# puts
20  
-# puts
21  
-# 
22  
-# puts 'PAGE'
23  
-# twitter.direct_messages(:page => 1).each do |s|
24  
-#   puts "- #{s.text}"
25  
-# end
26  
-# puts
27  
-# puts
28  
-
29  
-# puts twitter.destroy_direct_message(34489057).inspect
20  examples/favorites.rb
... ...
@@ -1,20 +0,0 @@
1  
-require 'rubygems'
2  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
3  
-config = YAML::load(open(ENV['HOME'] + '/.twitter'))
4  
-
5  
-twitter = Twitter::Base.new(config['email'], config['password'])
6  
-
7  
-puts 'CREATE'
8  
-puts twitter.create_favorite(865416114).text
9  
-puts
10  
-puts
11  
-
12  
-puts 'FAVORITES'
13  
-twitter.favorites.each { |f| puts f.text }
14  
-puts
15  
-puts
16  
-
17  
-puts 'DESTROY'
18  
-puts twitter.destroy_favorite(865416114).text
19  
-puts
20  
-puts
25  examples/friends_followers.rb
... ...
@@ -1,25 +0,0 @@
1  
-require 'rubygems'
2  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
3  
-config = YAML::load(open(ENV['HOME'] + '/.twitter'))
4  
-
5  
-twitter = Twitter::Base.new(config['email'], config['password'])
6  
-
7  
-puts "FRIENDS"
8  
-twitter.friends.each { |f| puts f.name }
9  
-puts
10  
-puts
11  
-
12  
-puts "FRIENDS FOR"
13  
-twitter.friends_for('orderedlist', :lite => true).each { |f| puts f.name }
14  
-puts
15  
-puts
16  
-
17  
-puts "FOLLOWERS"
18  
-twitter.followers(:lite => true).each { |f| puts f.name }
19  
-puts
20  
-puts
21  
-
22  
-puts "FOLLOWERS FOR"
23  
-twitter.followers_for('orderedlist', :lite => true).each { |f| puts f.name }
24  
-puts
25  
-puts
13  examples/friendships.rb
... ...
@@ -1,13 +0,0 @@
1  
-require 'rubygems'
2  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
3  
-config = YAML::load(open(ENV['HOME'] + '/.twitter'))
4  
-
5  
-twitter = Twitter::Base.new(config['email'], config['password'])
6  
-
7  
-puts twitter.create_friendship('orderedlist').name
8  
-puts twitter.follow('orderedlist').name
9  
-puts twitter.leave('orderedlist').name
10  
-puts twitter.destroy_friendship('orderedlist').name
11  
-
12  
-puts twitter.friendship_exists?('jnunemaker', 'orderedlist').inspect
13  
-puts twitter.friendship_exists?('jnunemaker', 'ze').inspect
7  examples/identica_timeline.rb
... ...
@@ -1,7 +0,0 @@
1  
-require 'rubygems'
2  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
3  
-config = YAML::load(open(ENV['HOME'] + '/.twitter'))
4  
-
5  
-identica = Twitter::Base.new(config['email'], config['password'], :api_host => 'identi.ca/api')
6  
-
7  
-identica.timeline(:public).each { |s| puts s.text, s.user.name, '' }
8  examples/location.rb
... ...
@@ -1,8 +0,0 @@
1  
-require 'rubygems'
2  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
3  
-config = YAML::load(open(ENV['HOME'] + '/.twitter'))
4  
-
5  
-twitter = Twitter::Base.new(config['email'], config['password'])
6  
-
7  
-puts twitter.update_location('Hollywood, CA').location
8  
-puts twitter.update_delivery_device('none')
60  examples/oauth.rb
... ...
@@ -1,60 +0,0 @@
1  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
2  
-require 'pp'
3  
-
4  
-class ConfigStore
5  
-  attr_reader :file
6  
-  
7  
-  def initialize(file)
8  
-    @file = file
9  
-  end
10  
-  
11  
-  def load
12  
-    @config ||= YAML::load(open(file))
13  
-    self
14  
-  end
15  
-  
16  
-  def [](key)
17  
-    load
18  
-    @config[key]
19  
-  end
20  
-  
21  
-  def []=(key, value)
22  
-    @config[key] = value
23  
-  end
24  
-  
25  
-  def update(c={})
26  
-    @config.merge!(c)
27  
-    save
28  
-  end
29  
-  
30  
-  def save
31  
-    File.open(file, 'w') { |f| f.write(YAML.dump(@config)) }
32  
-  end
33  
-end
34  
-
35  
-config = ConfigStore.new("#{ENV['HOME']}/.twitter")
36  
-oauth = Twitter::OAuth.new(config['token'], config['secret'])
37  
-
38  
-if config['atoken'] && config['asecret']
39  
-  oauth.authorize_from_access(config['atoken'], config['asecret'])
40  
-  puts oauth.access_token.get("/statuses/friends_timeline.json")
41  
-  
42  
-elsif config['rtoken'] && config['rsecret']  
43  
-  oauth.authorize_from_request(config['rtoken'], config['rsecret'])
44  
-  puts oauth.access_token.get("/statuses/friends_timeline.json")
45  
-  
46  
-  config.update({
47  
-    'atoken'  => oauth.access_token.token,
48  
-    'asecret' => oauth.access_token.secret,
49  
-    'rtoken'  => nil,
50  
-    'rsecret' => nil,
51  
-  })
52  
-else
53  
-  config.update({
54  
-    'rtoken'  => oauth.request_token.token,
55  
-    'rsecret' => oauth.request_token.secret,
56  
-  })
57  
-  
58  
-  # authorize in browser
59  
-  %x(open #{oauth.request_token.authorize_url})
60  
-end
9  examples/posting.rb
... ...
@@ -1,9 +0,0 @@
1  
-require 'rubygems'
2  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
3  
-config = YAML::load(open(ENV['HOME'] + '/.twitter'))
4  
-
5  
-twitter = Twitter::Base.new(config['email'], config['password'])
6  
-puts twitter.post("This is a test from the example file").inspect
7  
-
8  
-# sending a direct message
9  
-# puts twitter.d('jnunemaker', 'this is a test').inspect
27  examples/replies.rb
... ...
@@ -1,27 +0,0 @@
1  
-require 'rubygems'
2  
-require 'activesupport'
3  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
4  
-config = YAML::load(open(ENV['HOME'] + '/.twitter'))
5  
-
6  
-twitter = Twitter::Base.new(config['email'], config['password'])
7  
-
8  
-puts 'SINCE'
9  
-twitter.replies(:since => Time.now - 5.day).each do |s|
10  
-  puts "- #{s.text}"
11  
-end
12  
-puts
13  
-puts
14  
-
15  
-puts 'SINCE_ID'
16  
-twitter.replies(:since_id => 863081345).each do |s|
17  
-  puts "- #{s.text}"
18  
-end
19  
-puts
20  
-puts
21  
-
22  
-puts 'PAGE'
23  
-twitter.replies(:page => 1).each do |s|
24  
-  puts "- #{s.text}"
25  
-end
26  
-puts
27  
-puts
18  examples/search.rb
... ...
@@ -1,18 +0,0 @@
1  
-require 'rubygems'
2  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
3  
-
4  
-Twitter::Search.new('httparty').each { |r| puts r.inspect,'' }
5  
-Twitter::Search.new('httparty').page(2).each { |r| puts r.inspect, '' }
6  
-
7  
-# search = Twitter::Search.new
8  
-# search.from('jnunemaker').to('oaknd1').each { |r| puts r.inspect, '' }
9  
-# pp search.result
10  
-# search.clear
11  
-
12  
-# search.from('jnunemaker').to('oaknd1').since(814529437).containing('milk').each { |r| puts r.inspect, '' }
13  
-# search.clear
14  
-# 
15  
-# search.geocode('40.757929', '-73.985506', '50mi').containing('holland').each { |r| puts r.inspect, '' }
16  
-# search.clear
17  
-
18  
-# pp search.from('jnunemaker').fetch()
27  examples/sent_messages.rb
... ...
@@ -1,27 +0,0 @@
1  
-require 'rubygems'
2  
-require 'activesupport'
3  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
4  
-config = YAML::load(open(ENV['HOME'] + '/.twitter'))
5  
-
6  
-twitter = Twitter::Base.new(config['email'], config['password'])
7  
-
8  
-puts 'SINCE'
9  
-twitter.sent_messages(:since => Time.now - 5.day).each do |s|
10  
-  puts "- #{s.text}"
11  
-end
12  
-puts
13  
-puts
14  
-
15  
-puts 'SINCE_ID'
16  
-twitter.sent_messages(:since_id => 33505386).each do |s|
17  
-  puts "- #{s.text}"
18  
-end
19  
-puts
20  
-puts
21  
-
22  
-puts 'PAGE'
23  
-twitter.sent_messages(:page => 1).each do |s|
24  
-  puts "- #{s.text}"
25  
-end
26  
-puts
27  
-puts
34  examples/timeline.rb
... ...
@@ -1,34 +0,0 @@
1  
-require 'rubygems'
2  
-require 'activesupport'
3  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
4  
-config = YAML::load(open(ENV['HOME'] + '/.twitter'))
5  
-
6  
-twitter = Twitter::Base.new(config['email'], config['password'])
7  
-
8  
-puts 'SINCE'
9  
-twitter.timeline(:user, :since => Time.now - 1.day).each do |s|
10  
-  puts "- #{s.text}"
11  
-end
12  
-puts
13  
-puts
14  
-
15  
-puts 'SINCE_ID'
16  
-twitter.timeline(:user, :since_id => 865547074).each do |s|
17  
-  puts "- #{s.text}"
18  
-end
19  
-puts
20  
-puts
21  
-
22  
-puts 'COUNT'
23  
-twitter.timeline(:user, :count => 1).each do |s|
24  
-  puts "- #{s.text}"
25  
-end
26  
-puts
27  
-puts
28  
-
29  
-puts 'PAGE'
30  
-twitter.timeline(:user, :page => 1).each do |s|
31  
-  puts "- #{s.text}"
32  
-end
33  
-puts
34  
-puts
27  examples/twitter.rb
... ...
@@ -1,27 +0,0 @@
1  
-require 'rubygems'
2  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
3  
-config = YAML::load(open(ENV['HOME'] + '/.twitter'))
4  
-
5  
-puts "Public Timeline", "=" * 50
6  
-Twitter::Base.new(config['email'], config['password']).timeline(:public).each do |s|
7  
-  puts s.text, s.user.name
8  
-  puts
9  
-end
10  
-
11  
-puts '', "Friends Timeline", "=" * 50
12  
-Twitter::Base.new(config['email'], config['password']).timeline.each do |s|
13  
-  puts s.text, s.user.name
14  
-  puts
15  
-end
16  
-
17  
-puts '', "Friends", "=" * 50
18  
-Twitter::Base.new(config['email'], config['password']).friends.each do |u|
19  
-  puts u.name, u.status.text
20  
-  puts
21  
-end
22  
-
23  
-puts '', "Followers", "=" * 50
24  
-Twitter::Base.new(config['email'], config['password']).followers.each do |u|
25  
-  puts u.name, u.status.text
26  
-  puts
27  
-end
13  examples/verify_credentials.rb
... ...
@@ -1,13 +0,0 @@
1  
-require 'rubygems'
2  
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
3  
-config = YAML::load(open(ENV['HOME'] + '/.twitter'))
4  
-
5  
-twitter = Twitter::Base.new(config['email'], config['password'])
6  
-
7  
-puts twitter.verify_credentials
8  
-
9  
-begin
10  
-  Twitter::Base.new('asdf', 'foobar').verify_credentials
11  
-rescue => error
12  
-  puts error.message
13  
-end
38  lib/twitter.rb
... ...
@@ -1,38 +0,0 @@
1  
-require 'uri'
2  
-require 'cgi'
3  
-require 'net/http'
4  
-require 'yaml'
5  
-require 'time'
6  
-require 'rubygems'
7  
-
8  
-gem 'hpricot'
9  
-require 'hpricot'
10  
-
11  
-gem 'oauth'
12  
-require 'oauth'
13  
-
14  
-$:.unshift(File.dirname(__FILE__))
15  
-require 'twitter/version'
16  
-require 'twitter/easy_class_maker'
17  
-require 'twitter/oauth'
18  
-require 'twitter/base'
19  
-require 'twitter/user'
20  
-require 'twitter/search'
21  
-require 'twitter/status'
22  
-require 'twitter/direct_message'
23  
-require 'twitter/rate_limit_status'
24  
-require 'twitter/search_result_info'
25  
-require 'twitter/search_result'
26  
-
27  
-module Twitter
28  
-  class Unavailable < StandardError; end
29  
-  class CantConnect < StandardError; end
30  
-  class BadResponse < StandardError; end
31  
-  class UnknownTimeline < ArgumentError; end
32  
-  class RateExceeded < StandardError; end
33  
-  class CantFindUsers < ArgumentError; end
34  
-  class AlreadyFollowing < StandardError; end
35  
-  class CantFollowUser < StandardError; end
36  
-
37  
-  SourceName = 'twittergem'
38  
-end
284  lib/twitter/base.rb
... ...
@@ -1,284 +0,0 @@
1  
-# This is the base class for the twitter library. It makes all the requests 
2  
-# to twitter, parses the xml (using hpricot) and returns ruby objects to play with.
3  
-#
4  
-# For complete documentation on the options, check out the twitter api docs.
5  
-#   http://groups.google.com/group/twitter-development-talk/web/api-documentation
6  
-module Twitter
7  
-  class Base
8  
-    # Initializes the configuration for making requests to twitter
9  
-    # Twitter example:
10  
-    #   Twitter.new('email/username', 'password')
11  
-    #
12  
-    # Identi.ca example:
13  
-    #   Twitter.new('email/username', 'password', :api_host => 'identi.ca/api')
14  
-    def initialize(email, password, options={})
15  
-      @api_host = options.delete(:api_host) || 'twitter.com'
16  
-      @config, @config[:email], @config[:password] = options, email, password
17  
-      @proxy_host = options[:proxy_host]
18  
-      @proxy_port = options[:proxy_port]
19  
-    end
20  
-    
21  
-    # Returns an array of statuses for a timeline; Defaults to your friends timeline.
22  
-    def timeline(which=:friends, options={})
23  
-      raise UnknownTimeline unless [:friends, :public, :user].include?(which)
24  
-      auth = which.to_s.include?('public') ? false : true
25  
-      statuses(call("#{which}_timeline", :auth => auth, :since => options[:since], :args => parse_options(options)))
26  
-    end
27  
-    
28  
-    # Returns an array of users who are in your friends list
29  
-    def friends(options={})
30  
-      users(call(:friends, {:args => parse_options(options)}))
31  
-    end
32  
-    
33  
-    # Returns an array of users who are friends for the id or username passed in
34  
-    def friends_for(id, options={})
35  
-      friends(options.merge({:id => id}))
36  
-    end
37  
-    
38  
-    # Returns an array of user ids who are friends for the account or the option id/username passed in
39  
-    def friend_ids(id_or_screenname = nil)
40  
-      path = id_or_screenname ? "friends/ids/#{id_or_screenname}.xml" : "friends/ids.xml"
41  
-      doc = request(path, :auth => true)
42  
-      (doc/:id).inject([]) {|ids, id| ids << id.innerHTML; ids}
43  
-    end
44  
-    
45  
-    # Returns an array of users who are following you
46  
-    def followers(options={})
47  
-      users(call(:followers, {:args => parse_options(options)}))
48  
-    end
49  
-    
50  
-    def followers_for(id, options={})
51  
-      followers(options.merge({:id => id}))
52  
-    end
53  
-    
54  
-    # Returns an array of user ids who are followers for the account or the option id/username passed in
55  
-    def follower_ids(id_or_screenname = nil)
56  
-      path = id_or_screenname ? "followers/ids/#{id_or_screenname}.xml" : "followers/ids.xml"
57  
-      doc = request(path, :auth => true)
58  
-      (doc/:id).inject([]) {|ids, id| ids << id.innerHTML; ids}
59  
-    end
60  
-    
61  
-    # Returns a single status for a given id
62  
-    def status(id)
63  
-      statuses(call("show/#{id}")).first
64  
-    end
65  
-    
66  
-    # returns all the profile information and the last status for a user
67  
-    def user(id_or_screenname)
68  
-      users(request("users/show/#{id_or_screenname}.xml", :auth => true)).first
69  
-    end
70  
-    
71  
-    # Returns an array of statuses that are replies
72  
-    def replies(options={})
73  
-      statuses(call(:replies, :since => options[:since], :args => parse_options(options)))
74  
-    end
75  
-    
76  
-    # Destroys a status by id
77  
-    def destroy(id)
78  
-      call("destroy/#{id}")
79  
-    end
80  
-    
81  
-    def rate_limit_status
82  
-      RateLimitStatus.new_from_xml request("account/rate_limit_status.xml", :auth => true)
83  
-    end
84  
-    
85  
-    # waiting for twitter to correctly implement this in the api as it is documented
86  
-    def featured
87  
-      users(call(:featured))
88  
-    end
89  
-    
90  
-    # Returns an array of all the direct messages for the authenticated user
91  
-    def direct_messages(options={})
92  
-      doc = request(build_path('direct_messages.xml', parse_options(options)), {:auth => true, :since => options[:since]})
93  
-      (doc/:direct_message).inject([]) { |dms, dm| dms << DirectMessage.new_from_xml(dm); dms }
94  
-    end
95  
-    alias :received_messages :direct_messages
96  
-    
97  
-    # Returns direct messages sent by auth user
98  
-    def sent_messages(options={})
99  
-      doc = request(build_path('direct_messages/sent.xml', parse_options(options)), {:auth => true, :since => options[:since]})
100  
-      (doc/:direct_message).inject([]) { |dms, dm| dms << DirectMessage.new_from_xml(dm); dms }
101  
-    end
102  
-    
103  
-    # destroys a give direct message by id if the auth user is a recipient
104  
-    def destroy_direct_message(id)
105  
-      DirectMessage.new_from_xml(request("direct_messages/destroy/#{id}.xml", :auth => true, :method => :post))
106  
-    end
107  
-    
108  
-    # Sends a direct message <code>text</code> to <code>user</code>
109  
-    def d(user, text)
110  
-      DirectMessage.new_from_xml(request('direct_messages/new.xml', :auth => true, :method => :post, :form_data => {'text' => text, 'user' => user}))
111  
-    end
112  
-    
113  
-    # Befriends id_or_screenname for the auth user
114  
-    def create_friendship(id_or_screenname)
115  
-      users(request("friendships/create/#{id_or_screenname}.xml", :auth => true, :method => :post)).first
116  
-    end
117  
-    
118  
-    # Defriends id_or_screenname for the auth user
119  
-    def destroy_friendship(id_or_screenname)
120  
-      users(request("friendships/destroy/#{id_or_screenname}.xml", :auth => true, :method => :post)).first
121  
-    end
122  
-    
123  
-    # Returns true if friendship exists, false if it doesn't.
124  
-    def friendship_exists?(user_a, user_b)
125  
-      doc = request(build_path("friendships/exists.xml", {:user_a => user_a, :user_b => user_b}), :auth => true)
126  
-      doc.at('friends').innerHTML == 'true' ? true : false
127  
-    end
128  
-    
129  
-    # Updates your location and returns Twitter::User object
130  
-    def update_location(location)
131  
-      users(request(build_path('account/update_location.xml', {'location' => location}), :auth => true, :method => :post)).first
132  
-    end
133  
-    
134  
-    # Updates your deliver device and returns Twitter::User object
135  
-    def update_delivery_device(device)
136  
-      users(request(build_path('account/update_delivery_device.xml', {'device' => device}), :auth => true, :method => :post)).first
137  
-    end
138  
-    
139  
-    # Turns notifications by id_or_screenname on for auth user.
140  
-    def follow(id_or_screenname)
141  
-      users(request("notifications/follow/#{id_or_screenname}.xml", :auth => true, :method => :post)).first
142  
-    end
143  
-
144  
-    # Turns notifications by id_or_screenname off for auth user.    
145  
-    def leave(id_or_screenname)
146  
-      users(request("notifications/leave/#{id_or_screenname}.xml", :auth => true, :method => :post)).first
147  
-    end
148  
-    
149  
-    # Returns the most recent favorite statuses for the autenticating user
150  
-    def favorites(options={})
151  
-      statuses(request(build_path('favorites.xml', parse_options(options)), :auth => true))
152  
-    end
153  
-    
154  
-    # Favorites the status specified by id for the auth user
155  
-    def create_favorite(id)
156  
-      statuses(request("favorites/create/#{id}.xml", :auth => true, :method => :post)).first
157  
-    end
158  
-
159  
-    # Un-favorites the status specified by id for the auth user
160  
-    def destroy_favorite(id)
161  
-      statuses(request("favorites/destroy/#{id}.xml", :auth => true, :method => :post)).first
162  
-    end
163  
-    
164  
-    # Blocks the user specified by id for the auth user
165  
-    def block(id)
166  
-      users(request("blocks/create/#{id}.xml", :auth => true, :method => :post)).first
167  
-    end
168  
-    
169  
-    # Unblocks the user specified by id for the auth user
170  
-    def unblock(id)
171  
-      users(request("blocks/destroy/#{id}.xml", :auth => true, :method => :post)).first
172  
-    end
173  
-    
174  
-    # Posts a new update to twitter for auth user.
175  
-    def post(status, options={})
176  
-      form_data = {'status' => status}
177  
-      form_data.merge!({'source' => options[:source]}) if options[:source]
178  
-      form_data.merge!({'in_reply_to_status_id' => options[:in_reply_to_status_id]}) if options[:in_reply_to_status_id]
179  
-      Status.new_from_xml(request('statuses/update.xml', :auth => true, :method => :post, :form_data => form_data))
180  
-    end
181  
-    alias :update :post
182  
-    
183  
-    # Verifies the credentials for the auth user.
184  
-    #   raises Twitter::CantConnect on failure.
185  
-    def verify_credentials
186  
-      users(request('account/verify_credentials.xml', :auth => true)).first
187  
-    end
188  
-    
189  
-    private      
190  
-      # Converts an hpricot doc to an array of statuses
191  
-      def statuses(doc)
192  
-        (doc/:status).inject([]) { |statuses, status| statuses << Status.new_from_xml(status); statuses }
193  
-      end
194  
-      
195  
-      # Converts an hpricot doc to an array of users
196  
-      def users(doc)
197  
-        (doc/:user).inject([]) { |users, user| users << User.new_from_xml(user); users }
198  
-      end
199  
-      
200  
-      # Calls whatever api method requested that deals with statuses
201  
-      # 
202  
-      # ie: call(:public_timeline, :auth => false)
203  
-      def call(method, options={})
204  
-        options = { :auth => true, :args => {} }.merge(options)
205  
-        # Following line needed as lite=false doesn't work in the API: http://tinyurl.com/yo3h5d
206  
-        options[:args].delete(:lite) unless options[:args][:lite]
207  
-        args = options.delete(:args)
208  
-        request(build_path("statuses/#{method.to_s}.xml", args), options)
209  
-      end
210  
-      
211  
-      def response(path, options={})
212  
-        uri = URI.parse("http://#{@api_host}")
213  
-        
214  
-        begin
215  
-          response = Net::HTTP::Proxy(@proxy_host, @proxy_port).start(uri.host, uri.port) do |http|
216  
-            klass = Net::HTTP.const_get options[:method].to_s.downcase.capitalize
217  
-            req = klass.new("#{uri.path}/#{path}", options[:headers])
218  
-            req.basic_auth(@config[:email], @config[:password]) if options[:auth]
219  
-            if options[:method].to_s == 'post' && options[:form_data]
220  
-              req.set_form_data(options[:form_data])
221  
-            end
222  
-            http.request(req)
223  
-          end
224  
-        rescue => error
225  
-          raise CantConnect, error.message
226  
-        end
227  
-      end
228  
-      
229  
-      # Makes a request to twitter.
230  
-      def request(path, options={})
231  
-        options = {
232  
-          :headers => { "User-Agent" => @config[:email] },
233  
-          :method => :get,
234  
-        }.merge(options)
235  
-        
236  
-        unless options[:since].nil?
237  
-          since = options[:since].kind_of?(Date) ? options[:since].strftime('%a, %d-%b-%y %T GMT') : options[:since].to_s  
238  
-          options[:headers]["If-Modified-Since"] = since
239  
-        end
240  
-        
241  
-        handle_response!(response(path, options))
242  
-      end
243  
-      
244  
-      def handle_response!(response)
245  
-        if %w[200 304].include?(response.code)
246  
-          response = parse(response.body)
247  
-          raise RateExceeded if (response/:hash/:error).text =~ /Rate limit exceeded/
248  
-          response
249  
-        elsif response.code == '503'
250  
-          raise Unavailable, response.message
251  
-        elsif response.code == '401'
252  
-          raise CantConnect, 'Authentication failed. Check your username and password'
253  
-        elsif response.code == '403'
254  
-          error_message = (parse(response.body)/:hash/:error).text
255  
-          raise CantFindUsers, error_message  if error_message =~ /Could not find both specified users/
256  
-          raise AlreadyFollowing, error_message if error_message =~ /already on your list/
257  
-          raise CantFollowUser, "Response code #{response.code}: #{response.message} #{error_message}"
258  
-        else
259  
-          raise CantConnect, "Twitter is returning a #{response.code}: #{response.message}"
260  
-        end
261  
-      end
262  
-    
263  
-      # Given a path and a hash, build a full path with the hash turned into a query string
264  
-      def build_path(path, options)
265  
-        unless options.nil?
266  
-          query = options.inject('') { |str, h| str += "#{CGI.escape(h[0].to_s)}=#{CGI.escape(h[1].to_s)}&"; str }
267  
-          path += "?#{query}"
268  
-        end
269  
-        
270  
-        path
271  
-      end
272  
-
273  
-      # Tries to get all the options in the correct format before making the request
274  
-      def parse_options(options)
275  
-        options[:since] = options[:since].kind_of?(Date) ? options[:since].strftime('%a, %d-%b-%y %T GMT') : options[:since].to_s if options[:since]
276  
-        options
277  
-      end
278  
-      
279  
-      # Converts a string response into an Hpricot xml element.
280  
-      def parse(response)
281  
-        Hpricot.XML(response || '')
282  
-      end
283  
-  end
284  
-end
334  lib/twitter/cli.rb
... ...
@@ -1,334 +0,0 @@
1  
-require 'rubygems'
2  
-
3  
-gem 'main'
4  
-gem 'highline'
5  
-gem 'activerecord'
6  
-gem 'sqlite3-ruby'
7  
-
8  
-require 'main'
9  
-require 'highline/import'
10  
-require 'activerecord'
11  
-require 'sqlite3'
12  
-
13  
-HighLine.track_eof = false
14  
-CLI_ROOT = File.expand_path(File.join(File.dirname(__FILE__), 'cli'))
15  
-require CLI_ROOT + '/config'
16  
-require CLI_ROOT + '/helpers'
17  
-Dir[CLI_ROOT + '/models/*.rb'].each { |m| require m }
18  
-
19  
-include Twitter::CLI::Helpers
20  
-
21  
-Main {
22  
-  def run
23  
-    puts "twitter [command] --help for usage instructions."
24  
-    puts "The available commands are: \n   install, uninstall, add, remove, list, change, post, befriend, defriend, follow, leave, d and timeline."
25  
-  end
26  
-  
27  
-  mode 'install' do
28  
-    description 'Creates the sqlite3 database and runs the migrations.'
29  
-    def run
30  
-      migrate
31  
-      attempt_import
32  
-      say 'Twitter installed.'
33  
-    end
34  
-  end
35  
-  
36  
-  mode 'uninstall' do
37  
-    description 'Removes the sqlite3 database. There is no undo for this.'
38  
-    def run
39  
-      FileUtils.rm(Twitter::CLI::Config[:database]) if File.exists?(Twitter::CLI::Config[:database])
40  
-      say 'Twitter gem uninstalled.'
41  
-    end
42  
-  end
43  
-  
44  
-  mode 'add' do
45  
-    description 'Adds a new twitter account to the database. Prompts for username and password.'
46  
-    argument('username', 'u') {
47  
-      optional
48  
-      description 'optional username'
49  
-    }
50  
-    argument('password', 'p') {
51  
-      optional
52  
-      description 'optional password'
53  
-    }
54  
-    
55  
-    def run
56  
-      account = Hash.new
57  
-      say "Add New Account:"
58  
-      
59  
-      # allows optional username arg
60  
-      if params['username'].given?
61  
-        account[:username] = params['username'].value
62  
-      else
63  
-        account[:username] = ask('Username: ') do |q|
64  
-          q.validate = /\S+/
65  
-        end
66  
-      end
67  
-      
68  
-      # allows optional password arg
69  
-      if params['password'].given?
70  
-        account[:password] = params['password'].value
71  
-      else
72  
-        account[:password] = ask("Password (won't be displayed): ") do |q|
73  
-          q.echo = false
74  
-          q.validate = /\S+/
75  
-        end
76  
-      end
77  
-      
78  
-      do_work do
79  
-        base(account[:username], account[:password]).verify_credentials
80  
-        Account.add(account)
81  
-        say 'Account added.'
82  
-      end
83  
-    end
84  
-  end
85  
-  
86  
-  mode 'remove' do
87  
-    description 'Removes a twitter account from the database. If username provided it removes that username else it prompts with list and asks for which one you would like to remove.'
88  
-    argument( 'username' ) { 
89  
-      optional
90  
-      description 'username of account you would like to remove' 
91  
-    }
92  
-    
93  
-    def run
94  
-      do_work do
95  
-        if params['username'].given?
96  
-          account = Account.find_by_username(params['username'].value)
97  
-        else
98  
-          Account.find(:all, :order => 'username').each do |a|
99  
-            say "#{a.id}. #{a}"
100  
-          end
101  
-          account_id = ask 'Account to remove (enter number): ' do |q|
102  
-            q.validate = /\d+/
103  
-          end
104  
-        end
105  
-        
106  
-        begin
107  
-          account = account_id ? Account.find(account_id) : account
108  
-          account_name = account.username
109  
-          account.destroy
110  
-          Account.set_current(Account.first) if Account.new_active_needed?
111  
-          say "#{account_name} has been removed.\n"
112  
-        rescue ActiveRecord::RecordNotFound
113  
-          say "ERROR: Account could not be found. Try again. \n"
114  
-        end
115  
-      end
116  
-    end
117  
-  end
118  
-  
119  
-  mode 'list' do
120  
-    description 'Lists all the accounts that have been added and puts a * by the current one that is used for posting, etc.'
121  
-    def run
122  
-      do_work do
123  
-        if Account.count == 0
124  
-          say 'No accounts have been added.' 
125  
-        else
126  
-          say 'Account List'
127  
-          Account.find(:all, :order => 'username').each do |a|
128  
-            say a 
129  
-          end
130  
-        end
131  
-      end
132  
-    end
133  
-  end
134  
-  
135  
-  mode 'change' do
136  
-    description 'Changes the current account being used for posting etc. to the username provided. If no username is provided, a list is presented and you can choose the account from there.'
137  
-    argument( 'username' ) { 
138  
-      optional
139  
-      description 'username of account you would like to switched to' 
140  
-    }
141  
-    
142  
-    def run
143  
-      do_work do
144  
-        if params['username'].given?
145  
-          new_current = Account.find_by_username(params['username'].value)
146  
-        else
147  
-          Account.find(:all, :order => 'username').each do |a|
148  
-            say "#{a.id}. #{a}"
149  
-          end
150  
-          new_current = ask 'Change current account to (enter number): ' do |q|
151  
-            q.validate = /\d+/
152  
-          end
153  
-        end
154  
-        
155  
-        begin
156  
-          current = Account.set_current(new_current)
157  
-          say "#{current} is now the current account.\n"
158  
-        rescue ActiveRecord::RecordNotFound
159  
-          say "ERROR: Account could not be found. Try again. \n"
160  
-        end
161  
-      end
162  
-    end
163  
-  end
164  
-  
165  
-  mode 'post' do
166  
-    description "Posts a message to twitter using the current account. The following are all valid examples from the command line:
167  
-    $ twitter post 'my update'
168  
-    $ twitter post my update with quotes
169  
-    $ echo 'my update from stdin' | twitter post"
170  
-    def run
171  
-      do_work do
172  
-        post = ARGV.size > 1 ? ARGV.join(" ") : ARGV.shift
173  
-        say "Sending twitter update"
174  
-        finished, status = false, nil
175  
-        progress_thread = Thread.new { until finished; print "."; $stdout.flush; sleep 0.5; end; }
176  
-        post_thread = Thread.new(binding()) do |b|
177  
-          status = base.post(post, :source => Twitter::SourceName)
178  
-          finished = true
179  
-        end
180  
-        post_thread.join
181  
-        progress_thread.join
182  
-        say "Got it! New tweet created at: #{status.created_at}\n"
183  
-      end
184  
-    end
185  
-  end
186  
-
187  
-  mode 'befriend' do
188  
-    description "Allows you to add a user as a friend"
189  
-    argument('username') {
190  
-      required
191  
-      description 'username or id of twitterrer to befriend'
192  
-    }
193  
-
194  
-    def run
195  
-      do_work do
196  
-        username = params['username'].value
197  
-        base.create_friendship(username)
198  
-        say "#{username} has been added as a friend. follow notifications with 'twitter follow #{username}'"
199  
-      end
200  
-    end
201  
-  end
202  
-
203  
-  mode 'defriend' do
204  
-    description "Allows you to remove a user from being a friend"
205  
-    argument('username') {
206  
-      required
207  
-      description 'username or id of twitterrer to defriend'
208  
-    }
209  
-
210  
-    def run
211  
-      do_work do
212  
-        username = params['username'].value
213  
-        base.destroy_friendship(username)
214  
-        say "#{username} has been removed from your friends"
215